Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion iTriangle/src/float/delaunay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@ use crate::int::triangulation::IndexType;
use alloc::vec::Vec;
use i_overlay::i_float::adapter::FloatPointAdapter;
use i_overlay::i_float::float::compatible::FloatPointCompatible;
use i_overlay::i_float::float::rect::FloatRect;
use i_overlay::i_float::int::number::int::IntNumber;
use i_overlay::i_shape::float::adapter::PathToFloat;

/// A Delaunay-refined triangle mesh with float-mapped geometry.
///
/// Produced from [`Triangulation::into_delaunay`] by applying edge flips
/// Produced from [`RawTriangulation::into_delaunay`] by applying edge flips
/// to satisfy the Delaunay condition.
pub struct Delaunay<P: FloatPointCompatible, I: IntNumber = i32> {
pub(super) delaunay: IntDelaunay<I>,
pub(super) adapter: FloatPointAdapter<P, I>,
}

impl<P: FloatPointCompatible, I: IntNumber> Default for Delaunay<P, I> {
#[inline]
fn default() -> Self {
Self {
delaunay: IntDelaunay {
points: Vec::new(),
triangles: Vec::new(),
},
adapter: FloatPointAdapter::new_conservative(FloatRect::zero()),
}
}
}

impl<P: FloatPointCompatible, I: IntNumber> RawTriangulation<P, I> {
#[inline]
pub fn into_delaunay(self) -> Delaunay<P, I> {
Expand Down
1 change: 0 additions & 1 deletion iTriangle/src/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! Coordinates must be finite, with absolute values at most `2^60` for `f32`
//! or `2^500` for `f64`. Invalid input bounds panic; empty geometry produces
//! an empty mesh. Automatic conversion uses the conservative adapter constructors,
//! reserving `I::BITS - 3` coordinate bits for integer differences, products, and
//! rounding, including unchecked APIs.
//! Unchecked APIs skip topology validation. Reusable `Triangulator` methods
Expand Down
22 changes: 21 additions & 1 deletion iTriangle/src/float/triangulation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::int::triangulation::{IndexType, IntTriangulation, RawIntTriangulation};
use crate::float::delaunay::Delaunay;
use crate::int::triangulation::{IndexType, IndicesBuilder, IntTriangulation, RawIntTriangulation};
use alloc::vec::Vec;
use i_overlay::i_float::adapter::FloatPointAdapter;
use i_overlay::i_float::float::compatible::FloatPointCompatible;
Expand Down Expand Up @@ -54,6 +55,25 @@ impl<P: FloatPointCompatible, I: IntNumber> RawTriangulation<P, I> {
}

impl<P, N: IndexType> Triangulation<P, N> {
/// Fills the triangulation from a Delaunay mesh
#[inline]
pub fn set_with_delaunay<I: IntNumber>(&mut self, delaunay: &Delaunay<P, I>)
where
P: FloatPointCompatible,
{
let mesh = &delaunay.delaunay;
mesh.triangles
.feed_indices(mesh.points.len(), &mut self.indices);

self.points.clear();
self.points.reserve(mesh.points.len());
self.points.extend(
mesh.points
.iter()
.map(|point| delaunay.adapter.int_to_float(point)),
);
}

#[inline]
pub fn with_capacity(capacity: usize) -> Self {
Self {
Expand Down
Loading
Loading