|
@@ -1,84 +1,83 @@
|
|
-use std::fmt::{Debug, Display};
|
|
|
|
-
|
|
|
|
-use binrw::{BinRead, BinWrite};
|
|
|
|
-use diff::Diff;
|
|
|
|
-
|
|
|
|
-use crate::{
|
|
|
|
- field_of::FieldOf,
|
|
|
|
- types::{Coordinate, ObjectType, F64},
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-use super::{ObjectCore, ObjectModifier, Translate};
|
|
|
|
-
|
|
|
|
-#[derive(BinRead, BinWrite, Clone, Debug, Diff, PartialEq)]
|
|
|
|
-#[diff(attr(
|
|
|
|
- #[derive(Debug, PartialEq)]
|
|
|
|
-))]
|
|
|
|
-pub struct Rectangle {
|
|
|
|
- pub core: ObjectCore,
|
|
|
|
- #[brw(magic(8u32))] // Number of following fields in struct
|
|
|
|
- pub drawn_corner_a: FieldOf<Coordinate>,
|
|
|
|
- pub drawn_corner_b: FieldOf<Coordinate>,
|
|
|
|
- pub round_bottom_left: F64,
|
|
|
|
- pub round_bottom_right: F64,
|
|
|
|
- pub round_top_right: F64,
|
|
|
|
- pub round_top_left: F64,
|
|
|
|
- pub modifier: ObjectModifier,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-impl Display for Rectangle {
|
|
|
|
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
- let width: f64 = (self.drawn_corner_a.x.max(self.drawn_corner_b.x)
|
|
|
|
- - self.drawn_corner_a.x.min(self.drawn_corner_b.x))
|
|
|
|
- * self.modifier.modifiers.x_scale;
|
|
|
|
- let height: f64 = (self.drawn_corner_a.y.max(self.drawn_corner_b.y)
|
|
|
|
- - self.drawn_corner_a.y.min(self.drawn_corner_b.y))
|
|
|
|
- * self.modifier.modifiers.y_scale;
|
|
|
|
-
|
|
|
|
- let drawn_origin: Coordinate =
|
|
|
|
- (*self.drawn_corner_a + *self.drawn_corner_b) / Coordinate { x: 2.0, y: 2.0 };
|
|
|
|
-
|
|
|
|
- write!(
|
|
|
|
- f,
|
|
|
|
- "{}, Origin: {}, Width: {:.2}, Height: {:.2}",
|
|
|
|
- self.core,
|
|
|
|
- self.modifier.correction() + drawn_origin * self.modifier.scale(),
|
|
|
|
- width,
|
|
|
|
- height,
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-impl Default for Rectangle {
|
|
|
|
- fn default() -> Self {
|
|
|
|
- Self {
|
|
|
|
- core: ObjectCore::default(ObjectType::Rectangle),
|
|
|
|
- drawn_corner_a: Coordinate { x: 0.0, y: 0.0 }.into(),
|
|
|
|
- drawn_corner_b: Coordinate { x: 0.0, y: 0.0 }.into(),
|
|
|
|
- round_bottom_left: 0.0.into(),
|
|
|
|
- round_bottom_right: 0.0.into(),
|
|
|
|
- round_top_right: 0.0.into(),
|
|
|
|
- round_top_left: 0.0.into(),
|
|
|
|
- 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 {
|
|
|
|
- fn move_absolute(&mut self, origin: Option<Coordinate>, z: Option<f64>) {
|
|
|
|
- origin.map(|origin| {
|
|
|
|
- let delta: Coordinate = origin - *self.core.origin;
|
|
|
|
- self.modifier.move_relative(delta);
|
|
|
|
- });
|
|
|
|
- self.core.move_absolute(origin, z);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- fn move_relative(&mut self, delta: Option<Coordinate>, z: Option<f64>) {
|
|
|
|
- delta.map(|delta| {
|
|
|
|
- self.modifier.move_relative(delta);
|
|
|
|
- });
|
|
|
|
- self.core.move_relative(delta, z);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+use std::fmt::{Debug, Display};
|
|
|
|
+
|
|
|
|
+use binrw::{BinRead, BinWrite};
|
|
|
|
+use diff::Diff;
|
|
|
|
+use log::warn;
|
|
|
|
+
|
|
|
|
+use crate::{
|
|
|
|
+ field_of::FieldOf,
|
|
|
|
+ types::{Coordinate, ObjectType, F64},
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+use super::{ObjectCore, ObjectModifier, Translate};
|
|
|
|
+
|
|
|
|
+#[derive(BinRead, BinWrite, Clone, Debug, Diff, PartialEq)]
|
|
|
|
+#[diff(attr(
|
|
|
|
+ #[derive(Debug, PartialEq)]
|
|
|
|
+))]
|
|
|
|
+pub struct Rectangle {
|
|
|
|
+ pub core: ObjectCore,
|
|
|
|
+ #[brw(magic(8u32))] // Number of following fields in struct
|
|
|
|
+ pub drawn_corner_a: FieldOf<Coordinate>,
|
|
|
|
+ pub drawn_corner_b: FieldOf<Coordinate>,
|
|
|
|
+ pub round_bottom_left: F64,
|
|
|
|
+ pub round_bottom_right: F64,
|
|
|
|
+ pub round_top_right: F64,
|
|
|
|
+ pub round_top_left: F64,
|
|
|
|
+ pub modifier: ObjectModifier,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl Display for Rectangle {
|
|
|
|
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
+ let (origin, width, height) = self
|
|
|
|
+ .modifier
|
|
|
|
+ .corrected(*self.drawn_corner_a, *self.drawn_corner_b);
|
|
|
|
+
|
|
|
|
+ if format!("{}", origin) != format!("{}", *self.core.origin) {
|
|
|
|
+ warn!(
|
|
|
|
+ "Origin mismatch! Core: {}, Calculated: {}",
|
|
|
|
+ *self.core.origin, origin
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ write!(
|
|
|
|
+ f,
|
|
|
|
+ "{}, Origin: {}, Width: {:.2}, Height: {:.2}",
|
|
|
|
+ self.core, origin, width, height,
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl Default for Rectangle {
|
|
|
|
+ fn default() -> Self {
|
|
|
|
+ Self {
|
|
|
|
+ core: ObjectCore::default(ObjectType::Rectangle),
|
|
|
|
+ drawn_corner_a: Coordinate { x: 0.0, y: 0.0 }.into(),
|
|
|
|
+ drawn_corner_b: Coordinate { x: 0.0, y: 0.0 }.into(),
|
|
|
|
+ round_bottom_left: 0.0.into(),
|
|
|
|
+ round_bottom_right: 0.0.into(),
|
|
|
|
+ round_top_right: 0.0.into(),
|
|
|
|
+ round_top_left: 0.0.into(),
|
|
|
|
+ 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 {
|
|
|
|
+ fn move_absolute(&mut self, origin: Option<Coordinate>, z: Option<f64>) {
|
|
|
|
+ origin.map(|origin| {
|
|
|
|
+ let delta: Coordinate = origin - *self.core.origin;
|
|
|
|
+ self.modifier.move_relative(delta);
|
|
|
|
+ });
|
|
|
|
+ self.core.move_absolute(origin, z);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn move_relative(&mut self, delta: Option<Coordinate>, z: Option<f64>) {
|
|
|
|
+ delta.map(|delta| {
|
|
|
|
+ self.modifier.move_relative(delta);
|
|
|
|
+ });
|
|
|
|
+ self.core.move_relative(delta, z);
|
|
|
|
+ }
|
|
|
|
+}
|