Rename vector components to match new terminology (#719)

* Renamed VectorAnchor, VectorShape and VectorControlPoint. Also fixed other naming inconsistencies.

* Renamed messages relating to vector and updated naming in several tools

* Renamed comments + caught a few areas I had missed.

* Caught a few more incorrect names

* Code review pass

* Review changes

* Fixed warning

* Additional review feedback

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Oliver Davies
2022-07-12 17:59:06 -07:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent 5d1d93917d
commit 03633bf313
39 changed files with 1125 additions and 1095 deletions
+66 -58
View File
@@ -6,7 +6,7 @@ use crate::layers::layer_info::{Layer, LayerData, LayerDataType, LayerDataTypeDi
use crate::layers::shape_layer::ShapeLayer;
use crate::layers::style::RenderData;
use crate::layers::text_layer::{Font, FontCache, TextLayer};
use crate::layers::vector::vector_shape::VectorShape;
use crate::layers::vector::subpath::Subpath;
use crate::{DocumentError, DocumentResponse, Operation};
use glam::{DAffine2, DVec2};
@@ -126,28 +126,28 @@ impl Document {
Ok(shapes)
}
/// Return a copy of all VectorShapes currently in the document.
pub fn all_vector_shapes(&self) -> Vec<VectorShape> {
self.root.iter().flat_map(|layer| layer.as_vector_shape_copy()).collect::<Vec<VectorShape>>()
/// Return a copy of all [Subpath]s currently in the document.
pub fn all_subpaths(&self) -> Vec<Subpath> {
self.root.iter().flat_map(|layer| layer.as_subpath_copy()).collect::<Vec<Subpath>>()
}
/// Returns references to all VectorShapes currently in the document.
pub fn all_vector_shapes_ref(&self) -> Vec<&VectorShape> {
self.root.iter().flat_map(|layer| layer.as_vector_shape()).collect::<Vec<&VectorShape>>()
/// Returns references to all [Subpath]s currently in the document.
pub fn all_subpaths_ref(&self) -> Vec<&Subpath> {
self.root.iter().flat_map(|layer| layer.as_subpath()).collect::<Vec<&Subpath>>()
}
/// Returns a reference to the requested VectorShape by providing a path to its owner layer.
pub fn vector_shape_ref<'a>(&'a self, path: &[LayerId]) -> Option<&'a VectorShape> {
self.layer(path).ok()?.as_vector_shape()
/// Returns a reference to the requested [Subpath] by providing a path to its owner layer.
pub fn subpath_ref<'a>(&'a self, path: &[LayerId]) -> Option<&'a Subpath> {
self.layer(path).ok()?.as_subpath()
}
/// Returns a mutable reference of the requested VectorShape by providing a path to its owner layer.
pub fn vector_shape_mut<'a>(&'a mut self, path: &'a [LayerId]) -> Option<&'a mut VectorShape> {
self.layer_mut(path).ok()?.as_vector_shape_mut()
/// Returns a mutable reference of the requested [Subpath] by providing a path to its owner layer.
pub fn subpath_mut<'a>(&'a mut self, path: &'a [LayerId]) -> Option<&'a mut Subpath> {
self.layer_mut(path).ok()?.as_subpath_mut()
}
/// Set a VectorShape at the specified path.
pub fn set_vector_shape(&mut self, path: &[LayerId], shape: VectorShape) {
/// Set a [Subpath] at the specified path.
pub fn set_subpath(&mut self, path: &[LayerId], shape: Subpath) {
let layer = self.layer_mut(path);
if let Ok(layer) = layer {
if let LayerDataType::Shape(shape_layer) = &mut layer.data {
@@ -158,9 +158,9 @@ impl Document {
}
}
/// Set VectorShapes for multiple paths at once.
pub fn set_vector_shapes<'a>(&'a mut self, paths: impl Iterator<Item = &'a [LayerId]>, shapes: Vec<VectorShape>) {
paths.zip(shapes).for_each(|(path, shape)| self.set_vector_shape(path, shape));
/// Set [Subpath]s for multiple paths at once.
pub fn set_subpaths<'a>(&'a mut self, paths: impl Iterator<Item = &'a [LayerId]>, shapes: Vec<Subpath>) {
paths.zip(shapes).for_each(|(path, shape)| self.set_subpath(path, shape));
}
pub fn common_layer_path_prefix<'a>(&self, layers: impl Iterator<Item = &'a [LayerId]>) -> &'a [LayerId] {
@@ -591,9 +591,9 @@ impl Document {
transform,
insert_index,
style,
vector_path,
subpath,
} => {
let shape = ShapeLayer::new(vector_path, style);
let shape = ShapeLayer::new(subpath, style);
self.set_layer(&path, Layer::new(LayerDataType::Shape(shape), transform), insert_index)?;
Some([vec![DocumentChanged, CreatedLayer { path }]].concat())
}
@@ -758,53 +758,61 @@ impl Document {
self.mark_as_dirty(&path)?;
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
}
Operation::SetShapePath { path, vector_path } => {
Operation::SetShapePath { path, subpath } => {
self.mark_as_dirty(&path)?;
if let LayerDataType::Shape(shape) = &mut self.layer_mut(&path)?.data {
shape.shape = vector_path;
shape.shape = subpath;
}
Some(vec![DocumentChanged, LayerChanged { path }])
}
Operation::InsertVectorAnchor { layer_path, anchor, after_id } => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_vector_shape_mut()) {
shape.anchors_mut().insert(anchor, after_id);
Operation::InsertManipulatorGroup {
layer_path,
manipulator_group,
after_id,
} => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_subpath_mut()) {
shape.manipulator_groups_mut().insert(manipulator_group, after_id);
self.mark_as_dirty(&layer_path)?;
}
Some([update_thumbnails_upstream(&layer_path), vec![DocumentChanged, LayerChanged { path: layer_path }]].concat())
}
Operation::PushVectorAnchor { layer_path, anchor } => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_vector_shape_mut()) {
shape.anchors_mut().push(anchor);
Operation::PushManipulatorGroup { layer_path, manipulator_group } => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_subpath_mut()) {
shape.manipulator_groups_mut().push(manipulator_group);
self.mark_as_dirty(&layer_path)?;
}
Some([update_thumbnails_upstream(&layer_path), vec![DocumentChanged, LayerChanged { path: layer_path }]].concat())
}
Operation::RemoveVectorAnchor { layer_path, id } => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_vector_shape_mut()) {
shape.anchors_mut().remove(id);
Operation::RemoveManipulatorGroup { layer_path, id } => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_subpath_mut()) {
shape.manipulator_groups_mut().remove(id);
self.mark_as_dirty(&layer_path)?;
}
Some([update_thumbnails_upstream(&layer_path), vec![DocumentChanged, LayerChanged { path: layer_path }]].concat())
}
Operation::MoveVectorPoint {
Operation::MoveManipulatorPoint {
layer_path,
id,
control_type,
manipulator_type: control_type,
position,
} => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_vector_shape_mut()) {
if let Some(anchor) = shape.anchors_mut().by_id_mut(id) {
anchor.set_point_position(control_type as usize, position.into());
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_subpath_mut()) {
if let Some(manipulator_group) = shape.manipulator_groups_mut().by_id_mut(id) {
manipulator_group.set_point_position(control_type as usize, position.into());
self.mark_as_dirty(&layer_path)?;
}
}
Some([update_thumbnails_upstream(&layer_path), vec![DocumentChanged, LayerChanged { path: layer_path }]].concat())
}
Operation::RemoveVectorPoint { layer_path, id, control_type } => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_vector_shape_mut()) {
if let Some(anchor) = shape.anchors_mut().by_id_mut(id) {
anchor.points[control_type as usize] = None;
Operation::RemoveManipulatorPoint {
layer_path,
id,
manipulator_type: control_type,
} => {
if let Ok(Some(shape)) = self.layer_mut(&layer_path).map(|layer| layer.as_subpath_mut()) {
if let Some(manipulator_group) = shape.manipulator_groups_mut().by_id_mut(id) {
manipulator_group.points[control_type as usize] = None;
self.mark_as_dirty(&layer_path)?;
}
}
@@ -886,47 +894,47 @@ impl Document {
}
// We may not want the concept of selection here. For now leaving though.
Operation::SelectVectorPoints { layer_path, point_ids, add } => {
Operation::SelectManipulatorPoints { layer_path, point_ids, add } => {
let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_vector_shape_mut() {
if let Some(shape) = layer.as_subpath_mut() {
if !add {
shape.clear_selected_anchors();
shape.clear_selected_manipulator_groups();
}
shape.select_points(&point_ids, true);
}
Some(vec![LayerChanged { path: layer_path.clone() }])
}
Operation::DeselectVectorPoints { layer_path, point_ids } => {
Operation::DeselectManipulatorPoints { layer_path, point_ids } => {
let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_vector_shape_mut() {
if let Some(shape) = layer.as_subpath_mut() {
shape.select_points(&point_ids, false);
}
Some(vec![LayerChanged { path: layer_path.clone() }])
}
Operation::DeselectAllVectorPoints { layer_path } => {
Operation::DeselectAllManipulatorPoints { layer_path } => {
let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_vector_shape_mut() {
shape.clear_selected_anchors();
if let Some(shape) = layer.as_subpath_mut() {
shape.clear_selected_manipulator_groups();
}
Some(vec![LayerChanged { path: layer_path.clone() }])
}
Operation::DeleteSelectedVectorPoints { layer_paths } => {
Operation::DeleteSelectedManipulatorPoints { layer_paths } => {
let mut responses = vec![];
for layer_path in layer_paths {
let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_vector_shape_mut() {
if let Some(shape) = layer.as_subpath_mut() {
// Delete the selected points.
shape.delete_selected();
// Delete the layer if there are no longer any anchors
if (shape.anchors().len() - 1) == 0 {
// Delete the layer if there are no longer any manipulator groups
if (shape.manipulator_groups().len() - 1) == 0 {
self.delete(&layer_path)?;
responses.push(DocumentChanged);
responses.push(DocumentResponse::DeletedLayer { path: layer_path });
return Ok(Some(responses));
}
// If we still have anchors, update the layer and thumbnails
// If we still have manipulator groups, update the layer and thumbnails
self.mark_as_dirty(&layer_path)?;
responses.push(DocumentChanged);
responses.push(LayerChanged { path: layer_path.clone() });
@@ -935,13 +943,13 @@ impl Document {
}
Some(responses)
}
Operation::MoveSelectedVectorPoints { layer_path, delta, absolute_position } => {
Operation::MoveSelectedManipulatorPoints { layer_path, delta, absolute_position } => {
if let Ok(viewspace) = self.generate_transform_relative_to_viewport(&layer_path) {
let objectspace = &viewspace.inverse();
let delta = objectspace.transform_vector2(DVec2::new(delta.0, delta.1));
let absolute_position = objectspace.transform_point2(DVec2::new(absolute_position.0, absolute_position.1));
let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_vector_shape_mut() {
if let Some(shape) = layer.as_subpath_mut() {
shape.move_selected(delta, absolute_position, &viewspace);
}
}
@@ -954,9 +962,9 @@ impl Document {
toggle_angle,
} => {
let layer = self.layer_mut(&layer_path)?;
if let Some(shape) = layer.as_vector_shape_mut() {
for anchor in shape.selected_anchors_any_points_mut() {
anchor.toggle_mirroring(toggle_distance, toggle_angle);
if let Some(shape) = layer.as_subpath_mut() {
for manipulator_group in shape.selected_manipulator_groups_any_points_mut() {
manipulator_group.toggle_mirroring(toggle_distance, toggle_angle);
}
}
// This does nothing visually so we don't need to send any messages