Skip to main content

reda_gds/models/
sref.rs

1use derive_builder::Builder;
2use crate::{GdsCoord, GdsTransform};
3
4#[derive(Debug, Clone, Builder)]
5#[builder(setter(strip_option))]
6pub struct GdsSref {
7    #[builder(default)]
8    pub elf_flags: Option<i16>,
9    #[builder(default)]
10    pub plex: Option<i32>,
11
12    pub s_name: String,
13    
14    #[builder(default)]
15    pub transform: Option<GdsTransform>,
16    
17    pub position: GdsCoord,
18}
19
20impl GdsSref {
21    pub fn new(ref_name: impl Into<String>, position: impl Into<GdsCoord>, transform: Option<GdsTransform>) -> Self {
22        Self {
23            elf_flags: None,
24            plex: None,
25            s_name: ref_name.into(),
26            transform,
27            position: position.into()
28        }
29    }
30
31    pub fn position(&self) -> GdsCoord {
32        self.position
33    }
34
35    pub fn magnification(&self) -> f64 {
36        self.transform.map(|t| t.magnification()).unwrap_or(1.0)
37    }
38
39    pub fn angle(&self) -> f64 {
40        self.transform.map(|t| t.angle()).unwrap_or(0.0)
41    }
42}