Minor code cleanup and spelling fix

This commit is contained in:
Keavon Chambers 2024-03-16 00:30:29 -07:00
parent 6630e2b964
commit 1a2a0e8757
6 changed files with 29 additions and 30 deletions

View File

@ -493,7 +493,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
return Some(index as isize);
}
for descendant in direct_child.decendants(self.metadata()) {
for descendant in direct_child.descendants(self.metadata()) {
if self.selected_nodes.selected_layers(self.metadata()).any(|selected| selected == descendant) {
return Some(index as isize);
}
@ -918,7 +918,7 @@ impl DocumentMessageHandler {
let document_quad = self.metadata.document_to_viewport.inverse() * viewport_quad;
self.metadata
.root()
.decendants(&self.metadata)
.descendants(&self.metadata)
.filter(|&layer| self.selected_nodes.layer_visible(layer, self.network(), self.metadata()))
.filter(|&layer| !is_artboard(layer, network))
.filter_map(|layer| self.metadata.click_target(layer).map(|targets| (layer, targets)))
@ -931,7 +931,7 @@ impl DocumentMessageHandler {
let point = self.metadata.document_to_viewport.inverse().transform_point2(viewport_location);
self.metadata
.root()
.decendants(&self.metadata)
.descendants(&self.metadata)
.filter(|&layer| self.selected_nodes.layer_visible(layer, self.network(), self.metadata()))
.filter_map(|layer| self.metadata.click_target(layer).map(|targets| (layer, targets)))
.filter(move |(layer, target)| target.iter().any(|target: &ClickTarget| target.intersect_point(point, self.metadata.transform_to_document(*layer))))

View File

@ -517,7 +517,7 @@ impl<'a> ModifyInputsContext<'a> {
};
let layer_node = LayerNodeIdentifier::new(id, self.document_network);
let child_layers = layer_node.decendants(self.document_metadata).map(|layer| layer.to_node()).collect::<Vec<_>>();
let child_layers = layer_node.descendants(self.document_metadata).map(|layer| layer.to_node()).collect::<Vec<_>>();
layer_node.delete(self.document_metadata);
let new_input = node.inputs[1].clone();

View File

@ -928,9 +928,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
}
// Shift nodes connected to the output port of the specified node
for &decendant in outwards_links.get(&node_id).unwrap_or(&Vec::new()) {
let shift = required_shift(node_id, decendant, network);
let mut stack = vec![decendant];
for &descendant in outwards_links.get(&node_id).unwrap_or(&Vec::new()) {
let shift = required_shift(node_id, descendant, network);
let mut stack = vec![descendant];
while let Some(id) = stack.pop() {
shift_node(id, shift, network);
stack.extend(outwards_links.get(&id).unwrap_or(&Vec::new()).iter().copied())

View File

@ -48,8 +48,8 @@ impl DocumentMetadata {
LayerNodeIdentifier::ROOT
}
pub fn all_layers(&self) -> DecendantsIter<'_> {
self.root().decendants(self)
pub fn all_layers(&self) -> DescendantsIter<'_> {
self.root().descendants(self)
}
pub fn layer_exists(&self, layer: LayerNodeIdentifier) -> bool {
@ -396,9 +396,9 @@ impl LayerNodeIdentifier {
}
}
/// Iterator through all decendants, including recursive children (not including self)
pub fn decendants(self, metadata: &DocumentMetadata) -> DecendantsIter {
DecendantsIter {
/// Iterator through all descendants, including recursive children (not including self)
pub fn descendants(self, metadata: &DocumentMetadata) -> DescendantsIter {
DescendantsIter {
front: self.first_child(metadata),
back: self.last_child(metadata).and_then(|child| child.last_children(metadata).last()),
metadata,
@ -488,7 +488,7 @@ impl LayerNodeIdentifier {
}
let mut delete = vec![self];
delete.extend(self.decendants(metadata));
delete.extend(self.descendants(metadata));
for node in delete {
metadata.structure.remove(&node);
}
@ -533,17 +533,17 @@ impl<'a> Iterator for AxisIter<'a> {
}
// ==============
// DecendantsIter
// DescendantsIter
// ==============
#[derive(Clone)]
pub struct DecendantsIter<'a> {
pub struct DescendantsIter<'a> {
front: Option<LayerNodeIdentifier>,
back: Option<LayerNodeIdentifier>,
metadata: &'a DocumentMetadata,
}
impl<'a> Iterator for DecendantsIter<'a> {
impl<'a> Iterator for DescendantsIter<'a> {
type Item = LayerNodeIdentifier;
fn next(&mut self) -> Option<Self::Item> {
@ -561,7 +561,7 @@ impl<'a> Iterator for DecendantsIter<'a> {
}
}
}
impl<'a> DoubleEndedIterator for DecendantsIter<'a> {
impl<'a> DoubleEndedIterator for DescendantsIter<'a> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.front == self.back {
self.front = None;
@ -618,7 +618,7 @@ fn test_tree() {
assert_eq!(root.children(metadata).collect::<Vec<_>>(), vec![LayerNodeIdentifier::new_unchecked(NodeId(3))]);
root.push_child(metadata, LayerNodeIdentifier::new_unchecked(NodeId(6)));
assert_eq!(root.children(metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![NodeId(3), NodeId(6)]);
assert_eq!(root.decendants(metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![NodeId(3), NodeId(6)]);
assert_eq!(root.descendants(metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(), vec![NodeId(3), NodeId(6)]);
LayerNodeIdentifier::new_unchecked(NodeId(3)).add_after(metadata, LayerNodeIdentifier::new_unchecked(NodeId(4)));
LayerNodeIdentifier::new_unchecked(NodeId(3)).add_before(metadata, LayerNodeIdentifier::new_unchecked(NodeId(2)));
LayerNodeIdentifier::new_unchecked(NodeId(6)).add_before(metadata, LayerNodeIdentifier::new_unchecked(NodeId(5)));
@ -631,11 +631,11 @@ fn test_tree() {
vec![NodeId(1), NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(6), NodeId(9)]
);
assert_eq!(
root.decendants(metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
root.descendants(metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
vec![NodeId(1), NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(6), NodeId(7), NodeId(8), NodeId(9)]
);
assert_eq!(
root.decendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::<Vec<_>>(),
root.descendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::<Vec<_>>(),
vec![NodeId(9), NodeId(8), NodeId(7), NodeId(6), NodeId(5), NodeId(4), NodeId(3), NodeId(2), NodeId(1)]
);
assert!(root.children(metadata).all(|child| child.parent(metadata) == Some(root)));
@ -647,11 +647,11 @@ fn test_tree() {
vec![NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(9)]
);
assert_eq!(
root.decendants(metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
root.descendants(metadata).map(LayerNodeIdentifier::to_node).collect::<Vec<_>>(),
vec![NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(9), NodeId(10)]
);
assert_eq!(
root.decendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::<Vec<_>>(),
root.descendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::<Vec<_>>(),
vec![NodeId(10), NodeId(9), NodeId(5), NodeId(4), NodeId(3), NodeId(2)]
);
}

View File

@ -434,7 +434,7 @@ pub fn get_layer_snap_points(layer: LayerNodeIdentifier, snap_data: &SnapData, p
let document = snap_data.document;
if document.metadata().is_artboard(layer) {
} else if document.metadata().is_folder(layer) {
for child in layer.decendants(document.metadata()) {
for child in layer.descendants(document.metadata()) {
get_layer_snap_points(child, snap_data, points);
}
} else {

View File

@ -92,13 +92,11 @@ impl Fsm for FillToolFsmState {
let Some(layer_identifier) = document.click(input.mouse.position, &document.network) else {
return self;
};
// TODO: Use a match statement here instead of if-else
let color = if color_event == FillToolMessage::FillPrimaryColor {
global_tool_data.primary_color
} else {
global_tool_data.secondary_color
let fill = match color_event {
FillToolMessage::FillPrimaryColor => Fill::Solid(global_tool_data.primary_color),
FillToolMessage::FillSecondaryColor => Fill::Solid(global_tool_data.secondary_color),
_ => return self,
};
let fill = Fill::Solid(color);
responses.add(DocumentMessage::StartTransaction);
responses.add(GraphOperationMessage::FillSet { layer: layer_identifier, fill });
@ -109,7 +107,8 @@ impl Fsm for FillToolFsmState {
(FillToolFsmState::Filling, FillToolMessage::PointerUp) => FillToolFsmState::Ready,
(FillToolFsmState::Filling, FillToolMessage::Abort) => {
responses.add(DocumentMessage::AbortTransaction);
return FillToolFsmState::Ready;
FillToolFsmState::Ready
}
_ => self,
}