dymokomi/luce-cad
Source of release 0.9.3
0.9.3 / tests / regressions / y_blend_tests.luc
## Y corners: an inside and an outside fillet meeting where the corner's
## third edge stays sharp (y_blend.lucb), against closed forms and Fusion
## 2705 (probes 14 and 15 of 2026-10-13; Fusion's own solids exported as
## STEP and measured here, as its reported volumes are its default accuracy's):
## - a 20 x 4 x 20 plate with a 6 cube boss, its upright and one foot edge
## filleted 1: the foot runs on to the boss's front face, the upright's
## section rolls round its end, a torus (axis the foot's ball line, ring 2,
## tube 1: Fusion's exactly), cut by the plate. 14 faces, as Fusion's. Its
## volume in closed form (the foot's and the upright's strips, less the
## torus's spandrel turned while it stays above the plate: the integral
## of rho asin(1 / rho) over the spandrel) is 1815.952928; Fusion's solid
## 1815.952915 (it reports 1815.9313 at its default accuracy, 1815.9492 at
## its highest);
## - the same with radii 1 and 2 either way (closed forms 1819.741298 and
## 1812.001117; Fusion's solids 1819.741710, 1812.001098);
## - an L's inside upright and one top edge filleted 2 (the top edge runs
## on, the upright's section rolls round it): 11 faces, closed form
## 6008.960652 (Fusion's solid 6008.960639);
## - G2 and G3: the section swept round the rim, every smooth edge at the
## fillet's continuity but the cut on the plate (a crease, as Fusion's).
## Fusion's G2 corners are the same sweep: the boss's solid 1815.966512,
## its cut meeting the plate's edge at the same point (2.219250); the L's
## 6006.980384 (its strip there meshed coarser here; its faces' areas are
## ours within 0.003).
from luce_cad.modeling import CadModeling
from luce_cad.model import CadModel
from luce_cad.measure import CadMeasure
from luce_cad.solids import CadSolids
from luce_geocore.geocore import Vector3
from checks import closed, volume
from luce_std import math
pub func y_blend_tests() -> unit!:
let body = boss()
let upright = edges_in(body, Vector3(3.0, 2.0, 3.0), Vector3(3.0, 8.0, 3.0))
let foot = edges_in(body, Vector3(3.0, 2.0, -3.0), Vector3(3.0, 2.0, 3.0))
assert(upright.length == 1 and foot.length == 1)
let both = [upright[0], foot[0]]
y_corner(CadModeling.filleted(body, CadModeling.edge_references(body, both), 1.0, "f", 1, false), 14, 1, 1815.952928, 1815.9529148, 1e-4, "boss G1")
y_corner(CadModeling.filleted(body, CadModeling.edge_references(body, both), 1.0, "f", 2, false), 14, 2, -1.0, 1815.9665116, 1e-3, "boss G2")
y_corner(CadModeling.filleted(body, CadModeling.edge_references(body, both), 1.0, "f", 3, false), 14, 3, -1.0, -1.0, 0.0, "boss G3")
let sets = CadModeling.edge_references(body, upright) + "|" + CadModeling.edge_references(body, foot)
y_corner(CadModeling.filleted_sets(body, sets, [1.0, 2.0], "f", 1, false), 14, 1, 1819.741298, 1819.7417096, 1e-3, "boss upright 1, foot 2")
y_corner(CadModeling.filleted_sets(body, sets, [2.0, 1.0], "f", 1, false), 14, 1, 1812.001117, 1812.0010982, 1e-4, "boss upright 2, foot 1")
let l = ell()
let inside = edges_in(l, Vector3(0.0, -10.0, 0.0), Vector3(0.0, 10.0, 0.0))
let top = edges_in(l, Vector3(0.0, 10.0, 0.0), Vector3(10.0, 10.0, 0.0))
assert(inside.length == 1 and top.length == 1)
let pair = [inside[0], top[0]]
y_corner(CadModeling.filleted(l, CadModeling.edge_references(l, pair), 2.0, "f", 1, false), 11, 1, 6008.960652, 6008.9606393, 1e-3, "L G1")
y_corner(CadModeling.filleted(l, CadModeling.edge_references(l, pair), 2.0, "f", 2, false), 11, 2, -1.0, 6006.9803837, 0.015, "L G2")
print("PASS Y corners: a boss's upright and one foot edge filleted 1 (the upright's section rolled round the foot's end, Fusion's torus; 14 faces, the closed form 1815.952928) at G1, G2 and G3, radii 1 and 2 either way (closed forms); an L's inside upright and one top edge (11 faces, 6008.960652) at G1 and G2; every smooth edge at its continuity but the cut on the plate")
## The 20 x 4 x 20 plate with a 6 cube boss on it (probe 13's).
func boss() -> CadModel!:
let plate = CadModeling.tagged(CadSolids.box(20.0, 4.0, 20.0), "p")
let b = CadModeling.moved_body(CadModeling.tagged(CadSolids.box(6.0, 6.0, 6.0), "b"), Vector3(0.0, 5.0, 0.0))
return CadModeling.combined(plate, b, 0)
## A 20 cube with a 10 x 10 quarter taken out along y: an L prism.
func ell() -> CadModel!:
let cube = CadModeling.tagged(CadSolids.box(20.0, 20.0, 20.0), "c")
let notch = CadModeling.moved_body(CadModeling.tagged(CadSolids.box(10.0, 22.0, 10.0), "n"), Vector3(5.0, 0.0, 5.0))
return CadModeling.combined(cube, notch, 1)
## The edges of `body` lying wholly in the box from `lo` to `hi`.
func edges_in(body: CadModel, lo: Vector3, hi: Vector3) -> list[int]!:
let found: list[int] = []
for face in 0..<body.face_count():
for use in 0..<body.face_edge_count(face):
let id = body.face_edge_id(face, use)
var inside = true
for p in [body.face_edge_point(face, use, 0.0), body.face_edge_point(face, use, 1.0)]:
if p.x < lo.x - 1e-6 or p.y < lo.y - 1e-6 or p.z < lo.z - 1e-6 or p.x > hi.x + 1e-6 or p.y > hi.y + 1e-6 or p.z > hi.z + 1e-6: inside = false
if inside and not (id in found): found.append(id)
return found
## A Y corner's result: `faces` faces, one corner face (a torus at G1),
## its volume the closed form `exact` (when given) and near Fusion's
## (`within`, when given), every smooth edge at `level` but one (the cut).
func y_corner(made: CadModel, faces: int, level: int, exact: float, fusion: float, within: float, label: str) -> unit!:
assert(made.face_count() == faces, f"{label}: {made.face_count()} faces")
var corners = 0
for f in 0..<made.face_count():
if CadModeling.face_name_of(made, f).contains("corner"):
corners += 1
if level == 1: assert(made.face_surface_kind(f) == 5, f"{label}: the corner is no torus")
assert(corners == 1, f"{label}: {corners} corner faces")
let coarse = volume(made.tessellate(32))
let mesh = made.tessellate(64)
closed(mesh)
let fine = volume(mesh)
let v = fine + (fine - coarse) / 3.0
if exact > 0.0: assert(math.abs(v - exact) < 2e-3, f"{label}: {v} against {exact}")
if fusion > 0.0: assert(math.abs(v - fusion) < within, f"{label}: {v} against Fusion's {fusion}")
let check = CadMeasure.check(made, "", level, 24, 0.001, 0.1, 0.5, 1.0, false, 48, false, 1.0, false)
var below = 0
for k in 0..<check.edge_count():
if check.edge(k).level < level: below += 1
assert(below == 1, f"{label}: {below} smooth edges below G{level}: {check.summary()}")