dymokomi/luce-cad
Source of release 0.9.5
0.9.5 / src / layout / bounds.lucb
## The trim's sampled polygon is not its curve envelope. In particular, an
## odd-numbered arc sampling can miss the extremum of a thin circular segment.
## Exact projected extrema of planar circles and ellipses, restricted to each
## trimmed sweep. This expands the planning envelope, not the canonical trim.
## Other supports/curve families retain their existing sampled bounds.
pub func include_conics(s: Surface, face: BrepFace, edges: const Curve[], low: Vector3*, high: Vector3*) -> !:
if s.kind != surface_plane: return
for use in face.uses:
let edge = edges[edge_index(use)]
if edge.kind != curve_circle and edge.kind != curve_ellipse: continue
let minor = edge.weights[0] if edge.kind == curve_ellipse else edge.radius
for axis in [s.x,s.y]:
let critical = math.atan2(minor*edge.y.dot(axis),edge.radius*edge.x.dot(axis))
for theta in [critical,critical+math.pi]:
let t = arc_parameter(edge,theta)
if t < 0.0: continue
let relative = (try edge.at(t)).subtract(s.origin)
let uv = Vector3(relative.dot(s.x),relative.dot(s.y),0.0)
*low = Vector3(math.min(low.x,uv.x),math.min(low.y,uv.y),0.0)
*high = Vector3(math.max(high.x,uv.x),math.max(high.y,uv.y),0.0)