mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 21:12:57 -05:00
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.
This commit is contained in:
1 parent
79a68f6469
commit
6bb499f189
1 file changed
+51
@@ -255,6 +255,56 @@ fn star_ring(n: usize, x: f64, y: f64, r: f64, inner: f64, back: bool) -> Vec<Co
|
||||
ring_of(&points)
|
||||
}
|
||||
|
||||
/// `count` rings drawn from a fixed seed, each counterclockwise about its center: corners at random
|
||||
/// angles and distances, with every other corner pulled in close to the center in some (spikes),
|
||||
/// corners rounded to whole numbers and slanted in some (so that corners on other parts of the ring
|
||||
/// lie exactly on the line between two corners), corners midway along every edge in some, some
|
||||
/// stretched along one axis, some so small that a corner within the tolerance of an ear's new edge
|
||||
/// lies in another cell, and some far from the origin.
|
||||
fn random_rings(count: usize) -> Vec<Vec<Corner>> {
|
||||
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<f64> = (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::<Vec<_>>())
|
||||
})
|
||||
.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);
|
||||
|
||||
Reference in new issue
Block a user