Skip to main content

kcl_lib/std/
axis_or_reference.rs

1//! Types for referencing an axis or edge.
2
3use super::args::TyF64;
4use crate::execution::Plane;
5use crate::execution::Sketch;
6use crate::execution::Solid;
7use crate::execution::TagIdentifier;
8use crate::std::fillet::EdgeReference;
9use crate::std::sketch::FaceTag;
10
11/// A 2D axis or tagged edge.
12#[derive(Debug, Clone, PartialEq)]
13pub enum Axis2dOrEdgeReference {
14    /// 2D axis and origin.
15    Axis { direction: [TyF64; 2], origin: [TyF64; 2] },
16    /// Tagged edge.
17    Edge(EdgeReference),
18}
19
20/// A 3D axis or tagged edge.
21#[allow(clippy::large_enum_variant)]
22#[derive(Debug, Clone, PartialEq)]
23pub enum Axis3dOrEdgeReference {
24    /// 3D axis and origin.
25    Axis { direction: [TyF64; 3], origin: [TyF64; 3] },
26    /// Tagged edge.
27    Edge(EdgeReference),
28}
29
30/// A 2D axis or a raw point2d.
31#[derive(Debug, Clone, PartialEq)]
32pub enum Axis2dOrPoint2d {
33    /// 2D axis and origin.
34    Axis { direction: [TyF64; 2], origin: [TyF64; 2] },
35    /// Raw point2d.
36    Point([TyF64; 2]),
37}
38
39impl Axis2dOrPoint2d {
40    /// Convert to a 2D axis.
41    pub fn to_point2d(&self) -> [TyF64; 2] {
42        match self {
43            Axis2dOrPoint2d::Axis { direction, origin: _ } => direction.clone(),
44            Axis2dOrPoint2d::Point(point) => point.clone(),
45        }
46    }
47}
48
49/// A 3D axis or a raw point3d.
50#[derive(Debug, Clone, PartialEq)]
51pub enum Axis3dOrPoint3d {
52    /// 3D axis and origin.
53    Axis { direction: [TyF64; 3], origin: [TyF64; 3] },
54    /// Raw point3d.
55    Point([TyF64; 3]),
56}
57
58impl Axis3dOrPoint3d {
59    /// Convert to a 3D axis.
60    pub fn to_point3d(&self) -> [TyF64; 3] {
61        match self {
62            Axis3dOrPoint3d::Axis { direction, origin: _ } => direction.clone(),
63            Axis3dOrPoint3d::Point(point) => point.clone(),
64        }
65    }
66
67    pub fn axis_origin(&self) -> Option<[TyF64; 3]> {
68        match self {
69            Axis3dOrPoint3d::Axis { origin, .. } => Some(origin.clone()),
70            Axis3dOrPoint3d::Point(..) => None,
71        }
72    }
73}
74
75/// A raw point3d, 3D axis, Edge, Face, Solid or Tag.
76#[allow(clippy::large_enum_variant)]
77#[derive(Debug, Clone, PartialEq)]
78pub enum Point3dAxis3dOrGeometryReference {
79    /// Raw point3d.
80    Point([TyF64; 3]),
81    /// 3D axis and origin.
82    Axis { direction: [TyF64; 3], origin: [TyF64; 3] },
83    /// Plane.
84    Plane(Box<Plane>),
85    /// Edge Reference.
86    Edge(EdgeReference),
87    /// Face.
88    Face(FaceTag),
89    /// Sketch.
90    Sketch(Box<Sketch>),
91    /// Solid.
92    Solid(Box<Solid>),
93    /// Tagged edge or face.
94    TaggedEdgeOrFace(TagIdentifier),
95}