From 6bb499f189a7fdaa86e4d0714736a68e1c3dc9b9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 3 Dec 2026 06:50:05 -0800 Subject: [PATCH] 3D: the cap grid's test also cuts 1,200 seeded random rings both ways rings_cut_with_a_grid_give_the_triangles_cut_without_one now adds 1,200 rings drawn from a fixed seed: spiky rings, rings with whole-number corners on slanted lines, rings with a corner midway along every edge, stretched rings, rings scaled down by 1e-7 and rings far from the origin. The test now fails when the grid's margin is 0, when the row band is narrowed by the margin instead of widened, or when removed corners are not skipped. --- crates/three-d/src/mesh/tests.rs | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/crates/three-d/src/mesh/tests.rs b/crates/three-d/src/mesh/tests.rs index a4048f82ca..960f85dbf0 100644 --- a/crates/three-d/src/mesh/tests.rs +++ b/crates/three-d/src/mesh/tests.rs @@ -255,6 +255,56 @@ fn star_ring(n: usize, x: f64, y: f64, r: f64, inner: f64, back: bool) -> Vec Vec> { + let mut seed = 0x9e37_79b9_7f4a_7c15_u64; + let mut unit = move || { + seed ^= seed << 13; + seed ^= seed >> 7; + seed ^= seed << 17; + (seed >> 11) as f64 / (1u64 << 53) as f64 + }; + (0..count) + .map(|k| { + let n = 70 + (unit() * 200.0) as usize; + let mut angles: Vec = (0..n).map(|_| unit() * std::f64::consts::TAU).collect(); + angles.sort_by(f64::total_cmp); + angles.dedup(); + let spiky = k % 3 == 1; + let whole = k % 3 != 0; + let mut points: Vec<(f64, f64)> = angles + .iter() + .enumerate() + .map(|(i, a)| { + let r = if spiky && i % 2 == 1 { 0.05 + 0.1 * unit() } else { 0.5 + 0.5 * unit() }; + let (x, y) = (r * a.cos(), r * a.sin()); + if whole { + let (x, y) = ((40.0 * x).round(), (40.0 * y).round()); + (x + y, y) + } else { + (x, y) + } + }) + .collect(); + points.dedup(); + if points.first() == points.last() { + points.pop(); + } + if k % 2 == 0 { + points = points.iter().zip(points.iter().cycle().skip(1)).flat_map(|(&p, &q)| [p, ((p.0 + q.0) / 2.0, (p.1 + q.1) / 2.0)]).collect(); + } + let (sx, sy) = [(1.0, 1.0), (1024.0, 1.0), (1.0, 1.0 / 1024.0), (32.0, 64.0), (1e-7, 1e-7)][k % 5]; + let (ox, oy) = if k % 7 == 0 { ((1e6 * (unit() - 0.5)).round(), (1e6 * (unit() - 0.5)).round()) } else { (0.0, 0.0) }; + ring_of(&points.iter().map(|&(x, y)| (ox + sx * x, oy + sy * y)).collect::>()) + }) + .collect() +} + /// The triangles `ring` is cut into, with the ring's corners sorted into a grid as [`clip`] sorts /// them, or without one, and the number of corners tested against ears. fn cut_ring(ring: &[Corner], keep_straight: bool, grid: bool) -> (Vec<[[u64; 3]; 3]>, usize) { @@ -305,6 +355,7 @@ fn rings_cut_with_a_grid_give_the_triangles_cut_without_one() { let dent = ring_of(&[(4.0, 4.0), (4.0, 6.0), (6.0, 6.0), (6.0, 5.0), (6.0, 4.0), (5.0, 4.0)]); rings.push(bridge(square.clone(), &dent, &[], &mut work).unwrap()); rings.push(square); + rings.extend(random_rings(1200)); for (k, ring) in rings.iter().enumerate() { for keep_straight in [false, true] { let (with, _) = cut_ring(ring, keep_straight, true);