dymokomi/luce-cad
Source of release 0.9.2
0.9.2 / tests / contracts / surface_uv_contract.lucb
## A point's parameters on a B-spline surface (modeling surface_uv): found
## where the point is on it, an error where it is not. They used to come
## back NaN, and winding against NaN called points inside or outside at
## random.
from luce_geocore.geocore import Vector3, invalid
from geometry import Surface
from modeling import surface_uv
pub func surface_uv_contracts() -> !:
# A bilinear patch over the unit square in z = 0, bulged at no point.
let points: Vector3[4] = [Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), Vector3(1.0, 0.0, 0.0), Vector3(1.0, 1.0, 0.0)]
let weights: f64[4] = [1.0, 1.0, 1.0, 1.0]
let knots: f64[4] = [0.0, 0.0, 1.0, 1.0]
var s = try Surface(3, Vector3(), Vector3(1.0, 0.0, 0.0), Vector3(0.0, 0.0, 1.0), 0.0, 0.0, points[..<4], weights[..<4], knots[..<4], knots[..<4], 2, 2, 1, 1)
defer s.close()
let (u, v) = try surface_uv(&s, Vector3(0.25, 0.75, 0.0), 1e-7)
if u < 0.2499 or u > 0.2501 or v < 0.7499 or v > 0.7501: error(invalid, "a point on a B-spline surface has the wrong parameters")
_ = surface_uv(&s, Vector3(0.25, 0.75, 3.0), 1e-7) catch failure:
if failure.code != invalid: error(failure.code, failure.message)
return
error(invalid, "a point off a B-spline surface was given parameters")