From 8a451c1a7eaeacbb933889642e4e430f400888ec Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 29 Apr 2024 02:22:56 -0500 Subject: [PATCH] Add a `clear()` method to `VertexBuffers` This is just a convenience method for easier reuse. --- crates/tessellation/src/geometry_builder.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/tessellation/src/geometry_builder.rs b/crates/tessellation/src/geometry_builder.rs index 5a55c29c..9752fedc 100644 --- a/crates/tessellation/src/geometry_builder.rs +++ b/crates/tessellation/src/geometry_builder.rs @@ -189,13 +189,13 @@ //! ``` //! +pub use crate::error::GeometryBuilderError; use crate::math::Point; use crate::{FillVertex, Index, StrokeVertex, VertexId}; -pub use crate::error::GeometryBuilderError; +use alloc::vec::Vec; use core::convert::From; use core::ops::Add; -use alloc::vec::Vec; /// An interface separating tessellators and other geometry generation algorithms from the /// actual vertex construction. @@ -277,6 +277,12 @@ impl VertexBuffers { indices: Vec::with_capacity(num_indices), } } + + /// Empty the buffers without freeing memory, for reuse without reallocation. + pub fn clear(&mut self) { + self.vertices.clear(); + self.indices.clear(); + } } /// A temporary view on a `VertexBuffers` object which facilitate the population of vertex and index