Skip to content

Commit c2f7637

Browse files
committed
Add review fixes
1 parent 8080c2c commit c2f7637

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

client/web/src/components/panels/LayerTree.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ export default defineComponent({
330330
const responsePath = updateData.path;
331331
const responseLayer = updateData.data;
332332
333-
const index = this.layers.findIndex((layer: LayerPanelEntry) => responsePath.length === layer.path.length && responsePath.every((this_i, i) => this_i === layer.path[i]));
333+
const index = this.layers.findIndex((layer: LayerPanelEntry) => {
334+
const pathLengthsEqual = responsePath.length === layer.path.length;
335+
return pathLengthsEqual && responsePath.every((index, i) => index === layer.path[i]);
336+
});
334337
if (index >= 0) this.layers[index] = responseLayer;
335338
336339
this.setBlendModeForSelectedLayers();

core/document/src/intersection.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ impl Quad {
1111
let size = bbox[1] - bbox[0];
1212
Self([bbox[0], bbox[0] + size * DVec2::X, bbox[0] + size * DVec2::Y, bbox[1]])
1313
}
14+
1415
pub fn lines(&self) -> [Line; 4] {
1516
[
1617
Line::new(to_point(self.0[0]), to_point(self.0[1])),
@@ -39,12 +40,8 @@ fn to_point(vec: DVec2) -> Point {
3940

4041
pub fn intersect_quad_bez_path(quad: Quad, shape: &BezPath, closed: bool) -> bool {
4142
// check if outlines intersect
42-
for path_segment in shape.segments() {
43-
for line in quad.lines() {
44-
if !path_segment.intersect_line(line).is_empty() {
45-
return true;
46-
}
47-
}
43+
if shape.segments().any(|path_segment| quad.lines().iter().any(|line| !path_segment.intersect_line(*line).is_empty())) {
44+
return true;
4845
}
4946
// check if selection is entirely within the shape
5047
if closed && quad.0.iter().any(|q| shape.contains(to_point(*q))) {

core/document/src/layers/folder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ impl LayerData for Folder {
3030
}
3131

3232
fn bounding_box(&self, transform: glam::DAffine2) -> Option<[DVec2; 2]> {
33-
let mut layers_non_empty_bounding_boxes = self.layers.iter().filter_map(|layer| layer.data.bounding_box(transform * layer.transform)).peekable();
34-
layers_non_empty_bounding_boxes.peek()?;
35-
layers_non_empty_bounding_boxes.reduce(|a, b| [a[0].min(b[0]), a[1].max(b[1])])
33+
self.layers
34+
.iter()
35+
.filter_map(|layer| layer.data.bounding_box(transform * layer.transform))
36+
.reduce(|a, b| [a[0].min(b[0]), a[1].max(b[1])])
3637
}
3738
}
3839

core/document/src/layers/simple_shape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ impl Shape {
7878
}
7979

8080
pub fn shape(sides: u8, style: PathStyle) -> Self {
81-
use std::f64::consts::PI;
81+
use std::f64::consts::{FRAC_PI_2, PI};
8282
fn unit_rotation(theta: f64) -> DVec2 {
8383
DVec2::new(theta.sin(), theta.cos())
8484
}
8585
let mut path = kurbo::BezPath::new();
8686
let apothem_offset_angle = 2. * PI / (sides as f64);
87-
let offset = ((sides + 1) % 2) as f64 * PI / 2.; // rotate odd sided shaps by 90 degrees
87+
let offset = ((sides + 1) % 2) as f64 * FRAC_PI_2; // rotate odd sided shapes by 90 degrees
8888

8989
let relative_points = (0..sides).map(|i| apothem_offset_angle * i as f64 + offset).map(unit_rotation);
9090
let min = relative_points.clone().reduce(|a, b| a.min(b)).unwrap_or_default();

core/editor/src/document/layer_panel.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl LayerData {
2828
scale: 1.,
2929
}
3030
}
31+
3132
pub fn snapped_angle(&self) -> f64 {
3233
let increment_radians: f64 = ROTATE_SNAP_INTERVAL.to_radians();
3334
if self.snap_rotate {
@@ -36,7 +37,9 @@ impl LayerData {
3637
self.rotation
3738
}
3839
}
40+
3941
pub fn calculate_offset_transform(&self, offset: DVec2) -> DAffine2 {
42+
// TODO: replace with DAffine2::from_scale_angle_translation and fix the errors
4043
let offset_transform = DAffine2::from_translation(offset);
4144
let scale_transform = DAffine2::from_scale(DVec2::new(self.scale, self.scale));
4245
let angle_transform = DAffine2::from_angle(self.snapped_angle());
@@ -53,8 +56,6 @@ pub fn layer_data<'a>(layer_data: &'a mut HashMap<Vec<LayerId>, LayerData>, path
5356
}
5457

5558
pub fn layer_panel_entry(layer_data: &LayerData, transform: DAffine2, layer: &Layer, path: Vec<LayerId>) -> LayerPanelEntry {
56-
let blend_mode = layer.blend_mode;
57-
let opacity = layer.opacity;
5859
let layer_type: LayerType = (&layer.data).into();
5960
let name = layer.name.clone().unwrap_or_else(|| format!("Unnamed {}", layer_type));
6061
let arr = layer.data.bounding_box(transform).unwrap_or([DVec2::ZERO, DVec2::ZERO]);
@@ -79,9 +80,9 @@ pub fn layer_panel_entry(layer_data: &LayerData, transform: DAffine2, layer: &La
7980
LayerPanelEntry {
8081
name,
8182
visible: layer.visible,
82-
blend_mode,
83-
opacity,
84-
layer_type,
83+
blend_mode: layer.blend_mode,
84+
opacity: layer.opacity,
85+
layer_type: (&layer.data).into(),
8586
layer_data: *layer_data,
8687
path,
8788
thumbnail,

core/editor/src/tool/tools/eyedropper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Eyedropper {
2424
if let Some(path) = data.0.document.intersects_quad_root(quad).last() {
2525
if let Ok(layer) = data.0.document.layer(path) {
2626
if let LayerDataType::Shape(s) = &layer.data {
27-
s.style.fill().map(|fill| {
27+
s.style.fill().and_then(|fill| {
2828
fill.color().map(|color| match action {
2929
ToolMessage::Eyedropper(EyedropperMessage::LeftMouseDown) => responses.push_back(ToolMessage::SelectPrimaryColor(color).into()),
3030
ToolMessage::Eyedropper(EyedropperMessage::RightMouseDown) => responses.push_back(ToolMessage::SelectSecondaryColor(color).into()),

0 commit comments

Comments
 (0)