rectangle.rs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. use std::fmt::Debug;
  2. use binrw::{BinRead, BinWrite};
  3. use diff::Diff;
  4. use crate::{
  5. field_of::FieldOf,
  6. types::{Field, ObjectType, Point, F64},
  7. };
  8. use super::{ObjectCore, Translate};
  9. #[cfg_attr(feature = "default-debug", derive(Debug))]
  10. #[derive(BinRead, BinWrite, Clone, Diff, PartialEq)]
  11. #[diff(attr(
  12. #[derive(Debug, PartialEq)]
  13. ))]
  14. pub struct Rectangle {
  15. pub core: ObjectCore,
  16. #[brw(magic(8u32))] // Number of following fields in struct
  17. pub corner_a: FieldOf<Point>,
  18. pub corner_b: FieldOf<Point>,
  19. pub round_bottom_left: F64,
  20. pub round_bottom_right: F64,
  21. pub round_top_right: F64,
  22. pub round_top_left: F64,
  23. pub _unknown_1: [Field; 2],
  24. }
  25. // Custom Debug implementation to only print known fields
  26. #[cfg(not(feature = "default-debug"))]
  27. impl Debug for Rectangle {
  28. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  29. f.debug_struct("Rectangle")
  30. .field("core", &self.core)
  31. .field("corner_a", &self.corner_a)
  32. .field("corner_b", &self.corner_b)
  33. .field("round_bottom_left", &self.round_bottom_left)
  34. .field("round_bottom_right", &self.round_bottom_right)
  35. .field("round_top_right", &self.round_top_right)
  36. .field("round_top_left", &self.round_top_left)
  37. .finish()
  38. }
  39. }
  40. impl Default for Rectangle {
  41. fn default() -> Self {
  42. Self {
  43. core: ObjectCore::default(ObjectType::Rectangle),
  44. corner_a: Point { x: 0.0, y: 0.0 }.into(),
  45. corner_b: Point { x: 0.0, y: 0.0 }.into(),
  46. round_bottom_left: 0.0.into(),
  47. round_bottom_right: 0.0.into(),
  48. round_top_right: 0.0.into(),
  49. round_top_left: 0.0.into(),
  50. _unknown_1: [
  51. vec![0, 0, 0, 0].into(), // 0_u32
  52. vec![
  53. 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,
  54. 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,
  55. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63,
  56. ] // ???
  57. .into(),
  58. ]
  59. .into(),
  60. }
  61. }
  62. }
  63. impl Translate for Rectangle {
  64. fn translate(&mut self, origin: Option<Point>, z: Option<f64>) {
  65. self.core.translate(origin, z);
  66. origin.map(|origin| {
  67. *self.corner_a += origin;
  68. *self.corner_b += origin;
  69. });
  70. }
  71. }