dymokomi/luce-cad
Source of release 0.9.1
0.9.1 / tests / cad_edits_tests.luc
## CadEdits: the pick mesh tags polygons with their model and B-rep face
## and edges with their B-rep edge; whole models move about their centroid
## and part of a model does not; faces delete, and a model losing every
## face goes; a model is added.
from luce_cad.solids import CadSolids
from luce_cad.cad_edits import CadEdits
from luce_cad.cad_geometry import CadGeometry
from checks import near
pub func cad_edits_tests() -> unit!:
let box = CadGeometry.of_model(CadSolids.box(2.0, 2.0, 2.0))
let pick = CadEdits.pick_mesh(box)
assert(pick.face_count() == 6 and pick.find_attribute("cad_model", 2) >= 0)
let edge = pick.find_attribute("cad_edge", 4)
var tagged = 0
for at in 0..<pick.edge_count():
if pick.attribute_value(edge, at) >= 0.0: tagged += 1
assert(tagged == 12)
# Moved and turned about its centroid.
let moved = CadEdits.transformed_parts(box, pick, "*", [3.0, 0.0, 0.0, 0.0, 90.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])
let placed = CadGeometry.model(moved, 0).tessellate(8)
near(placed.bounds().minimum.x, 2.0)
near(placed.bounds().maximum.x, 4.0)
var refused = false
_ = CadEdits.transformed_parts(box, pick, "0", [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]) catch failure:
refused = true
assert(refused)
# Faces go; the last face takes the model with it.
let open_box = CadEdits.without_parts(box, pick, "0 1")
assert(CadGeometry.model_count(open_box) == 1 and CadGeometry.model(open_box, 0).face_count() == 4)
assert(CadGeometry.model_count(CadEdits.without_parts(box, pick, "*")) == 0)
# Another model after it.
let two = CadEdits.with_model(box, CadSolids.sphere(1.0))
assert(CadGeometry.model_count(two) == 2 and CadEdits.pick_mesh(two).face_count() > 6)
print("PASS CAD edits: tagged pick mesh, whole-model moves (parts refused), face and model deletes, added models")