dymokomi/luce-step
Source of release 0.11.0
## Shared assertions for the STEP regressions.
from luce_geocore.geocore import Mesh
from luce_std import math
pub func near(a: float, b: float):
if math.abs(a - b) >= 0.000001: print(f"near failed: actual={a}, expected={b}")
assert(math.abs(a - b) < 0.000001)
## Every edge is used by exactly two faces in opposite directions, and every
## display triangle faces the same way as its corner normals.
pub func manifold(mesh: Mesh) -> unit!:
let counts: list[int] = []
let directions: list[int] = []
for edge in 0..<mesh.edge_count():
counts.append(0)
directions.append(0)
for face in 0..<mesh.face_count():
for at in 0..<mesh.face_size(face):
let edge = mesh.face_edge(face,at)
let a = mesh.edge_point(edge,0)
let b = mesh.edge_point(edge,1)
let p = mesh.face_point(face,at)
let q = mesh.face_point(face,(at+1)%mesh.face_size(face))
assert((p == a and q == b) or (p == b and q == a))
counts[edge] += 1
directions[edge] += 1 if p == a else -1
for edge in 0..<mesh.edge_count(): assert(counts[edge] == 2 and directions[edge] == 0)
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))
if b.position.subtract(a.position).cross(c.position.subtract(a.position)).dot(a.normal) <= 0.0:
print(f"invalid display triangle {triangle}: {a.position.x},{a.position.y},{a.position.z}; {b.position.x},{b.position.y},{b.position.z}; {c.position.x},{c.position.y},{c.position.z}; normal {a.normal.x},{a.normal.y},{a.normal.z}")
assert(false)