Another project
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.9 kB View raw
1use bone_types::{Aabb3, ChordHeightTolerance, Parameter, Point3, Tolerance, Vec3}; 2 3use crate::arc3::Arc3; 4use crate::circle3::Circle3; 5use crate::closest::ClosestPoint3; 6use crate::line3::Line3; 7 8pub trait Curve3 { 9 fn evaluate(&self, t: Parameter) -> Point3; 10 fn derivative(&self, t: Parameter) -> Vec3; 11 fn bounding_box(&self) -> Aabb3; 12 fn closest_point(&self, p: Point3, tolerance: Tolerance) -> ClosestPoint3; 13 fn tessellate(&self, tolerance: ChordHeightTolerance) -> Vec<Point3>; 14} 15 16#[derive(Copy, Clone, Debug, PartialEq)] 17pub enum Curve3Kind { 18 Line(Line3), 19 Arc(Arc3), 20 Circle(Circle3), 21} 22 23impl Curve3 for Curve3Kind { 24 fn evaluate(&self, t: Parameter) -> Point3 { 25 match self { 26 Self::Line(c) => c.evaluate(t), 27 Self::Arc(c) => c.evaluate(t), 28 Self::Circle(c) => c.evaluate(t), 29 } 30 } 31 fn derivative(&self, t: Parameter) -> Vec3 { 32 match self { 33 Self::Line(c) => c.derivative(t), 34 Self::Arc(c) => c.derivative(t), 35 Self::Circle(c) => c.derivative(t), 36 } 37 } 38 fn bounding_box(&self) -> Aabb3 { 39 match self { 40 Self::Line(c) => c.bounding_box(), 41 Self::Arc(c) => c.bounding_box(), 42 Self::Circle(c) => c.bounding_box(), 43 } 44 } 45 fn closest_point(&self, p: Point3, tolerance: Tolerance) -> ClosestPoint3 { 46 match self { 47 Self::Line(c) => c.closest_point(p, tolerance), 48 Self::Arc(c) => c.closest_point(p, tolerance), 49 Self::Circle(c) => c.closest_point(p, tolerance), 50 } 51 } 52 fn tessellate(&self, tolerance: ChordHeightTolerance) -> Vec<Point3> { 53 match self { 54 Self::Line(c) => c.tessellate(tolerance), 55 Self::Arc(c) => c.tessellate(tolerance), 56 Self::Circle(c) => c.tessellate(tolerance), 57 } 58 } 59}