kernel_api/queries.rs
1//! The queries a built solid or mesh answers, which the kernel adapter
2//! implements.
3
4use crate::*;
5
6pub trait KernelQueries: Send + Sync {
7 /// The wall thickness of `target` at each point, `NaN` where none is
8 /// found within reach.
9 fn thickness(
10 &self,
11 _target: DistanceTarget<'_>,
12 _request: &ThicknessRequest,
13 ) -> KernelResult<Vec<f64>> {
14 Err(KernelError::Unsupported("thickness".into()))
15 }
16
17 /// The sections of `mesh` by the plane through `origin` square to
18 /// `normal`, moved along it by each of `offsets`: one list of chains
19 /// per offset, in their order. Each chain runs with the material on
20 /// its left seen from the side `normal` points to.
21 fn mesh_sections(
22 &self,
23 _mesh: &TriMesh,
24 _origin: [f64; 3],
25 _normal: [f64; 3],
26 _offsets: &[f64],
27 ) -> KernelResult<Vec<Vec<SectionChain>>> {
28 Err(KernelError::Unsupported("mesh_sections".into()))
29 }
30
31 /// The shadow `mesh` casts on `request.plane` seen along its normal,
32 /// and an outline fitted around it within `request`'s band.
33 fn mesh_shadow(&self, _mesh: &TriMesh, _request: &ShadowRequest) -> KernelResult<ShadowAnswer> {
34 Err(KernelError::Unsupported("mesh_shadow".into()))
35 }
36
37 /// Lines and arcs fitted to a 2D chain of points, every point within
38 /// `fit.tolerance` of its piece and the pieces meeting end to end: a
39 /// polyline whose bulges give the arcs, or a circle where one holds a
40 /// closed chain.
41 fn fit_chain_2d(&self, _points: &[[f64; 2]], _fit: &ChainFit) -> KernelResult<DrawingShape> {
42 Err(KernelError::Unsupported("fit_chain_2d".into()))
43 }
44
45 /// `start` with `ops` applied in turn: a mesh body's history.
46 fn build_mesh_chain(&self, _start: &TriMesh, _ops: &[MeshOp]) -> KernelResult<MeshChainAnswer> {
47 Err(KernelError::Unsupported("build_mesh_chain".into()))
48 }
49
50 /// The mesh as a file of `format` (`stl`, `3mf`, `ply` or `obj`),
51 /// its triangles as they are, in millimetres.
52 fn write_mesh(&self, _mesh: &TriMesh, _format: &str) -> KernelResult<Vec<u8>> {
53 Err(KernelError::Unsupported("write_mesh".into()))
54 }
55
56 /// A solid trimmed to where a scan breaks off.
57 fn trim_to_scan(&self, _request: &TrimRequest) -> KernelResult<TrimAnswer> {
58 Err(KernelError::Unsupported("trim_to_scan".into()))
59 }
60
61 /// A DXF drawing of polylines in millimetres: `visible` continuous,
62 /// `hidden` dashed, each on a layer of its own.
63 fn write_dxf(
64 &self,
65 _visible: &[Vec<[f64; 2]>],
66 _hidden: &[Vec<[f64; 2]>],
67 ) -> KernelResult<String> {
68 Err(KernelError::Unsupported("write_dxf".into()))
69 }
70
71 /// A drawing as an R2000 DXF, each curve and text as itself on its
72 /// layer (a layer draws dashed when its curves are hidden), its unit
73 /// declared from `unit_mm` (1 millimetres, 25.4 inches, none
74 /// unitless).
75 fn write_dxf_drawing(&self, _drawing: &Drawing2d) -> KernelResult<String> {
76 Err(KernelError::Unsupported("write_dxf_drawing".into()))
77 }
78
79 /// A STEP file of one part, `part`, holding `items` as its construction
80 /// geometry and no solid.
81 fn write_construction_step(
82 &self,
83 _part: &str,
84 _items: &[ConstructionItem],
85 ) -> KernelResult<Vec<u8>> {
86 Err(KernelError::Unsupported("write_construction_step".into()))
87 }
88
89 /// An IGES file holding `items` as construction geometry and no solid,
90 /// with warnings for geometry or names the writer cannot carry in full.
91 fn write_construction_iges(
92 &self,
93 _part: &str,
94 _items: &[ConstructionItem],
95 ) -> KernelResult<IgesExport> {
96 Err(KernelError::Unsupported("write_construction_iges".into()))
97 }
98
99 /// An upright frame inferred from the scan's faces, walls and open rims.
100 fn orient(&self, _mesh: &TriMesh) -> KernelResult<Orientation> {
101 Err(KernelError::Unsupported("orient".into()))
102 }
103
104 /// The best mirror plane seeded from the scan's principal frame.
105 fn symmetry_plane(&self, _mesh: &TriMesh) -> KernelResult<SymmetryPlane> {
106 Err(KernelError::Unsupported("symmetry_plane".into()))
107 }
108
109 /// The rigid motion that brings `request`'s points best onto
110 /// `target`'s surface.
111 fn register(
112 &self,
113 _target: DistanceTarget<'_>,
114 _request: &RegisterRequest,
115 ) -> KernelResult<Registration> {
116 Err(KernelError::Unsupported("register".into()))
117 }
118
119 /// Where `scan`, given in the solid's frame, and the native-format
120 /// solid `solid` differ, as regions on a grid of cells `cell` wide,
121 /// largest first. Holes in the scan read as the solid.
122 fn volume_difference(
123 &self,
124 _scan: &TriMesh,
125 _solid: &[u8],
126 _cell: f64,
127 ) -> KernelResult<Vec<VolumeRegion>> {
128 Err(KernelError::Unsupported("volume_difference".into()))
129 }
130
131 /// Each point's signed distance to `target`'s surface, positive
132 /// outside it, `NaN` where nothing lies within reach.
133 fn signed_distance(
134 &self,
135 _target: DistanceTarget<'_>,
136 _request: &DistanceRequest,
137 ) -> KernelResult<Vec<f64>> {
138 Err(KernelError::Unsupported("signed_distance".into()))
139 }
140
141 /// Grow a region of `request.kind` over `mesh` from its seeds, joining
142 /// triangles while they lie on one surface, and fit it.
143 fn grow(&self, _mesh: &TriMesh, _request: &GrowRequest) -> KernelResult<GrowAnswer> {
144 Err(KernelError::Unsupported("grow".into()))
145 }
146
147 /// Every edge two faces of `brep` share, with how they meet there.
148 fn continuity(&self, _brep: &[u8]) -> KernelResult<Vec<EdgeContinuity>> {
149 Err(KernelError::Unsupported("continuity".into()))
150 }
151
152 /// The shape of `request.kind` that fits its points best: orthogonal
153 /// least squares, started robustly, with what it rests on.
154 fn fit(&self, _request: &FitRequest) -> KernelResult<FitAnswer> {
155 Err(KernelError::Unsupported("fit".into()))
156 }
157
158 /// `kind` fitted to every one of `points` by `method`, a zone or a
159 /// mating fit rather than a mean one; `converged` says whether the zone
160 /// is certified optimal. `form` is the zone's two boundaries as signed
161 /// distances from the shape, its width their difference.
162 fn zone_fit(
163 &self,
164 _kind: FitKind,
165 _method: FitMethod,
166 _points: &[[f64; 3]],
167 ) -> KernelResult<FitAnswer> {
168 Err(KernelError::Unsupported("zone_fit".into()))
169 }
170
171 /// The principal curvatures of `brep`'s faces at points on them. Each
172 /// entry names a face by a point inside it (the face nearest that
173 /// point) and lists points on it, each with the normal it is signed
174 /// against, in the shape's own frame; the answer gives, per point, the
175 /// largest and the smallest normal curvature (1/mm): negative where the
176 /// face bulges toward that normal, positive where it hollows away.
177 /// `None` where the surface has no normal (a pole, an apex).
178 fn curvature(
179 &self,
180 _brep: &[u8],
181 _faces: &[FacePoints],
182 ) -> KernelResult<Vec<Vec<Option<[f64; 2]>>>> {
183 Err(KernelError::Unsupported("curvature".into()))
184 }
185
186 /// The edges bounding the face of `brep` nearest `near`: a point on
187 /// each, halfway along, and its direction there, in the shape's own
188 /// frame. A seam (the edge a round face meets itself along) and an
189 /// edge with no curve (a pole) are left out.
190 fn face_edges(&self, _brep: &[u8], _near: [f64; 3]) -> KernelResult<Vec<([f64; 3], [f64; 3])>> {
191 Err(KernelError::Unsupported("face_edges".into()))
192 }
193
194 /// The round holes of `brep`, in its own frame, and how many bores it
195 /// has that are not holes it can describe (a counterbore, a slot).
196 fn recognize_holes(&self, _brep: &[u8]) -> KernelResult<(Vec<RecognizedHole>, usize)> {
197 Err(KernelError::Unsupported("recognize_holes".into()))
198 }
199
200 /// What `a` and `b` share when `b` sits where `b_in_a` (a rigid
201 /// row-major 4×4 matrix) puts it in `a`'s frame; `None` when they only
202 /// touch or are apart.
203 fn overlap(
204 &self,
205 _a: &[u8],
206 _b: &[u8],
207 _b_in_a: &[[f64; 4]; 4],
208 ) -> KernelResult<Option<Overlap>> {
209 Err(KernelError::Unsupported("overlap".into()))
210 }
211
212 /// How near `a` and `b` come when `b` sits where `b_in_a` puts it in
213 /// `a`'s frame.
214 fn gap(&self, _a: &[u8], _b: &[u8], _b_in_a: &[[f64; 4]; 4]) -> KernelResult<Gap> {
215 Err(KernelError::Unsupported("gap".into()))
216 }
217
218 /// `brep` mirrored across the plane through `point` with `normal`, in
219 /// its own frame, as a snapshot of its own.
220 fn mirror(&self, _brep: &[u8], _point: [f64; 3], _normal: [f64; 3]) -> KernelResult<Vec<u8>> {
221 Err(KernelError::Unsupported("mirror".into()))
222 }
223
224 /// The volume, area and centre of mass of `brep`, in its own frame.
225 fn measure(&self, _brep: &[u8]) -> KernelResult<PhysicalProperties> {
226 Err(KernelError::Unsupported("measure".into()))
227 }
228
229 /// The edge of `brep` nearest `near`, projected orthogonally onto
230 /// `plane`. Both are in the shape's own frame.
231 fn project_edge(
232 &self,
233 brep: &[u8],
234 near: [f64; 3],
235 plane: &ProfilePlane,
236 ) -> KernelResult<ProjectedEdge>;
237
238 /// Points and tangents along the edge of `brep` nearest `near` (within
239 /// a pick's reach of it), from the start of its curve: one per entry of
240 /// `stations`, each a fraction of the edge's length (0 its start, 1 its
241 /// end) placed by arc length, not by the curve's parameter. Everything
242 /// is in the shape's own frame.
243 fn edge_frames(
244 &self,
245 _brep: &[u8],
246 _near: [f64; 3],
247 _stations: &[f64],
248 ) -> KernelResult<PathFrames> {
249 Err(KernelError::Unsupported("points along an edge".into()))
250 }
251
252 /// Points and tangents along `wire` on `plane`, walked from its first
253 /// segment's start: one per entry of `stations`, each a fraction of the
254 /// wire's whole length placed by arc length, as `edge_frames`.
255 fn wire_frames(
256 &self,
257 _plane: &ProfilePlane,
258 _wire: &ProfileWire,
259 _stations: &[f64],
260 ) -> KernelResult<PathFrames> {
261 Err(KernelError::Unsupported("points along a wire".into()))
262 }
263
264 /// Where every occurrence of a [`SolidOp::Pattern`] with `steps` stands,
265 /// as row-major transforms from the original's place, the original's
266 /// (the identity) first: what the chain works out, with `brep` (in the
267 /// pattern's frame) as the solid a step's edge is found on.
268 fn pattern_transforms(
269 &self,
270 _brep: Option<&[u8]>,
271 _steps: &[PatternStep],
272 ) -> KernelResult<Vec<[[f64; 4]; 4]>> {
273 Err(KernelError::Unsupported("pattern transforms".into()))
274 }
275
276 /// The face of `brep` nearest `near` (in the shape's own frame), as a
277 /// native-format snapshot of its own: what a face taken from a solid
278 /// keeps once the solid moves on.
279 fn face_of(&self, _brep: &[u8], _near: [f64; 3]) -> KernelResult<Vec<u8>> {
280 Err(KernelError::Unsupported(
281 "taking a face out of a solid".into(),
282 ))
283 }
284
285 /// The edge of `brep` nearest `near` (in the shape's own frame), as a
286 /// native-format snapshot of its own.
287 fn edge_of(&self, _brep: &[u8], _near: [f64; 3]) -> KernelResult<Vec<u8>> {
288 Err(KernelError::Unsupported(
289 "taking an edge out of a solid".into(),
290 ))
291 }
292
293 /// Where the face of `brep` nearest `near` crosses `plane`, as the
294 /// curves the plane cuts from it, in the plane's own 2D coordinates:
295 /// each the exact line, circle or ellipse it is, or points along any
296 /// other. Empty when the face does not reach the plane. Both are in the
297 /// shape's own frame.
298 fn section_face(
299 &self,
300 _brep: &[u8],
301 _near: [f64; 3],
302 _plane: &ProfilePlane,
303 ) -> KernelResult<Vec<ProjectedEdge>> {
304 Err(KernelError::Unsupported("face section".into()))
305 }
306
307 /// A point on each solid of `brep`, one per solid in the order the
308 /// shape holds them, in its own frame: where each piece of a shape of
309 /// several stands.
310 fn solid_pieces(&self, _brep: &[u8]) -> KernelResult<Vec<[f64; 3]>> {
311 Err(KernelError::Unsupported("solid pieces".into()))
312 }
313
314 /// Where `plane` crosses `brep`, chained end to end, each curve exact
315 /// in the plane's own 2D coordinates and drawn in the shape's own
316 /// frame: the whole shape's section, or with `near` only the face
317 /// nearest it. Empty when the plane misses.
318 fn section(
319 &self,
320 _brep: &[u8],
321 _plane: &ProfilePlane,
322 _near: Option<[f64; 3]>,
323 ) -> KernelResult<Vec<SectionRun>> {
324 Err(KernelError::Unsupported("section".into()))
325 }
326
327 /// The boundary loops of the face of `brep` nearest `near`, the outer
328 /// one first, each edge in loop order, in the shape's own frame.
329 fn face_loops(&self, _brep: &[u8], _near: [f64; 3]) -> KernelResult<Vec<Vec<LoopEdge>>> {
330 Err(KernelError::Unsupported("face loops".into()))
331 }
332
333 /// The curves of a DXF drawing, given as its text.
334 fn read_dxf(&self, _text: &str) -> KernelResult<Drawing2d> {
335 Err(KernelError::Unsupported("reading DXF".into()))
336 }
337
338 /// The regions `profile` encloses, meshed where they stand in its
339 /// plane: what a feature swept from it takes, holes left open.
340 fn profile_mesh(&self, _profile: &Profile) -> KernelResult<TriMesh> {
341 Err(KernelError::Unsupported("profile mesh".into()))
342 }
343
344 /// The medial axis of each region of `profile`, held to `tolerance`
345 /// (mm), in the profile plane's own 2D coordinates.
346 fn medial_axis(&self, _profile: &Profile, _tolerance: f64) -> KernelResult<Vec<MedialRegion>> {
347 Err(KernelError::Unsupported("medial axis".into()))
348 }
349
350 /// The centre line of the solid in `brep` from the face `from` names to
351 /// the face `to` names, held to `tolerance` (mm). Everything is in the
352 /// shape's own frame.
353 fn centre_line(
354 &self,
355 _brep: &[u8],
356 _from: &FaceProbe,
357 _to: &FaceProbe,
358 _tolerance: f64,
359 ) -> KernelResult<CentreLine> {
360 Err(KernelError::Unsupported("centre line".into()))
361 }
362
363 /// What the shape in `brep` answers to `probe`, in the shape's own
364 /// frame.
365 fn probe(&self, _brep: &[u8], _probe: &ShapeProbe) -> KernelResult<ProbeAnswer> {
366 Err(KernelError::Unsupported("probing a shape".into()))
367 }
368}