#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct GdsTransformFlag {
pub reflect: bool, pub absolute_magnification: bool, pub absolute_angle: bool, }
impl GdsTransformFlag {
pub fn new(reflect: bool, absolute_magnification: bool, absolute_angle: bool) -> Self {
Self { reflect, absolute_angle, absolute_magnification }
}
pub fn from_u16(bits: u16) -> Self {
Self {
reflect: (bits & (1 << 15)) != 0, absolute_magnification: (bits & (1 << 2)) != 0, absolute_angle: (bits & (1 << 1)) != 0, }
}
pub fn to_u16(&self) -> u16 {
let mut bits = 0u16;
if self.reflect {
bits |= 1 << 15; }
if self.absolute_magnification {
bits |= 1 << 2; }
if self.absolute_angle {
bits |= 1 << 1; }
bits
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GdsTransform {
pub flag: GdsTransformFlag,
pub magnification: Option<f64>,
pub angle: Option<f64>,
}
impl GdsTransform {
pub fn with_flag(bits: u16) -> Self {
Self {
flag: GdsTransformFlag::from_u16(bits),
magnification: None,
angle: None,
}
}
pub fn magnification(&self) -> f64 {
self.magnification.unwrap_or(1.0)
}
pub fn angle(&self) -> f64 {
self.angle.unwrap_or(0.0)
}
}
impl GdsTransform {
pub fn identity() -> Self {
Self {
flag: GdsTransformFlag::default(),
magnification: None,
angle: None,
}
}
pub fn mirror_x() -> Self {
Self {
flag: GdsTransformFlag {
reflect: true,
absolute_magnification: false,
absolute_angle: false,
},
magnification: None,
angle: Some(0.0),
}
}
pub fn mirror_y() -> Self {
Self {
flag: GdsTransformFlag {
reflect: true,
absolute_magnification: false,
absolute_angle: false,
},
magnification: None,
angle: Some(180.0),
}
}
pub fn mirror_xy() -> Self {
Self {
flag: GdsTransformFlag {
reflect: false,
absolute_magnification: false,
absolute_angle: false,
},
magnification: None,
angle: Some(180.0),
}
}
pub fn with_magnification(mut self, m: f64) -> Self {
assert!(m > 0.0, "magnification must be positive");
self.magnification = Some(m);
self
}
pub fn with_rotation(mut self, angle_deg: f64) -> Self {
self.angle = Some(angle_deg);
self
}
pub fn absolute_magnification(mut self) -> Self {
self.flag.absolute_magnification = true;
self
}
pub fn absolute_angle(mut self) -> Self {
self.flag.absolute_angle = true;
self
}
}