Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-cad

Source of release 0.9.3

0.9.3 / src / modeling / rules.lucb

## Fusion's Rule Fillet: edges chosen by a rule rather than picked, so the
## choice follows the body as it changes upstream. Rounds are convex edges
## (material taken away), fillets concave ones (material added); All Edges
## takes every blendable edge of those kinds, Between Faces only those
## between a face of one set and a face of the other.

## The references (references.lucb) of `w`'s edges the rule takes onto
## `out`: blendable edges, convex when `rounds`, concave when `fillets`;
## with `faces` naming faces (apart by `;`), only edges on one of them, and
## with `others` too, only edges between one of `faces` and one of
## `others`. An error when the rule takes none.
func rule_references(w: Shape*, rounds: bool, fillets: bool, faces: str, others: str, out: Growing[u8]*) -> !:
    if not rounds and not fillets: error(invalid, "a rule fillet takes rounds, fillets or both")
    var first = Growing[bool]()
    defer first.close()
    var second = Growing[bool]()
    defer second.close()
    try rule_faces(w, faces, &first)
    try rule_faces(w, others, &second)
    var taken = Growing[i64]()
    defer taken.close()
    for e in 0..<w.edges.count:
        let fa = w.sides.items[e * 2]
        let fb = w.sides.items[e * 2 + 1]
        if fa < 0 or fb < 0: continue
        if trimmed(faces) != "" and not between(w, e, first.view(), second.view()): continue
        if not (try blendable(w, e)): continue
        let rounded = try convex(w, e)
        if (rounded and rounds) or (not rounded and fillets): try taken.push((i64)e)
    if taken.count == 0: error(invalid, "the rule takes no edges of this body")
    try references_of(w, taken.view(), out)

## Which faces of `w` `names` names (apart by `;`) into `marks`; none named:
## every face.
func rule_faces(w: const Shape*, names: str, marks: Growing[bool]*) -> !:
    marks.clear()
    let all = trimmed(names) == ""
    try marks.fill(w.faces.count, all)
    if all: return
    var picked = Growing[usize]()
    defer picked.close()
    try faces_named(w, names, &picked)
    for f in picked.view(): marks.items[f] = true