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
//! Does a field meet the bound it declares?
//!
//! Ticket: F-002. The other half of F-001, and the half that makes the
//! declaration mean something.
//!
//! # Why a declaration needs a checker
//!
//! F-001 replaced `is_exact_distance() -> bool` because `csg_difference` had
//! declared `true` with `// away from the seam` beside it for months and nothing
//! looked. Replacing the *type* does not fix that: a `FieldBound` nobody checks
//! is the same defect with more cases. It is not a hypothetical either — the
//! first draft of F-001 declared `noise_cavity` at `l = 2.598` when its gradient
//! reaches **7.73**, and only a checker caught it (M-244).
//!
//! # What is measured, and what the numbers mean
//!
//! `‖∇f‖`, sampled over the field's own domain.
//!
//! - **`sup`** is the largest gradient seen. Against
//! [`Lipschitz`](crate::fields::FieldBound::Lipschitz) this is the number that
//! must not exceed `l`.
//! - **`eikonal_fraction`** is the share of samples with `‖∇f‖ ≈ 1`, which is the
//! differential form of *"the value is the distance"*. An
//! [`Exact`](crate::fields::FieldBound::Exact) field should be near 1.0 and a
//! gyroid nowhere near it.
//!
//! # The direction of the error is the whole point
//!
//! **A sampled maximum is a lower bound on a supremum.** So this can prove a
//! declaration *wrong* and can never prove one right: finding `‖∇f‖ = 7.73`
//! against a declared `2.598` is conclusive, while finding nothing above `1.7`
//! against a declared `3.46` says only that the sampling missed. That asymmetry
//! is why [`FieldBoundReport::violates`] answers a one-sided question, and why
//! `noise_cavity` is declared [`Unbounded`](crate::fields::FieldBound::Unbounded)
//! rather than given the measured figure — declaring a sampled maximum as a
//! Lipschitz constant is unsound in exactly the direction that lets a sphere
//! tracer step through a surface.
use crate;
use crateReal;
/// How close to `1` a gradient must be to count as eikonal.
///
/// Loose on purpose. An exact field's gradient is one everywhere it is defined,
/// but a finite sample lands near creases — a box's edges, a CSG seam — where it
/// is not defined at all and a central difference reads short. The fraction is a
/// description of the field, not a gate, so the band only has to be wide enough
/// that a crease does not dominate it.
pub const EIKONAL_TOLERANCE: f64 = 0.05;
/// What sampling `‖∇f‖` over a field's domain found.
/// Sample `‖∇f‖` over `field`'s domain and report what was found.
///
/// `n` is samples per axis, so cost is `n³` gradient evaluations.
///
/// # The grid is offset, deliberately
///
/// Samples land at cell *centres* plus an irrational-ish nudge. A grid aligned
/// to the domain lands exactly on a box's faces and on the noise lattice, which
/// are precisely the points where the gradient is undefined or degenerate — so
/// an aligned sweep measures the discontinuities instead of the field, and its
/// `inf` is an artefact.