dymokomi/luce-cad
Source of release 0.9.3
0.9.3 / tests / contracts / boolean_contract.lucb
## Booleans (modeling/boolean.lucb). A curved face is met where it bulges
## past its boundary: a cylinder turned so no boundary sample lands on its
## widest point, cut by a box reaching only that bulge, gains the box's
## flat face (a box of the face's boundary alone missed it, and the cut was
## silently dropped). A pointed cone's face is split through its apex.
import interop
from luce_std import math
from luce_geocore.geocore import Vector3, invalid
from model import CadModel
from solids import CadSolids
from modeling import CadModeling
pub func boolean_contracts() -> !:
try bulge()
try apex()
func bulge() -> !:
# The circles' samples fall every 22.5 degrees from 11.25: none at +x,
# where the side reaches 1 (the nearest reach cos 11.25 = 0.981).
let cylinder = try (try CadSolids.cylinder(1.0, 1.0)).value().transformed(Vector3(), Vector3(0.0, math.pi / 16.0, 0.0), Vector3(1.0, 1.0, 1.0))
defer cylinder.release()
let box = try (try CadSolids.box(2.0, 2.0, 2.0)).value().transformed(Vector3(1.99, 0.0, 0.0), Vector3(), Vector3(1.0, 1.0, 1.0))
defer box.release()
let cut = try CadModeling.combined(cylinder, box, 1)
defer cut.release()
# Its side, top and bottom, and the box's face at x = 0.99.
if cut.value().face_count() != 4: error(invalid, "a box cutting a cylinder's bulge was missed")
## A pointed cone tilted through a post, joined: splitting the cone's face
## passes its apex, where the seam turns back on itself and the surface has
## no normal (none is needed: there is one way on).
func apex() -> !:
let post = try CadSolids.cylinder(0.5, 3.0)
defer post.release()
let cone = try (try CadSolids.cone(0.6, 3.0)).value().transformed(Vector3(), Vector3(math.pi / 3.0, 0.0, 0.0), Vector3(1.0, 1.0, 1.0))
defer cone.release()
let joined = try CadModeling.combined(post, cone, 0)
defer joined.release()
if joined.value().face_count() < 4: error(invalid, "a post and a tilted cone joined lost faces")