dymokomi/luce-cad
Source of release 0.9.1
0.9.1 / tests / nurbs_tests.luc
## Rational surface evaluation, uniform patch tessellation and rectangular CAD trims.
from luce_cad.tessellation.surface import NurbsSurface
from luce_cad.model import CadModel
from luce_geocore.geocore import Vector3
from checks import near
pub func nurbs_tests() -> unit!:
let patch = NurbsSurface.tessellate([Vector3(), Vector3(0.0, 0.0, 2.0), Vector3(2.0, 0.0, 0.0), Vector3(2.0, 0.0, 2.0)], [1.0, 1.0, 1.0, 1.0], 2, 2, 1, 1, [0.0, 0.0, 1.0, 1.0], [0.0, 0.0, 1.0, 1.0], 2)
assert(patch.point_count() == 9 and patch.face_count() == 4)
near(patch.point(4).x, 1.0)
near(patch.point(4).z, 1.0)
let cad = CadModel()
cad.add_nurbs([Vector3(), Vector3(0.0, 0.0, 2.0), Vector3(2.0, 0.0, 0.0), Vector3(2.0, 0.0, 2.0)], [1.0, 1.0, 1.0, 1.0], 2, 2, 1, 1, [0.0, 0.0, 1.0, 1.0], [0.0, 0.0, 1.0, 1.0])
cad.trim_rectangle(0, 0.25, 0.75, 0.0, 0.5)
let trimmed = cad.tessellate(2)
assert(cad.face_count() == 1 and trimmed.face_count() == 4)
near(trimmed.bounds().minimum.x, 0.5)
near(trimmed.bounds().maximum.x, 1.5)
near(trimmed.bounds().maximum.z, 1.0)
assert(cad.tessellate(4).face_count() == 16 and cad.face_count() == 1)
var bad_trim = false
cad.trim_rectangle(0, -0.1, 0.75, 0.0, 0.5) catch failure:
bad_trim = true
assert(bad_trim)
near(cad.tessellate(2).bounds().minimum.x, 0.5)
var nonplanar = false
cad.add_planar([Vector3(), Vector3(1.0, 0.0, 0.0), Vector3(1.0, 1.0, 1.0), Vector3(0.0, 1.0, 0.0)]) catch failure:
nonplanar = true
assert(nonplanar and cad.face_count() == 1)
let curved = NurbsSurface.tessellate([Vector3(1.0, 0.0, 0.0), Vector3(1.0, 1.0, 0.0), Vector3(1.0, 0.0, 1.0), Vector3(1.0, 1.0, 1.0), Vector3(0.0, 0.0, 1.0), Vector3(0.0, 1.0, 1.0)], [1.0, 1.0, 0.7071067811865476, 0.7071067811865476, 1.0, 1.0], 3, 2, 2, 1, [0.0, 0.0, 0.0, 1.0, 1.0, 1.0], [0.0, 0.0, 1.0, 1.0], 2)
near(curved.point(4).x, 0.7071067811865476)
near(curved.point(4).z, 0.7071067811865476)
# Local-support evaluation spans large nets and handles both knot endpoints.
let net: list[Vector3] = []
let weights: list[float] = []
let knots: list[float] = [0.0]
for u in 0..<65:
knots.append(float(u))
for v in 0..<2:
net.append(Vector3(float(u), float(v), 0.0))
weights.append(1.0)
knots.append(64.0)
for u in [0.0, 12.25, 64.0]:
let point = NurbsSurface.at(net, weights, 65, 2, 1, 1, knots, [0.0, 0.0, 1.0, 1.0], u, 0.75)
near(point.x, u)
near(point.y, 0.75)
print("PASS rational tessellation, rectangular trims, planar rejection and local-support evaluation")