123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- use std::fmt::Debug;
- use binrw::{BinRead, BinWrite};
- use diff::Diff;
- use crate::{
- field_of::FieldOf,
- types::{Field, ObjectType, Point, F64},
- };
- use super::{ObjectCore, Translate};
- #[cfg_attr(feature = "default-debug", derive(Debug))]
- #[derive(BinRead, BinWrite, Clone, Diff, PartialEq)]
- #[diff(attr(
- #[derive(Debug, PartialEq)]
- ))]
- pub struct Rectangle {
- pub core: ObjectCore,
- #[brw(magic(8u32))] // Number of following fields in struct
- pub corner_a: FieldOf<Point>,
- pub corner_b: FieldOf<Point>,
- pub round_bottom_left: F64,
- pub round_bottom_right: F64,
- pub round_top_right: F64,
- pub round_top_left: F64,
- pub _unknown_1: [Field; 2],
- }
- // 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.corner_a)
- .field("corner_b", &self.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()
- }
- }
- impl Default for Rectangle {
- fn default() -> Self {
- Self {
- core: ObjectCore::default(ObjectType::Rectangle),
- corner_a: Point { x: 0.0, y: 0.0 }.into(),
- corner_b: Point { 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(),
- _unknown_1: [
- vec![0, 0, 0, 0].into(), // 0_u32
- vec![
- 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63,
- ] // ???
- .into(),
- ]
- .into(),
- }
- }
- }
- impl Translate for Rectangle {
- fn translate(&mut self, origin: Option<Point>, z: Option<f64>) {
- self.core.translate(origin, z);
- origin.map(|origin| {
- *self.corner_a += origin;
- *self.corner_b += origin;
- });
- }
- }
|