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
use super::*;
pub trait ParametricSurface: Clone {
type Point;
type Vector;
fn subs(&self, u: f64, v: f64) -> Self::Point;
fn uder(&self, u: f64, v: f64) -> Self::Vector;
fn vder(&self, u: f64, v: f64) -> Self::Vector;
fn uuder(&self, u: f64, v: f64) -> Self::Vector;
fn uvder(&self, u: f64, v: f64) -> Self::Vector;
fn vvder(&self, u: f64, v: f64) -> Self::Vector;
}
impl<'a, S: ParametricSurface> ParametricSurface for &'a S {
type Point = S::Point;
type Vector = S::Vector;
fn subs(&self, u: f64, v: f64) -> Self::Point { (*self).subs(u, v) }
fn uder(&self, u: f64, v: f64) -> Self::Vector { (*self).uder(u, v) }
fn vder(&self, u: f64, v: f64) -> Self::Vector { (*self).vder(u, v) }
fn uuder(&self, u: f64, v: f64) -> Self::Vector { (*self).uuder(u, v) }
fn uvder(&self, u: f64, v: f64) -> Self::Vector { (*self).uvder(u, v) }
fn vvder(&self, u: f64, v: f64) -> Self::Vector { (*self).vvder(u, v) }
}
pub trait ParametricSurface2D: ParametricSurface<Point = Point2, Vector = Vector2> {}
impl<S: ParametricSurface<Point = Point2, Vector = Vector2>> ParametricSurface2D for S {}
pub trait ParametricSurface3D: ParametricSurface<Point = Point3, Vector = Vector3> {
fn normal(&self, u: f64, v: f64) -> Vector3 {
self.uder(u, v).cross(self.vder(u, v)).normalize()
}
}
impl<'a, S: ParametricSurface3D> ParametricSurface3D for &'a S {
fn normal(&self, u: f64, v: f64) -> Vector3 { (*self).normal(u, v) }
}
pub trait BoundedSurface: ParametricSurface {
fn parameter_range(&self) -> ((f64, f64), (f64, f64));
}
impl<'a, S: BoundedSurface> BoundedSurface for &'a S {
fn parameter_range(&self) -> ((f64, f64), (f64, f64)) {
(*self).parameter_range()
}
}
pub trait IncludeCurve<C: ParametricCurve> {
fn include(&self, curve: &C) -> bool;
}
pub trait ParameterDivision2D {
fn parameter_division(&self, range: ((f64, f64), (f64, f64)), tol: f64) -> (Vec<f64>, Vec<f64>);
}
impl<'a, S: ParameterDivision2D> ParameterDivision2D for &'a S {
fn parameter_division(&self, range: ((f64, f64), (f64, f64)), tol: f64) -> (Vec<f64>, Vec<f64>) {
(*self).parameter_division(range, tol)
}
}
impl ParametricSurface for () {
type Point = ();
type Vector = ();
fn subs(&self, _: f64, _: f64) -> Self::Point {}
fn uder(&self, _: f64, _: f64) -> Self::Vector {}
fn vder(&self, _: f64, _: f64) -> Self::Vector {}
fn uuder(&self, _: f64, _: f64) -> Self::Vector {}
fn uvder(&self, _: f64, _: f64) -> Self::Vector {}
fn vvder(&self, _: f64, _: f64) -> Self::Vector {}
}
impl BoundedSurface for () {
fn parameter_range(&self) -> ((f64, f64), (f64, f64)) { ((0.0, 1.0), (0.0, 1.0)) }
}
impl IncludeCurve<()> for () {
fn include(&self, _: &()) -> bool { true }
}