Skip to content

Commit 810a6b8

Browse files
Fix Reserve (#54)
* Stubs for the new decimater * Fix reserve * Remove the other stuff * Clean up the option reference stuff * Clippy
1 parent 4b25401 commit 810a6b8

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub mod use_glam;
148148
mod subdiv;
149149

150150
#[cfg(feature = "decimate")]
151-
pub mod decimate;
151+
mod decimate;
152152

153153
#[cfg(feature = "decimate")]
154154
pub use decimate::{

src/property.rs

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ where
5252
self.props.push(prop);
5353
}
5454

55+
/**
56+
* Reserve memory to accomodate an additional `n` elements.
57+
*/
5558
pub fn reserve(&mut self, n: usize) -> Result<(), Error> {
5659
for prop in self.props.iter_mut() {
5760
prop.reserve(n)?;
@@ -486,6 +489,9 @@ where
486489
T: Clone + Copy,
487490
H: Handle,
488491
{
492+
/**
493+
* Reserve memory for an additional `n` values.
494+
*/
489495
fn reserve(&mut self, n: usize) -> Result<(), Error> {
490496
if let Some(prop) = self.data.upgrade() {
491497
prop.try_borrow_mut()

src/subdiv/catmull.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,24 @@ where
3131
fn reserve(
3232
niter: usize,
3333
mesh: &mut Topology,
34-
vertex_points: &mut Option<Vec<A::Vector>>,
34+
mut vertex_points: Option<&mut Vec<A::Vector>>,
3535
edge_points: &mut Vec<A::Vector>,
3636
face_points: &mut Vec<A::Vector>,
3737
) -> Result<(), Error> {
38+
if let Some(vpts) = vertex_points.as_mut() {
39+
vpts.clear();
40+
}
41+
edge_points.clear();
42+
face_points.clear();
3843
debug_assert!(niter > 0);
3944
let mut nv = mesh.num_vertices();
4045
let mut ne = mesh.num_edges();
4146
let mut nf = mesh.num_faces();
4247
for i in 0..niter {
4348
if i == niter - 1 {
4449
// Reserve the pos arrays.
45-
if let Some(vpos) = vertex_points {
46-
vpos.reserve(nv);
50+
if let Some(vpts) = vertex_points.as_mut() {
51+
vpts.reserve(nv);
4752
}
4853
edge_points.reserve(ne);
4954
face_points.reserve(nf);
@@ -256,7 +261,7 @@ where
256261
CatmullClark::<DIM, A>::reserve(
257262
iterations,
258263
&mut self.topol,
259-
&mut vpos,
264+
vpos.as_mut(),
260265
&mut epos,
261266
&mut fpos,
262267
)?;

src/subdiv/loop_subd.rs

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ where
105105
edge_points: &mut Vec<A::Vector>,
106106
) -> Result<(), Error> {
107107
let (mut nv, mut ne, mut nf) = (mesh.num_vertices(), mesh.num_edges(), mesh.num_faces());
108+
vertex_points.clear();
109+
edge_points.clear();
108110
for i in 0..iterations {
109111
if i == iterations - 1 {
110112
vertex_points.reserve(nv);

src/topol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ pub trait HasTopology: Sized {
197197
self.topology().fprops.num_properties()
198198
}
199199

200-
/// Reserve memory for the given number of elements.
200+
/// Reserve memory for the given number of `additional` elements.
201201
///
202202
/// The memory is also reserved for all properties.
203203
fn reserve(&mut self, nverts: usize, nedges: usize, nfaces: usize) -> Result<(), Error> {

0 commit comments

Comments
 (0)