3D: Revolve's drawn faces and exported mesh share one side-corner helper

The canvas faces and the exported side mesh each worked out where a
side quad's four corners lie on the unrolled surface. Both now call
surface_corners, so the two keep the same corner order and formula.
This commit is contained in:
dotCooCoo
2026-11-18 16:04:41 -08:00
parent f80f6aa220
commit 877befe5a6
2 changed files with 22 additions and 11 deletions
+12 -11
View File
@@ -478,6 +478,15 @@ fn surface_span(sweep: f64, edge: Edge) -> f64 {
}
}
/// Where the four corners of the quad that the profile's edge from `a` to `b` sweeps in one step
/// about `axis` lie on the side surface ([`SurfaceCell`]), in the quad's order (`a`, `b`, then `b`
/// and `a` one step on): y is `along`, the surface y of each end of the edge, and x is the step's
/// surface angle at each end, `angle`, times the corner's own distance from the axis.
fn surface_corners(a: Point, b: Point, axis: f64, [va, vb]: [f64; 2], [t0, t1]: [f64; 2]) -> [Point; 4] {
let (ra, rb) = ((a.x - axis).abs(), (b.x - axis).abs());
[Point::new(t0 * ra, va), Point::new(t0 * rb, vb), Point::new(t1 * rb, vb), Point::new(t1 * ra, va)]
}
/// The surface y ([`SurfaceCell`]) of each end of each piece of a contour's profile `profile`
/// about `axis`: the length along the profile from its middle, counted from just after the
/// pieces that lie on the axis (which sweep no surface and add no length) on a closed contour.
@@ -1077,12 +1086,7 @@ fn keep_profile(
let (dr, dy) = ((b.x - a.x) * turn, (b.y - a.y) * turn);
let (sin, cos) = (at.sweep * (j as f64 + 0.5) / steps as f64).sin_cos();
// The corners on the side surface, as the drawn faces place them.
let uv = surface.map(|(along, angle)| {
let [va, vb] = along.get(i).copied().unwrap_or_default();
let [t0, t1] = angle(j);
let (ra, rb) = ((a.x - at.axis).abs(), (b.x - at.axis).abs());
[Point::new(t0 * ra, va), Point::new(t0 * rb, vb), Point::new(t1 * rb, vb), Point::new(t1 * ra, va)]
});
let uv = surface.map(|(along, angle)| surface_corners(*a, *b, at.axis, along.get(i).copied().unwrap_or_default(), angle(j)));
keep(vec![v0, v1, v2, v3], o.rotate(V3(dy * cos, -dr, dy * sin)), uv)?;
}
}
@@ -1600,7 +1604,7 @@ fn revolve_sweep(
for (i, ((pair, [ta, tb]), hole)) in profile.windows(2).zip(drawn.tangents.iter().copied()).zip(drawn.holes.iter().copied()).enumerate() {
let [a, b] = pair else { continue };
let turn = if hole { -turn } else { turn };
let [va, vb] = along.get(i).copied().unwrap_or_default();
let ends = along.get(i).copied().unwrap_or_default();
if ![a.x, a.y, b.x, b.y].iter().all(|v| v.is_finite() && v.abs() <= 1e8) {
return Err("Revolve profile contains invalid coordinates".into());
}
@@ -1610,10 +1614,7 @@ fn revolve_sweep(
let last = (i + 2 == profile.len()).then(|| rings.last().and_then(Option::as_ref).and_then(|r| r.arcs.get(j))).flatten();
// Where the corners lie on the unrolled side surface, and whether the face shows
// its outside: the edge's outward normal swept to the middle of the step.
// x is the angle times the corner's own distance from the axis.
let [t0, t1] = surface_angle(j);
let (ra, rb) = ((a.x - axis).abs(), (b.x - axis).abs());
let corners = [Point::new(t0 * ra, va), Point::new(t0 * rb, vb), Point::new(t1 * rb, vb), Point::new(t1 * ra, va)];
let corners = surface_corners(*a, *b, axis, ends, surface_angle(j));
let on_surface = surface_contour == Some(contour);
let outward = {
let (dr, dy) = ((b.x - a.x) * turn, (b.y - a.y) * turn);
+10
View File
@@ -327,6 +327,16 @@ fn only_the_longest_contour_of_a_compound_profile_carries_the_side_surface() {
let (w, h) = revolve_surface_size(&PathData::from_bezpath(&bp), b, Revolve::default()).unwrap();
assert!((w - 10.0 * std::f64::consts::PI).abs() < 1e-9 && (h - 80.0).abs() < 1e-3, "{w} {h}");
}
#[test]
fn a_side_quad_lies_on_the_surface_at_its_corners_distances_from_the_axis() {
// An edge from 30 to 50 pt right of an axis at 10, at surface y -5 and 15, over a step from
// 0.25 to 0.5 radians: x is each angle times each corner's own distance from the axis.
let corners = surface_corners(Point::new(30.0, 0.0), Point::new(50.0, 20.0), 10.0, [-5.0, 15.0], [0.25, 0.5]);
assert_eq!(corners, [Point::new(5.0, -5.0), Point::new(10.0, 15.0), Point::new(20.0, 15.0), Point::new(10.0, -5.0)]);
// Left of the axis the distances are the same.
let left = surface_corners(Point::new(-10.0, 0.0), Point::new(-30.0, 20.0), 10.0, [-5.0, 15.0], [0.25, 0.5]);
assert_eq!(left, corners);
}
/// The square ring of [`a_ring_profile_is_measured_from_its_outer_side_at_mid_height`] with an
/// anchor in the middle of its inner side.
fn split_square() -> [Point; 6] {