Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-cad

Source of release 0.9.5

0.9.5 / src / meshing / mapped_refine.lucb

## Compound analytic sides can have equal counts but different angular phases.
## Check their interior support without introducing independent seam vertices.

## Refine a mapped analytic grid in UV while retaining every boundary identity.
pub func mapped_refine(mesh: MeshBuilder*, uv: const Vector3[], ids: const i64[], nx: usize, ny: usize, s: Surface, forward: bool, tolerance: f64, divisions: Density) -> !:
    var source = try MeshBuilder(precise = true)
    defer source.close()
    var low = mesh.points[(usize)ids[0]]
    var high = low
    for at in 0..<uv.length:
        _ = try source.point(uv[at])
        let p = mesh.points[(usize)ids[at]]
        low = Vector3(math.min(low.x, p.x), math.min(low.y, p.y), math.min(low.z, p.z))
        high = Vector3(math.max(high.x, p.x), math.max(high.y, p.y), math.max(high.z, p.z))
    for row in 0..<ny:
        for column in 0..<nx:
            let at = (i64)(row * (nx + 1) + column)
            let corners = [at, at + 1, at + (i64)nx + 2, at + (i64)nx + 1]
            try source.face(4)
            for corner in 0..<(usize)4: try source.corner(corners[corner if forward else 3 - corner])
    let initial = try source.finish()
    defer initial.release()
    # A cell stepping the angle both ways strays at its middle by both
    # directions' sags: the loosest way's and the tightest's.
    let deviation = (try loosest_sag(s, divisions, tolerance)) + (try surface_sag(s, divisions, tolerance))
    let refined = try refine_uv(initial, s, 1.0, 1.0, deviation)
    defer refined.release()
    let mapped = try new i64[(usize)refined.value().point_count()] --- in memory.heap
    defer free(mapped) in memory.heap
    for at in 0..<mapped.length:
        let p = try refined.value().point((i64)at)
        mapped[at] = ids[at] if at < ids.length else (try mesh.point(analytic_point(s, p.x, p.y)))
    for face in 0..<refined.value().face_count():
        let size = try refined.value().face_size(face)
        try mesh.face(size)
        for at in 0..<size: try mesh.corner(mapped[(usize)(try refined.value().face_point(face, at))])