1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use super::AsConstraintData;
use crate::{
    bindings::{Slvs_Constraint, Slvs_hEntity, Slvs_hGroup, SLVS_C_ARC_ARC_DIFFERENCE},
    element::{AsHandle, TypeInfo},
    entity::{ArcOfCircle, Entity},
    group::Group,
};

#[derive(Clone, Copy, Debug)]
pub struct ArcArcDifference {
    pub group: Group,
    pub arc_a: Entity<ArcOfCircle>,
    pub arc_b: Entity<ArcOfCircle>,
    pub difference: f64,
}

impl ArcArcDifference {
    pub fn new(
        group: Group,
        arc_a: Entity<ArcOfCircle>,
        arc_b: Entity<ArcOfCircle>,
        difference: f64,
    ) -> Self {
        Self {
            group,
            arc_a,
            arc_b,
            difference,
        }
    }
}

impl AsConstraintData for ArcArcDifference {
    fn type_(&self) -> i32 {
        SLVS_C_ARC_ARC_DIFFERENCE as _
    }

    fn workplane(&self) -> Option<Slvs_hEntity> {
        None
    }

    fn group(&self) -> Slvs_hGroup {
        self.group.handle()
    }

    fn entities(&self) -> Option<Vec<Slvs_hEntity>> {
        Some(vec![self.arc_a.handle(), self.arc_b.handle()])
    }

    fn val(&self) -> Option<f64> {
        Some(self.difference)
    }
}

impl TypeInfo for ArcArcDifference {
    fn type_of() -> String {
        "ArcArcDifference".to_string()
    }
}

impl From<Slvs_Constraint> for ArcArcDifference {
    fn from(value: Slvs_Constraint) -> Self {
        Self {
            group: Group(value.group),
            arc_a: Entity::new(value.entityA),
            arc_b: Entity::new(value.entityB),
            difference: value.valA,
        }
    }
}