dymokomi/luce-cad
Source of release 0.9.3
0.9.3 / tests / regressions / grooved_grid_tests.luc
## Numerous authored grooves do not make a simple conical support an arbitrary
## triangle mesh. Clip one regular chart and keep its repeated seam stitched.
from luce_cad.model import BrepModel
from luce_geocore.geocore import Vector3
from checks import near
from luce_std import math
pub func grooved_grid_tests() -> unit!:
for reverse in [false,true]: grooved_cone(reverse)
print("PASS many-coedge grooved cone, hard trim termination, canonical vertices and repeated seam")
func grooved_cone(reverse: bool) -> unit!:
let model = BrepModel()
let x = Vector3(1.0,0.0,0.0)
let z = Vector3(0.0,0.0,1.0)
let teeth = 36
let positions: list[Vector3] = []
for tooth in 0..<teeth:
for corner in 0..<4:
let angle = 2.0*math.pi*(float(tooth)+(0.0 if corner == 0 else (1.0 if corner == 3 else 0.5)))/float(teeth)
let height = 0.5 if corner < 2 else 0.75
let p = Vector3((2.0+height)*math.cos(angle),(2.0+height)*math.sin(angle),height)
positions.append(p)
_ = model.add_vertex(p)
let n = positions.length
let bottom = model.add_vertex(x.multiply_scalar(2.0))
for at in 0..<n:
if at%2 == 0:
let height = positions[at].z
_ = model.add_circle(at,(at+1)%n,z.multiply_scalar(height),z,x,2.0+height)
else:
_ = model.add_line(at,(at+1)%n)
let seam = model.add_line(bottom,0)+1
let circle = model.add_circle(bottom,bottom,Vector3(),z,x,2.0)+1
_ = model.add_surface(2,Vector3(),z,x,2.0,math.pi/4.0)
let uses: list[int] = [circle,seam]
for at in 0..<n: uses.append(-(n-at))
uses.append(-seam)
let oriented: list[int] = []
for at in 0..<uses.length: oriented.append(-uses[uses.length-1-at] if reverse else uses[at])
_ = model.add_face(0,oriented,[oriented.length],not reverse)
assert(model.face_edge_count(0) > 128)
let mesh = model.mesh(8,0.2)
let method = mesh.find_attribute("cad_mesher",2)
let counts: list[int] = []
for edge in 0..<mesh.edge_count(): counts.append(0)
var quads = 0
for face in 0..<mesh.face_count():
assert(mesh.attribute_value(method,face,0) == 2.0)
if mesh.face_size(face) == 4: quads += 1
for corner in 0..<mesh.face_size(face): counts[mesh.face_edge(face,corner)] += 1
assert(quads > 128 and mesh.face_count() < 4000)
for at in 0..<positions.length:
# The input IDs are kept and used, never merged with nearby stations.
near(mesh.point(at).subtract(positions[at]).length(),0.0)
var found = false
for edge in 0..<mesh.edge_count():
if mesh.edge_point(edge,0) == at or mesh.edge_point(edge,1) == at: found = true
assert(found)
var stitched = 0
var boundary = 0
for edge in 0..<mesh.edge_count():
let a = mesh.point(mesh.edge_point(edge,0))
let b = mesh.point(mesh.edge_point(edge,1))
assert(counts[edge] == 1 or counts[edge] == 2)
if counts[edge] == 1: boundary += 1
if math.abs(a.y)+math.abs(b.y) < 0.000001 and a.x > 0.0 and b.x > 0.0 and a.z < 0.5 and b.z <= 0.5:
assert(counts[edge] == 2)
stitched += 1
assert(stitched > 0 and boundary > n)
for at in 0..<mesh.point_count():
let p = mesh.point(at)
near(math.sqrt(p.x*p.x+p.y*p.y),2.0+p.z)
# A ray through a removed tooth interval must miss both sides; the adjacent
# tall interval must hit the exact support within the sampled mesh budget.
for fraction in [0.25,0.75]:
let angle = 2.0*math.pi*fraction/float(teeth)
let radial = Vector3(math.cos(angle),math.sin(angle),0.0)
let distance = mesh.ray_distance(radial.multiply_scalar(4.0).add(z.multiply_scalar(0.65)),radial.multiply_scalar(-1.0))
if fraction == 0.25: assert(distance < 0.0)
else: assert(distance > 1.34 and distance < 1.36)
for triangle in 0..<mesh.index_count()//3:
let a = mesh.vertex(mesh.index(triangle*3))
let b = mesh.vertex(mesh.index(triangle*3+1))
let c = mesh.vertex(mesh.index(triangle*3+2))
let normal = b.position.subtract(a.position).cross(c.position.subtract(a.position))
for corner_normal in [a.normal,b.normal,c.normal]: assert(normal.dot(corner_normal) > 0.0)