Skip to main content

Module brep

Module brep 

Source
Expand description

The .brep interchange text format, both directions.

An interchange format for boundary representation, implemented from its published specification. It carries exact geometry and full topology, which is what makes it a bridge for an application moving onto this kernel that a mesh cannot be.

The file is a header followed by tables (placements, geometry, topology), and the last of those is the interesting one. The header’s first line, the content type, is left out by a writer saving a shape on its own (as a project archive holds its parts), so the version line alone is enough. Topology records are written leaves first and numbered backwards: the final record is number one, and a record refers to its children by how far above it they sit. So a parent can only name children already written, the file needs no forward references, and a reader can build the model in a single pass with nothing left dangling.

§What crosses

Everything this kernel’s own geometry can say: lines, circles, ellipses, parabolas, hyperbolas, B-splines, and the trimmed and offset forms over them, in two dimensions and three; planes, cylinders, cones, spheres, tori, extrusions, revolutions, B-spline surfaces, and trimmed and offset forms over those. All of the topology, with every occurrence’s orientation and placement, and edges carrying their curve, their pcurves and their seams.

No record carries a reversal, so a curve run backwards crosses as a forward curve through the same points in the same direction: a circle or an ellipse with its frame turned, a hyperbola or a parabola with its y turned round, a reversed trim as a trim of its basis reversed. Where that curve reads the original at a shifted parameter (a conic run backwards over a window not symmetric about zero), every curve of the edge is written at the same shift, and the chart of a surface swept from it moves with it, so the edge’s curves still agree at each parameter.

§What does not

One thing the reader deliberately does not take on faith: whether an edge’s representations agree on parameterization. That is a claim, the writing kernel’s claim about its own data, and everything downstream relies on it, so it is measured here instead, each representation evaluated against the others at matched parameters and the claim re-established only where they actually land together. A file can therefore come back with the claim established where its writer never made it, which is the right direction to be wrong in.

Cached triangulations and the polygons that go with them are parsed and skipped rather than half-honoured: this kernel tessellates on demand and keeps its own cache, and a mesh read from a file would be a mesh nobody could say the deflection of. The bookkeeping flags each record carries are read and dropped for the same reason: they describe the state of the writer’s own session, not the shape.

Structs§

Numbering
A shape’s edges and faces in the order the file numbers them.

Functions§

read
Read a shape from interchange text, into a model of its own.
read_numbered
read, with the edges and faces as the file numbers them.
write
Write a shape as interchange text.