|
@@ -8,10 +8,9 @@ use crate::{
|
|
types::{Coordinate, ObjectType, F64},
|
|
types::{Coordinate, ObjectType, F64},
|
|
};
|
|
};
|
|
|
|
|
|
-use super::{ObjectCore, Translate, ObjectModified};
|
|
|
|
|
|
+use super::{ObjectCore, ObjectModifier, Translate};
|
|
|
|
|
|
-#[cfg_attr(feature = "default-debug", derive(Debug))]
|
|
|
|
-#[derive(BinRead, BinWrite, Clone, Diff, PartialEq)]
|
|
|
|
|
|
+#[derive(BinRead, BinWrite, Clone, Debug, Diff, PartialEq)]
|
|
#[diff(attr(
|
|
#[diff(attr(
|
|
#[derive(Debug, PartialEq)]
|
|
#[derive(Debug, PartialEq)]
|
|
))]
|
|
))]
|
|
@@ -24,25 +23,7 @@ pub struct Rectangle {
|
|
pub round_bottom_right: F64,
|
|
pub round_bottom_right: F64,
|
|
pub round_top_right: F64,
|
|
pub round_top_right: F64,
|
|
pub round_top_left: F64,
|
|
pub round_top_left: F64,
|
|
- // origin_x = (corner_a.x + corner_b.x) / 2 * width_scale + origin_x_delta
|
|
|
|
- pub modified: ObjectModified,
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// Custom Debug implementation to only print known fields
|
|
|
|
-#[cfg(not(feature = "default-debug"))]
|
|
|
|
-impl Debug for Rectangle {
|
|
|
|
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
- f.debug_struct("Rectangle")
|
|
|
|
- .field("core", &self.core)
|
|
|
|
- .field("corner_a", &self.drawn_corner_a)
|
|
|
|
- .field("corner_b", &self.drawn_corner_b)
|
|
|
|
- .field("round_bottom_left", &self.round_bottom_left)
|
|
|
|
- .field("round_bottom_right", &self.round_bottom_right)
|
|
|
|
- .field("round_top_right", &self.round_top_right)
|
|
|
|
- .field("round_top_left", &self.round_top_left)
|
|
|
|
- .finish()
|
|
|
|
- }
|
|
|
|
|
|
+ pub modifier: ObjectModifier,
|
|
}
|
|
}
|
|
|
|
|
|
impl Default for Rectangle {
|
|
impl Default for Rectangle {
|
|
@@ -55,25 +36,25 @@ impl Default for Rectangle {
|
|
round_bottom_right: 0.0.into(),
|
|
round_bottom_right: 0.0.into(),
|
|
round_top_right: 0.0.into(),
|
|
round_top_right: 0.0.into(),
|
|
round_top_left: 0.0.into(),
|
|
round_top_left: 0.0.into(),
|
|
- modified: ObjectModified::default(),
|
|
|
|
|
|
+ modifier: ObjectModifier::default(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// origin_x = x_corretion + (drawn_a.x + drawn_b.x) / 2 * x_scale
|
|
|
|
+// x_correction = origin_x - (drawn_a.x + drawn_b.x) / 2 * x_scale
|
|
impl Translate for Rectangle {
|
|
impl Translate for Rectangle {
|
|
fn move_absolute(&mut self, origin: Option<Coordinate>, z: Option<f64>) {
|
|
fn move_absolute(&mut self, origin: Option<Coordinate>, z: Option<f64>) {
|
|
origin.map(|origin| {
|
|
origin.map(|origin| {
|
|
- let delta: Coordinate = *self.core.origin - origin;
|
|
|
|
- *self.drawn_corner_a += delta;
|
|
|
|
- *self.drawn_corner_b += delta;
|
|
|
|
|
|
+ let delta: Coordinate = origin - *self.core.origin;
|
|
|
|
+ self.modifier.move_relative(delta);
|
|
});
|
|
});
|
|
self.core.move_absolute(origin, z);
|
|
self.core.move_absolute(origin, z);
|
|
}
|
|
}
|
|
|
|
|
|
fn move_relative(&mut self, delta: Option<Coordinate>, z: Option<f64>) {
|
|
fn move_relative(&mut self, delta: Option<Coordinate>, z: Option<f64>) {
|
|
delta.map(|delta| {
|
|
delta.map(|delta| {
|
|
- *self.drawn_corner_a += delta;
|
|
|
|
- *self.drawn_corner_b += delta;
|
|
|
|
|
|
+ self.modifier.move_relative(delta);
|
|
});
|
|
});
|
|
self.core.move_relative(delta, z);
|
|
self.core.move_relative(delta, z);
|
|
}
|
|
}
|