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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//! Maps a rasterized `facet_id` (a plane index, see `raster::SolidRasterizer::pick_at`)
//! back to the tier/orbit-member it came from, for hover/click/selection and the
//! critical-angle overlay.
//!
//! # Mirroring `Design::planes_from_solved`'s plane order exactly
//!
//! [`FacetMap::from_design`] must assign facet ids that line up 1:1 with
//! `indicatrix_cut_core::Design::planes_from_solved`'s output (`preform.planes()` first,
//! then one plane per (tier, index-on-gear) pair), since that plane slice is exactly
//! what `build_solid_mesh` -- and therefore `pick_at`'s `facet_id` -- indexes into.
//!
//! `StandardGemCuts::from_asc_schedule` is not a simple flatten: its last step is
//! `dedup_planes`, a linear, first-occurrence-wins scan dropping any facet whose
//! normal/offset are within tolerance of one already kept, with no "give me the
//! provenance" entry point, so this module reimplements the same three steps against
//! `Design`'s own tier list: (1) the same crown/pavilion side rule, the shared
//! `indicatrix::geometry::plane::tier_is_crown_side` (sign of the angle, including
//! the sign of a zero); (2) the same
//! per-(tier, index) normal construction (`sin`/`cos` of `theta = angle_deg.abs()`,
//! azimuth from `StandardGemCuts::index_to_azimuth`, which applies the schedule's
//! gear reference angle) at `f32` precision; (3) the same first-occurrence-wins
//! dedup: the shared `indicatrix::geometry::cuts::normals_coincide` rule on the
//! normals and an offset tolerance of `1/2048` relative to `max(|d|, 1)`.
//!
//! A candidate carries its `(tier_index, index_on_gear)` provenance through all
//! three steps, so the facet id a surviving candidate ends up at is the exact index
//! [`Design::planes_from_solved`] gives the same plane, by construction rather than
//! by re-matching floats after the fact.
//!
//! # Concave facets
//!
//! A design's concave tiers resolve to tools, and a tool is one more facet of the
//! stone: tool `k` has facet id `plane_count + k`. [`FacetMap::from_design_with_tools`]
//! appends those ids *after* the flat ones from the `(concave tier, placement)` list
//! `Design::concave_tools_from_solved` returns, so the flat construction above is not
//! touched and a design without concave tiers builds the identical map.
use Vec3;
use Block;
/// Whether a facet is one of the stone's flat planes or the surface a concave tool
/// cut into it.
/// Everything this map remembers about one facet beyond its bare plane equation.
///
/// `tier_index` is `None` for a preform plane (the rough's own bounding planes,
/// preceding every schedule-derived facet); other fields are placeholders then. It is
/// also `None` for a concave facet, whose tier lives in a different list: read
/// [`Self::kind`] for that.
/// The critical-angle-overlay and selection-tint flags [`FacetMap::overlay_flags`]
/// produces.
///
/// Sized to the full plane count and indexed by `facet_id` -- ready to
/// drop straight into `raster::SolidStyle::flagged`/`pending`/`selected`.
/// Maps every `facet_id` (plane index) in `Design::planes_from_solved`'s output back
/// to the tier/orbit-member it came from (see this module's doc comment).
/// One (tier, index-on-gear) candidate plane, carrying its provenance through the
/// dedup pass.
/// Relative offset tolerance of the plane builder's dedup (module doc, step 3): two
/// offsets merge when they differ by at most this times `max(|d_a|, |d_b|, 1)`.
const OFFSET_REL_EPSILON: f32 = 1.0 / 2048.0;