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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
pub mod curve;
pub mod cycle;
pub mod edge;
pub mod face;
pub mod path;
pub mod shell;
pub mod sketch;
pub mod solid;
pub mod tolerance;
use std::{
any::Any,
cmp::Ordering,
fmt::Debug,
hash::{Hash, Hasher},
rc::Rc,
};
use fj_math::Point;
use crate::objects::Curve;
pub use self::tolerance::{InvalidTolerance, Tolerance};
pub trait Approx: Sized {
type Approximation;
type Cache: Default;
fn approx(self, tolerance: impl Into<Tolerance>) -> Self::Approximation {
let mut cache = Self::Cache::default();
self.approx_with_cache(tolerance, &mut cache)
}
fn approx_with_cache(
self,
tolerance: impl Into<Tolerance>,
cache: &mut Self::Cache,
) -> Self::Approximation;
}
#[derive(Debug, Clone)]
pub struct ApproxPoint<const D: usize> {
pub local_form: Point<D>,
pub global_form: Point<3>,
pub source: Option<Rc<dyn Source>>,
}
impl<const D: usize> ApproxPoint<D> {
pub fn new(local_form: Point<D>, global_form: Point<3>) -> Self {
Self {
local_form,
global_form,
source: None,
}
}
pub fn with_source(self, source: impl Source) -> Self {
Self {
source: Some(Rc::new(source)),
..self
}
}
}
impl<const D: usize> Eq for ApproxPoint<D> {}
impl<const D: usize> PartialEq for ApproxPoint<D> {
fn eq(&self, other: &Self) -> bool {
self.local_form == other.local_form
&& self.global_form == other.global_form
}
}
impl<const D: usize> Hash for ApproxPoint<D> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.local_form.hash(state);
self.global_form.hash(state);
}
}
impl<const D: usize> Ord for ApproxPoint<D> {
fn cmp(&self, other: &Self) -> Ordering {
match self.local_form.cmp(&other.local_form) {
Ordering::Equal => {}
ord => return ord,
}
self.global_form.cmp(&other.global_form)
}
}
impl<const D: usize> PartialOrd for ApproxPoint<D> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
pub trait Source: Any + Debug {}
impl Source for (Curve, Point<1>) {}