geometry.union — Fuse two or more geometry features into one exact Boolean union.
feature = geometry.union(feature1, feature2, ...) returns a geometry.Feature for the volume occupied by any operand.
Syntax
feature = geometry.union(feature1, feature2, ...)Inputs
feature- Type
Any- Required
- Variadic
- Default
- —
- Description
- Two or more geometry.Feature operands.
Returns
feature- Type
Any- Description
- geometry.Feature for the Boolean union of all operands.
Errors
RunMat:geometry:union:InvalidInput- When
- The wrong number of arguments is passed. Fewer than two operands are given, an operand is not a geometry.Feature, or the operand graphs define one feature identity differently. A value violates the feature-graph contract.
- Message
geometry.union: invalid input
Behavior
At least two operands are required. Their feature graphs are merged so that shared features are kept once; two graphs that define the same feature identity differently are rejected. The union is one operation on all operands, not a chain of pairwise unions.
Operands that touch or overlap fuse into one solid. Disjoint operands remain separate solids in one result, so geometry.solid (which requires exactly one solid) fails at realization for a disjoint union.
The call records construction intent only. It appends one operation to an immutable, content-addressed feature graph and returns a new geometry.Feature; it does not run a CAD kernel, tessellate, or touch the filesystem. The graph is realized as exact B-rep topology when a .fea geometry declaration that imports the generating function is materialized for meshing or analysis.
Every failure, including the wrong number of arguments, a value of the wrong kind, and a value that violates the feature-graph contract (a nonpositive or non-finite length, radius, depth, distance, or angle, or an all-zero direction), raises the builtin's own RunMat:geometry:<name>:InvalidInput identifier, and no value is returned. Feature identities are derived from a digest of each operation, so repeating the same construction yields the same feature identity.
Use in a study
Return the finished part from a pure .m function: geometry.finish(feature) turns the final feature into a geometry.Generated product, and geometry.withRegion publishes typed selections under names. A .fea geometry declaration written as generated by function.<name> calls that function, realizes the exact geometry, and exposes each named selection as output.region.<name> for meshing, material assignment, constraints, and loads.
Fuse bosses, ribs, and stock into one body before selecting its material region with geometry.solid.
Errors
RunMat:geometry:union:InvalidInput reports every failure of the call: the wrong number of arguments, fewer than two operands, an operand that is not a geometry.Feature, or conflicting feature definitions, or a value that violates the feature-graph contract, such as a zero or negative dimension, a non-finite value, or an all-zero direction. A failed call returns nothing, and earlier values are unchanged because builder values are immutable.
Examples
Fuse a boss onto a plate
plate = geometry.box(80e-3, 50e-3, 8e-3);
boss = geometry.cylinder(8e-3, 12e-3, [0 0 1], [40e-3 25e-3 8e-3]);
body = geometry.union(plate, boss);
class(body)A single operand is rejected
plate = geometry.box(80e-3, 50e-3, 8e-3);
body = geometry.union(plate);Using geometry.union with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how geometry.union changes the result.
Run a small geometry.union example, explain the result, then change one input and compare the output.
FAQ
Does the order of operands matter?⌄
Not for the shape. The operand order is recorded in the operation, so it does affect the feature identity.
Can I display or mesh a feature directly in a script?⌄
Not yet. geometry.Feature and geometry.Generated are construction values; mesh and meshing.generate accept a loaded geometry.Asset. Realization happens when a .fea geometry declaration imports the generating function.
Related Geometry functions
Construction
geometry.box · geometry.chamfer · geometry.cylinder · geometry.edges · geometry.edgesIntroducedBy · geometry.extrude · geometry.faces · geometry.facesIntroducedBy · geometry.fillet · geometry.finish · geometry.hole · geometry.instance · geometry.intersect · geometry.pocket · geometry.revolve · geometry.solid · geometry.sphere · geometry.subtract · geometry.transform · geometry.withRegion
Related guides
Source you can read
Every RunMat function's source is public. Read exactly how geometry.union is executed, line by line, in Rust.
- View the source for geometry.union in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.