ellipse.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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, U32},
  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 Ellipse {
  15. pub core: ObjectCore,
  16. #[brw(magic(8u32))] // Number of following fields in struct
  17. pub clockwise: U32,
  18. pub corner_a: FieldOf<Point>,
  19. pub corner_b: FieldOf<Point>,
  20. pub start_angle: F64, // Radians
  21. pub end_angle: F64, // Radians
  22. pub _unknown_1: [Field; 2],
  23. pub open_curve: U32,
  24. }
  25. // Custom Debug implementation to only print known fields
  26. #[cfg(not(feature = "default-debug"))]
  27. impl Debug for Ellipse {
  28. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  29. f.debug_struct("Ellipse")
  30. .field("core", &self.core)
  31. .field("clockwise", &self.clockwise)
  32. .field("corner_a", &self.corner_a)
  33. .field("corner_b", &self.corner_b)
  34. .field("start_angle", &self.start_angle)
  35. .field("end_angle", &self.end_angle)
  36. .field("open_curve", &self.open_curve)
  37. .finish()
  38. }
  39. }
  40. impl Default for Ellipse {
  41. fn default() -> Self {
  42. Self {
  43. core: ObjectCore::default(ObjectType::Ellipse),
  44. clockwise: 0.into(),
  45. corner_a: Point { x: 0.0, y: 0.0 }.into(),
  46. corner_b: Point { x: 0.0, y: 0.0 }.into(),
  47. start_angle: 0.0.into(),
  48. end_angle: 0.0.into(),
  49. _unknown_1: [
  50. vec![0, 0, 0, 0].into(), // 0_u32
  51. vec![
  52. 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,
  53. 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,
  54. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63,
  55. ] // ???
  56. .into(),
  57. ],
  58. open_curve: 0.into(),
  59. }
  60. }
  61. }
  62. impl Translate for Ellipse {
  63. fn translate(&mut self, origin: Option<Point>, z: Option<f64>) {
  64. self.core.translate(origin, z);
  65. origin.map(|origin| {
  66. *self.corner_a += origin;
  67. *self.corner_b += origin;
  68. });
  69. }
  70. }