dymokomi/luce-cad
Source of release 0.9.5
0.9.5 / src / surfacing / blend_api.lucb
## Blends between surfaces (surfacing Stage 6; blend_surface.lucb,
## surface_fillet.lucb and tube.lucb have the plans): what Luce calls,
## CadSurfaceBlend. Each takes a geometry set and returns it with a new
## sheet named `name` after its bodies (the Surface Fillet's trims change
## the faces it rolls on), with its measures (CadSurfaceEdit's).
pub struct CadSurfaceBlend:
let reserved: u8 = 0
## Blend Surface (Alias's Freeform Blend; Profile Blend with
## `profiles`): between the sides `first` and `second` (Align's master
## words: edges, isoparms, curves on faces, free curves; a side's chain
## apart by `+`), each `continuity` G0 to G3 with its `shape` (1 as
## built; above it tighter toward the corner); Proportional Crown
## `crown` (-0.25 to 0.25 of the chord); `flow` flow_connect (the
## sides' ends connected) or flow_free (sections square to side 1);
## each side's `range` (side 1 from and to, side 2 from and to,
## fractions of its length); through the curves `profiles` (words apart
## by `;`).
pub static func blend(set: interop.Reference[GeometrySet], first: str, second: str, continuity: const i64[] = [1, 1], shape: const f64[] = [1.0, 1.0], crown: f64 = 0.0,
flow: i64 = 0, range: const f64[] = [0.0, 1.0, 0.0, 1.0], profiles: str = "", name: str = "Blend", interior: bool = false,
explicit: bool = false, degree_u: i64 = 0, spans_u: i64 = 1, degree_v: i64 = 0, spans_v: i64 = 4, tolerances: CadTolerances = CadTolerances()) -> interop.Reference[CadSurfaceEdit]!:
if continuity.length != 2 or shape.length != 2: error(invalid, "Blend Surface: a continuity and a shape for each side")
if range.length != 4: error(invalid, "Blend Surface: each side's range is two fractions")
if not (crown >= -0.25 and crown <= 0.25): error(invalid, "Blend Surface: Proportional Crown is -0.25 to 0.25")
if flow != flow_connect and flow != flow_free and flow != flow_edge: error(invalid, "Blend Surface: Flow Control is Connect ends, Free or Edge align")
let opts = BlendOptions([continuity[0], continuity[1]], [shape[0], shape[1]], crown, flow, [range[0], range[1], range[2], range[3]], interior,
Explicit(explicit, degree_u, spans_u, degree_v, spans_v))
var net = try blend_net(set, first, second, &opts, profiles)
defer net.close()
return try added_sheet(set, &net, name, tolerances)
## Surface Fillet (Alias's; Parasolid's face-face blend): a rolling ball
## between the face sets `first` and `second` (face names apart by `;`),
## radius `size` (with `chordal`, the chord between the contacts), each
## set's side flipped by `flips` (the default: toward the other set),
## the section `section` (fillet_chamfer, fillet_circular, fillet_g2,
## fillet_g3, fillet_bias with Bias Factor `bias`, fillet_lead with Knee
## Ratio `knee`) with Form Factor `form`, Curvature `curvature`
## (curvature_both, _one, _two, _none: the sets whose curvature G2, G3 and
## Bias match), `trim` (fillet_trim_automatic, fillet_trim_curves,
## fillet_trim_off), and Variable Fillets `variable` (pairs of a fraction
## along the fillet and the radius or chord there; fewer than two pairs:
## constant).
pub static func fillet(set: interop.Reference[GeometrySet], first: str, second: str, size: f64, section: i64 = 1, chordal: bool = false, flips: const bool[] = [false, false],
trim: i64 = 0, form: f64 = 1.0, name: str = "Fillet", bias: f64 = 0.0, knee: f64 = 0.0, curvature: i64 = 0,
variable: const f64[] = [0.0, 0.0], tolerances: CadTolerances = CadTolerances()) -> interop.Reference[CadSurfaceEdit]!:
if flips.length != 2: error(invalid, "Surface Fillet: a flip for each set")
if trim < fillet_trim_automatic or trim > fillet_trim_off: error(invalid, "Surface Fillet: Trim is Automatic, Curves on surface or Off")
let opts = FilletOptions(section, size, chordal, [flips[0], flips[1]], trim, form, bias, knee, curvature)
var sets: FilletSet[2] = [FilletSet(Growing[Master](), 1.0), FilletSet(Growing[Master](), 1.0)]
defer sets[0].close()
defer sets[1].close()
# A law of fewer than two points is none (the default's one pair).
var made = try fillet_net(set, first, second, &opts, &sets, variable if variable.length >= 4 else variable[..<0])
defer made.close()
let body = try net_body(tolerances, &made.net, name, true)
defer body.release()
var result = try with_body_added(set, body)
if trim != fillet_trim_off:
let trimmed = try fillet_trims(result, &made, &sets, trim, name)
result.release()
result = trimmed
let edit = try edit_of(result)
edit.value().count = 1
return edit
## Bridge Fillet (Alias's; Parasolid's three-face blend): a circular
## blend tangent to the face sets `first`, `second` and `center` (face
## names apart by `;`), its radius whatever touches all three at each
## station (`size` the first guess), each set's side flipped by `flips`
## (the defaults face the others); `trim` Automatic trims the first two
## sets back to their contacts and consumes the center set (its faces
## taken out: a rib's top rounded away), Curves on surface leaves the
## contacts as curves, Off leaves the faces.
pub static func bridge(set: interop.Reference[GeometrySet], first: str, second: str, center: str, size: f64, flips: const bool[] = [false, false], trim: i64 = 0,
name: str = "Bridge", tolerances: CadTolerances = CadTolerances()) -> interop.Reference[CadSurfaceEdit]!:
if flips.length != 2: error(invalid, "Bridge Fillet: a flip for each side set")
if trim < fillet_trim_automatic or trim > fillet_trim_off: error(invalid, "Bridge Fillet: Trim is Automatic, Curves on surface or Off")
if center.length == 0: error(invalid, "Bridge Fillet: pick the center set's faces")
let opts = FilletOptions(fillet_bridge, size, false, [flips[0], flips[1]], trim, 1.0)
var sets: FilletSet[2] = [FilletSet(Growing[Master](), 1.0), FilletSet(Growing[Master](), 1.0)]
defer sets[0].close()
defer sets[1].close()
let none_law: f64[1] = [0.0]
var made = try fillet_net(set, first, second, &opts, &sets, none_law[..<0], center)
defer made.close()
let body = try net_body(tolerances, &made.net, name, true)
defer body.release()
var result = try with_body_added(set, body)
if trim != fillet_trim_off:
let trimmed = try fillet_trims(result, &made, &sets, trim, name)
result.release()
result = trimmed
if trim == fillet_trim_automatic:
let consumed = try without_faces(result, center)
result.release()
result = consumed
let edit = try edit_of(result)
edit.value().count = 1
return edit
## Tube (Alias's Tubular Offset): a circular tube of radius `radius`
## along the curve `curve` (Align's master words: a curve, a curve on a
## face, an edge, an isoparm), its center moved `normal_offset` along
## the face's normal (the curve's frame's up off a face; negated with
## `flip`: a groove for a bump) and `tangent_offset` across; Alias's
## variable radius `variable` (pairs of a fraction along the curve and a
## radius; fewer than two pairs: constant) and `trim` (tube_trim_off,
## tube_trim_curves: where it meets the face as curves on it,
## tube_trim_inside: the face's strip under it taken away).
pub static func tube(set: interop.Reference[GeometrySet], curve: str, radius: f64, tangent_offset: f64 = 0.0, normal_offset: f64 = 0.0, flip: bool = false, name: str = "Tube",
variable: const f64[] = [0.0, 0.0], trim: i64 = 0, tolerances: CadTolerances = CadTolerances()) -> interop.Reference[CadSurfaceEdit]!:
if trim < tube_trim_off or trim > tube_trim_inside: error(invalid, "Tube: Trim is Off, Curves on surface or Inside")
let law = variable if variable.length >= 4 else variable[..<0]
var net = try tube_net(set, curve, radius, tangent_offset, normal_offset, flip, law)
defer net.close()
let added = try added_sheet(set, &net, name, tolerances)
if trim == tube_trim_off: return added
defer added.release()
let geometry = try added.value().geometry()
defer geometry.release()
let edit = try edit_of(try tube_trims(geometry, curve, radius, tangent_offset, normal_offset, flip, law, trim, name))
edit.value().count = 1
return edit