dymokomi/luce-cad
Source of release 0.9.2
0.9.2 / tests / regressions / 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. On a set of two tagged models (and one
## untagged), picked edges give each model its own references, a feature
## made from them replaces its model, and an untagged model has none.
from luce_cad.solids import CadSolids
from luce_cad.modeling import CadModeling
from luce_geocore.geocore import Vector3
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)
edge_references()
print("PASS CAD edits: tagged pick mesh, whole-model moves (parts refused), face and model deletes, added models, per-model edge references, replaced models")
func edge_references() -> unit!:
let first = CadModeling.tagged(CadSolids.box(2.0, 2.0, 2.0), "#a")
let second = CadModeling.tagged(CadSolids.box(1.0, 1.0, 1.0), "#b").transformed(Vector3(4.0, 0.0, 0.0), Vector3(), Vector3(1.0, 1.0, 1.0))
let models = CadEdits.with_model(CadEdits.with_model(CadGeometry.of_model(first), second), CadSolids.sphere(0.5))
let pick = CadEdits.pick_mesh(models)
let a = CadEdits.model_edges(pick, "*", 0)
let b = CadEdits.model_edges(pick, "*", 1)
assert(a.split(";").length == 12 and b.split(";").length == 12)
assert(a.contains("#a") and not a.contains("#b") and b.contains("#b") and not b.contains("#a"))
# The untagged sphere's edges have no names; no model 3.
assert(CadEdits.model_edges(pick, "*", 2) == "" and CadEdits.model_edges(pick, "*", 3) == "")
# The second box's edges all filleted, in its place.
let rounded = CadEdits.replaced(models, 1, CadModeling.filleted(CadGeometry.model(models, 1), b, 0.1, "#f"))
assert(CadGeometry.model_count(rounded) == 3)
assert(CadGeometry.model(rounded, 1).face_count() == 26 and CadGeometry.model(rounded, 0).face_count() == 6)
var refused = false
_ = CadEdits.replaced(models, 3, first) catch failure:
refused = true
assert(refused)