kcl_lib/std/
axis_or_reference.rs

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