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