Skip to content

Commit

Permalink
limit number of polygons in one layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jul 18, 2024
1 parent 18806bc commit 1df9661
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ pub enum MeshError {
/// The mesh is invalid, such as having a vertex that does not belong to any polygon.
#[error("The mesh is invalid")]
InvalidMesh,
/// One of the layer has too many polygons (more than 2^24-1).
#[error("One layer has too many polygons")]
TooManyPolygon,
}

impl Layer {
Expand Down Expand Up @@ -252,6 +255,9 @@ impl Layer {
if vertices.is_empty() || polygons.is_empty() {
return Err(MeshError::EmptyMesh);
}
if polygons.len() > (2_i32.pow(24) - 1) as usize {
return Err(MeshError::TooManyPolygon);
}
let mut layer = Layer {
vertices,
polygons,
Expand Down

0 comments on commit 1df9661

Please sign in to comment.