circle.rs 2.0 KB

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