Skip to content

Commit 2610201

Browse files
committed
Add BufferType doc and simplify its use in buffer3d
1 parent 63516a8 commit 2610201

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/geometry.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
ptr::NonNull,
66
};
77

8-
use num_traits::FromPrimitive;
8+
use num_traits::{FromPrimitive, ToPrimitive};
99
use sfcgal_sys::{
1010
initialize, sfcgal_alloc_handler_t, sfcgal_error_handler_t, sfcgal_free_handler_t,
1111
sfcgal_geometry_alpha_shapes, sfcgal_geometry_approximate_medial_axis, sfcgal_geometry_area,
@@ -77,19 +77,20 @@ use crate::{
7777
Result, ToSFCGAL,
7878
};
7979

80+
/// Represent the buffer types usable with the `buffer3d` method.
8081
#[repr(C)]
82+
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Primitive)]
8183
pub enum BufferType {
82-
Round,
83-
CylSphere,
84-
Flat,
84+
Round = 0,
85+
CylSphere = 1,
86+
Flat = 2,
8587
}
8688

8789
/// SFCGAL Geometry types.
8890
///
8991
/// Indicates the type of shape represented by a `SFCGeometry`.
9092
#[repr(C)]
9193
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Primitive)]
92-
9394
pub enum GeomType {
9495
Point = 1,
9596
Linestring = 2,
@@ -120,7 +121,6 @@ impl GeomType {
120121

121122
/// Represents the orientation of a `SFCGeometry`.
122123
#[derive(PartialEq, Eq, Debug, Primitive)]
123-
124124
pub enum Orientation {
125125
CounterClockWise = -1isize,
126126
ClockWise = 1isize,
@@ -1355,16 +1355,13 @@ impl SFCGeometry {
13551355
bail!("The algorithm needs at least 3 segments");
13561356
}
13571357

1358-
let explicit = {
1359-
match buffer_type {
1360-
BufferType::Round => 0_u32,
1361-
BufferType::CylSphere => 1_u32,
1362-
BufferType::Flat => 2_u32,
1363-
}
1364-
};
1365-
13661358
unsafe {
1367-
let result = sfcgal_geometry_buffer3d(self.c_geom.as_ptr(), radius, segments, explicit);
1359+
let result = sfcgal_geometry_buffer3d(
1360+
self.c_geom.as_ptr(),
1361+
radius,
1362+
segments,
1363+
buffer_type.to_u32().unwrap(),
1364+
);
13681365

13691366
SFCGeometry::new_from_raw(result, true)
13701367
}

0 commit comments

Comments
 (0)