Kevin Lee 6 mēneši atpakaļ
vecāks
revīzija
1c886bb325

BIN
samples/CircleRotate135.mlp


BIN
samples/CircleRotate270.mlp


BIN
samples/Circle2.mlp


BIN
samples/CircleScaleX.mlp


BIN
samples/Circle5.mlp


BIN
samples/CircleScaleY.mlp


BIN
samples/CircleSkewRightRotate45.mlp


BIN
samples/Circle4.mlp


BIN
samples/CircleSkewTopLeft.mlp


samples/Ellipse3.mlp → samples/EllipseAngle.mlp


BIN
samples/EllipseClosed.mlp


samples/Ellipse.mlp → samples/EllipseOpen.mlp


samples/EllipseRotated2.mlp → samples/EllipseRotated30.mlp


samples/EllipseRotated.mlp → samples/EllipseRotated45.mlp


samples/EllipseSkewed4.mlp → samples/EllipseSkewBottomRight.mlp


samples/EllipseSkewed3.mlp → samples/EllipseSkewLeftDown.mlp


samples/EllipseSkewed.mlp → samples/EllipseSkewRightDown.mlp


samples/EllipseSkewed2.mlp → samples/EllipseSkewTopLeft.mlp


samples/Rectangle3.mlp → samples/RectangleDrawn.mlp


BIN
samples/RectangleDrawnRotate140.mlp


BIN
samples/RectangleDrawnRotate20.mlp


BIN
samples/Circle3.mlp


BIN
samples/Rectangle2.mlp


BIN
samples/RectangleDrawnScaleY.mlp


BIN
samples/RectangleDrawnSkewRightUp.mlp


BIN
samples/RectangleDrawnSkewTopRight.mlp


BIN
samples/Rectangle4.mlp


BIN
samples/RectangleSkewTopRight.mlp


BIN
samples/RectangleSkewTopRightTranslated.mlp


+ 1 - 1
src/ezcad/objects/circle.rs

@@ -30,7 +30,7 @@ impl Display for Circle {
             f,
             "{}, Origin: {}, Width : {:.2}, Height: {:.2}, Start Radian: {:.2}, Clockwise: {}",
             self.core,
-            self.modifier.correction() + *self.drawn_origin * self.modifier.scale(),
+            self.modifier.translation() + *self.drawn_origin * self.modifier.scale(),
             *self.radius * self.modifier.modifiers.x_scale * 2.0,
             *self.radius * self.modifier.modifiers.y_scale * 2.0,
             *self.start_angle,

+ 19 - 32
src/ezcad/objects/mod.rs

@@ -292,12 +292,12 @@ impl ObjectModifier {
     /// Apply relative move to origin correction vector
     pub fn move_relative(&mut self, delta: Point) {
         self.default = 255.into();
-        self.modifiers.correction += delta;
+        self.modifiers.translate += delta;
     }
 
-    /// Return correction to origin offset of object
-    pub fn correction(&self) -> Point {
-        self.modifiers.correction
+    /// Return correction to offset of object
+    pub fn translation(&self) -> Point {
+        self.modifiers.translate
     }
 
     /// Returns scaling vector of object
@@ -328,7 +328,7 @@ impl ObjectModifier {
         );
 
         // Calculate 4 points of drawn rectangle
-        let drawn_pts: Vec<Point> = vec![
+        let corners: Vec<Point> = vec![
             Point {
                 x: pt1.min(pt2).x,
                 y: pt1.min(pt2).y,
@@ -349,40 +349,27 @@ impl ObjectModifier {
 
         debug!(
             "Drawn points: {}",
-            drawn_pts
+            corners
                 .iter()
                 .map(|x| format!("{x}"))
                 .collect_vec()
                 .join(", ")
         );
 
-        // Apply skew to points of drawn rectangle
-        let skewed_pts: Vec<Point> = drawn_pts
+        // Apply skew, then scale and translation
+        let corners: Vec<Point> = corners
             .iter()
             .map(|pt| Point {
                 x: pt.x + pt.y * self.modifiers.x_skew.asin().tan(),
                 y: pt.y + pt.x * self.modifiers.y_skew.asin().tan(),
             })
+            .inspect(|pt| debug!("pt: {pt}"))
+            .map(|pt| pt * self.scale() + self.translation())
             .collect_vec();
 
         debug!(
-            "Skewed points: {}",
-            skewed_pts
-                .iter()
-                .map(|x| format!("{x}"))
-                .collect_vec()
-                .join(", ")
-        );
-
-        // Apply scale and origin correction
-        let corrected_pts: Vec<Point> = skewed_pts
-            .iter()
-            .map(|pt| *pt * self.scale() + self.correction())
-            .collect_vec();
-
-        debug!(
-            "Skewed points (corrected): {}",
-            corrected_pts
+            "Corrected points: {}",
+            corners
                 .iter()
                 .map(|x| format!("{x}"))
                 .collect_vec()
@@ -390,10 +377,10 @@ impl ObjectModifier {
         );
 
         // Calculate resulting bounds
-        let min_x: f64 = corrected_pts.iter().fold(f64::MAX, |acc, pt| acc.min(pt.x));
-        let max_x: f64 = corrected_pts.iter().fold(f64::MIN, |acc, pt| acc.max(pt.x));
-        let min_y: f64 = corrected_pts.iter().fold(f64::MAX, |acc, pt| acc.min(pt.y));
-        let max_y: f64 = corrected_pts.iter().fold(f64::MIN, |acc, pt| acc.max(pt.y));
+        let min_x: f64 = corners.iter().fold(f64::MAX, |acc, pt| acc.min(pt.x));
+        let max_x: f64 = corners.iter().fold(f64::MIN, |acc, pt| acc.max(pt.x));
+        let min_y: f64 = corners.iter().fold(f64::MAX, |acc, pt| acc.min(pt.y));
+        let max_y: f64 = corners.iter().fold(f64::MIN, |acc, pt| acc.max(pt.y));
 
         // Compute min/max bounding box
         let bound_a: Point = Point { x: min_x, y: min_y };
@@ -436,7 +423,7 @@ pub struct ScaleValues {
     pub y_scale: f64, // Y scaled ratio on drawn object
     #[br(assert(_unknown_4 == 0.0))]
     _unknown_4: f64,
-    correction: Point, // Correction factor due to scaling
+    translate: Point, // Correction factor due to scaling
     #[br(assert(_unknown_5 == 1.0))]
     _unknown_5: f64,
 }
@@ -450,7 +437,7 @@ impl Default for ScaleValues {
             x_skew: 0.0.into(),
             y_scale: 1.0.into(),
             _unknown_4: 0.0.into(),
-            correction: (0.0, 0.0).into(),
+            translate: (0.0, 0.0).into(),
             _unknown_5: 1.0.into(),
         }
     }
@@ -464,7 +451,7 @@ impl Debug for ScaleValues {
             .field("y_scale", &self.y_scale)
             .field("x_skew", &self.x_skew)
             .field("y_skew", &self.y_skew)
-            .field("correction", &self.correction)
+            .field("translate", &self.translate)
             .finish()
     }
 }

+ 1 - 1
src/ezcad/objects/polygon.rs

@@ -44,7 +44,7 @@ impl Display for Polygon {
             f,
             "{}, Origin: {}, Width: {:.2}, Height: {:.2}, Inverted: {}, Offset CX: {:.2}, Offset CY: {:.2}, Offset DX: {:.2}, Offset: DY: {:.2}, Edges: {}",
             self.core,
-            self.modifier.correction() + drawn_origin * self.modifier.scale(),
+            self.modifier.translation() + drawn_origin * self.modifier.scale(),
             width,
             height,
             *self.invert_shape != 0,