pub struct Cage {
pub vertices: Vec<CageVertex>,
pub faces: Vec<CageFace>,
pub creases: Vec<Crease>,
pub next_id: u32,
}Expand description
A control cage: a mesh of faces of any number of sides — quads mostly,
triangles and n-gons allowed — with the edges named in creases kept
sharp. Ids are unique across vertices and faces, and next_id is the
next one no element has had.
Fields§
§vertices: Vec<CageVertex>§faces: Vec<CageFace>§creases: Vec<Crease>The edges creased, in order of their vertices.
next_id: u32Implementations§
Source§impl Cage
impl Cage
Sourcepub fn vertex(&self, id: u32) -> GeopResult<&CageVertex>
pub fn vertex(&self, id: u32) -> GeopResult<&CageVertex>
The vertex id.
pub fn vertex_mut(&mut self, id: u32) -> GeopResult<&mut CageVertex>
Sourcepub fn face(&self, id: u32) -> GeopResult<&CageFace>
pub fn face(&self, id: u32) -> GeopResult<&CageFace>
The face id.
Sourcepub fn edges(&self) -> BTreeSet<[u32; 2]>
pub fn edges(&self) -> BTreeSet<[u32; 2]>
Every edge, each by its two vertices, the smaller id first, in order.
Sourcepub fn sharpness(&self, a: u32, b: u32) -> f64
pub fn sharpness(&self, a: u32, b: u32) -> f64
How sharp the edge between a and b is creased: zero for a smooth
edge, one for a sharp one (see Crease).
Sourcepub fn is_crease(&self, a: u32, b: u32) -> bool
pub fn is_crease(&self, a: u32, b: u32) -> bool
Whether the edge between a and b is creased at all.
Sourcepub fn directed_edges(&self) -> HashMap<(u32, u32), (usize, usize)>
pub fn directed_edges(&self) -> HashMap<(u32, u32), (usize, usize)>
The face that runs along each directed edge (a, b), by its index
and the corner of it at a. Two faces running the same way along
an edge are turned against each other: the later one is kept, and
Topology::new refuses the cage by name.
Sourcepub fn indexed(&self) -> GeopResult<(Mesh, Topology)>
pub fn indexed(&self) -> GeopResult<(Mesh, Topology)>
The cage indexed and its topology checked, for an edit that walks
around vertices: vertex i of the mesh is self.vertices[i], face
f is self.faces[f].
Source§impl Cage
impl Cage
Sourcepub fn cuboid(size: [f64; 3]) -> Self
pub fn cuboid(size: [f64; 3]) -> Self
A box around the origin, size long along each axis: eight
vertices, six quads.
Sourcepub fn cylinder(radius: f64, height: f64, segments: usize) -> Self
pub fn cylinder(radius: f64, height: f64, segments: usize) -> Self
A cylinder around the z axis, centred on the origin: segments
quads around, two rows high, closed by an n-gon at each end.
Sourcepub fn sphere(radius: f64) -> Self
pub fn sphere(radius: f64) -> Self
A sphere-like cage around the origin: a cube of 2 x 2 quads a side,
its vertices pushed out onto the sphere of radius.
Sourcepub fn plane(size: f64, n: usize) -> Self
pub fn plane(size: f64, n: usize) -> Self
A flat square in the z = 0 plane around the origin, size wide,
of n x n quads facing +z: an open cage, whose limit is a
sheet.
Sourcepub fn vertices_of(&self, keys: &[String]) -> BTreeSet<u32>
pub fn vertices_of(&self, keys: &[String]) -> BTreeSet<u32>
The vertices of the elements keys name, by id.
Sourcepub fn centre(&self, vertices: &BTreeSet<u32>) -> Option<[f64; 3]>
pub fn centre(&self, vertices: &BTreeSet<u32>) -> Option<[f64; 3]>
The centre of the vertices vertices: their average.
Sourcepub fn transform(
&mut self,
vertices: &BTreeSet<u32>,
mirror: Mirror,
f: impl Fn([f64; 3]) -> [f64; 3],
)
pub fn transform( &mut self, vertices: &BTreeSet<u32>, mirror: Mirror, f: impl Fn([f64; 3]) -> [f64; 3], )
The vertices vertices moved to where f takes them — those on the
plane of mirror kept on it, where the mirror image joins them.
Sourcepub fn set_sharpness(&mut self, edges: &[[u32; 2]], sharpness: f64)
pub fn set_sharpness(&mut self, edges: &[[u32; 2]], sharpness: f64)
Creases the edges edges at sharpness (see Crease): one is
sharp, zero or less smooths them again, and more than one is sharp.
Sourcepub fn delete_faces(&mut self, faces: &BTreeSet<u32>)
pub fn delete_faces(&mut self, faces: &BTreeSet<u32>)
Deletes the faces faces, and every vertex and crease that leaves
without a face.
Sourcepub fn faces_along(&self, edges: &[[u32; 2]]) -> BTreeSet<u32>
pub fn faces_along(&self, edges: &[[u32; 2]]) -> BTreeSet<u32>
The faces any of the edges edges is on, by id.
Sourcepub fn faces_around(&self, vertices: &BTreeSet<u32>) -> BTreeSet<u32>
pub fn faces_around(&self, vertices: &BTreeSet<u32>) -> BTreeSet<u32>
The faces any of the vertices vertices is a corner of, by id.
Sourcepub fn frame(&self, faces: &BTreeSet<u32>) -> Option<[[f64; 3]; 3]>
pub fn frame(&self, faces: &BTreeSet<u32>) -> Option<[[f64; 3]; 3]>
The orientation of the faces faces, for moving them along it: z
along their normals together, x along the first one’s first edge,
both unit and square to each other. None for no faces, or faces
whose normals cancel out.
Sourcepub fn extrude(
&mut self,
faces: &BTreeSet<u32>,
distance: f64,
mirror: Mirror,
) -> GeopResult<()>
pub fn extrude( &mut self, faces: &BTreeSet<u32>, distance: f64, mirror: Mirror, ) -> GeopResult<()>
Extrudes the faces faces distance along their normals (see
Cage::offset_region).
Sourcepub fn inset(
&mut self,
faces: &BTreeSet<u32>,
thickness: f64,
mirror: Mirror,
) -> GeopResult<()>
pub fn inset( &mut self, faces: &BTreeSet<u32>, thickness: f64, mirror: Mirror, ) -> GeopResult<()>
Insets the faces faces: their rim moves thickness inwards, in
the faces’ own planes, and a new ring of quads fills the gap to where
the rim was (see Cage::offset_region). A vertex inside the region
stays.
Sourcepub fn insert_loop(&mut self, a: u32, b: u32, t: f64) -> GeopResult<()>
pub fn insert_loop(&mut self, a: u32, b: u32, t: f64) -> GeopResult<()>
Cuts a new edge loop across the edge between a and b: through
every edge of its ring (see Cage::edge_ring) at the fraction t
of the way along it from a’s side, splitting each quad of the
ring in two. The halves of a creased edge keep its crease.
Sourcepub fn edge_slide(
&mut self,
edges: &[[u32; 2]],
factor: f64,
mirror: Mirror,
) -> GeopResult<()>
pub fn edge_slide( &mut self, edges: &[[u32; 2]], factor: f64, mirror: Mirror, ) -> GeopResult<()>
Slides the vertices of the chain of edges edges along the edges
leaving the chain, by the fraction factor of their length: towards
the side the faces running along the chain, oriented from its first
edge, lie on for a positive factor, the other side for a negative
one. Each vertex needs one edge to slide along on that side, which
the quads of the chain’s faces give it: a vertex where the chain
branches, or where its faces disagree, is refused by name.
Sourcepub fn bevel(
&mut self,
edges: &[[u32; 2]],
width: f64,
mirror: Mirror,
) -> GeopResult<()>
pub fn bevel( &mut self, edges: &[[u32; 2]], width: f64, mirror: Mirror, ) -> GeopResult<()>
Bevels the edges edges: each becomes a strip of one quad, width
wide, between the two faces along it, and each vertex where three or
more bevelled edges meet a face of its own. A vertex is split into
one vertex per sector — the faces around it between two bevelled
edges — placed width from both edges in the sector’s first and
last face. At a vertex with one bevelled edge the strip ends on the
faces beside it: its end vertices lie width along the two other
edges of the edge’s faces there, which split there, and a triangle
caps the strip between them and the vertex — which goes if that
leaves it between two faces, as at a box’s corner. Edges on the
boundary cannot be bevelled.
Sourcepub fn merge_vertices(
&mut self,
vertices: &BTreeSet<u32>,
mirror: Mirror,
) -> GeopResult<()>
pub fn merge_vertices( &mut self, vertices: &BTreeSet<u32>, mirror: Mirror, ) -> GeopResult<()>
Merges the vertices vertices into one at their centre — on the
mirror plane if any of them was — keeping the lowest id. A face left
with fewer than three corners goes; one that would run through the
merged vertex twice is refused by name.
Sourcepub fn dissolve_edges(
&mut self,
edges: &[[u32; 2]],
mirror: Mirror,
) -> GeopResult<()>
pub fn dissolve_edges( &mut self, edges: &[[u32; 2]], mirror: Mirror, ) -> GeopResult<()>
Dissolves the edges edges: the two faces along each become one,
keeping the lower id, and an end left between those two faces alone
goes with it. An edge with one face, or two faces that meet along
more than that edge, is refused by name.
Sourcepub fn dissolve_vertices(
&mut self,
vertices: &BTreeSet<u32>,
mirror: Mirror,
) -> GeopResult<()>
pub fn dissolve_vertices( &mut self, vertices: &BTreeSet<u32>, mirror: Mirror, ) -> GeopResult<()>
Dissolves the vertices vertices: the faces around each become one
face, keeping the lowest id, and the vertex goes — as does any
neighbour of it left between two faces alone. Faces around it that
meet elsewhere than at it are refused by name.
Sourcepub fn bridge(&mut self, a: u32, b: u32, mirror: Mirror) -> GeopResult<()>
pub fn bridge(&mut self, a: u32, b: u32, mirror: Mirror) -> GeopResult<()>
Bridges the faces a and b: both go, and a ring of quads joins
their rims, each corner of a to the nearest corner of b going
the other way round — a tunnel through the body, or a handle between
two of its faces. The faces need the same number of corners. With a
mirror, a quad that would lie in its plane is the seam to the
mirror image, and is left out.
Sourcepub fn fill_hole(&mut self, a: u32, b: u32, mirror: Mirror) -> GeopResult<()>
pub fn fill_hole(&mut self, a: u32, b: u32, mirror: Mirror) -> GeopResult<()>
Fills the hole the open edge between a and b is on with one face
through all the vertices around it (see Cage::boundary_run).
With a mirror, a hole whose rim lies in the plane is the seam to
the mirror image, and is refused.
Sourcepub fn halve(&mut self, axis: usize) -> GeopResult<()>
pub fn halve(&mut self, axis: usize) -> GeopResult<()>
Cuts the cage at the plane where coordinate axis is zero and keeps
the half where it is positive, as a mirrored cage holds it. Every
edge reaching across the plane is split where it crosses, the new
vertex exactly on the plane. A face crossing the plane more than
twice is refused, by name.
Sourcepub fn unmirrored(&self, mirror: Mirror) -> GeopResult<Cage>
pub fn unmirrored(&self, mirror: Mirror) -> GeopResult<Cage>
The whole cage the mirrored half stands for, as a cage of its own: the half keeps its ids, the mirror image gets new ones.
Source§impl Cage
impl Cage
Sourcepub fn edge_ring(&self, a: u32, b: u32) -> GeopResult<Ring>
pub fn edge_ring(&self, a: u32, b: u32) -> GeopResult<Ring>
The edge ring through the edge between a and b (see Ring).
Sourcepub fn edge_loop(&self, a: u32, b: u32) -> GeopResult<Vec<[u32; 2]>>
pub fn edge_loop(&self, a: u32, b: u32) -> GeopResult<Vec<[u32; 2]>>
The edge loop through the edge between a and b: on through
each vertex of four edges by the edge opposite — the one sharing no
face with the edge arrived by — until the loop closes or reaches a
vertex of any other number of edges, or the boundary. A boundary
edge’s loop is the boundary it is on (see Cage::boundary_run).
Sourcepub fn is_boundary(&self, a: u32, b: u32) -> bool
pub fn is_boundary(&self, a: u32, b: u32) -> bool
Whether only one face runs along the edge between a and b.
Sourcepub fn boundary_run(&self, a: u32, b: u32) -> GeopResult<Vec<u32>>
pub fn boundary_run(&self, a: u32, b: u32) -> GeopResult<Vec<u32>>
The boundary the open edge between a and b is on, as the
vertices around it, in the order the faces along it run: a face
closing it runs the other way. Fails for an edge that is not on the
boundary, and for a boundary that touches itself at a vertex, by
name.