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
9 changes: 3 additions & 6 deletions iTriangle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "i_triangle"
version = "0.45.2"
version = "0.46.0"
edition = "2021"
authors = ["Nail Sharipov <nailxsharipov@gmail.com>"]
description = "Polygon Triangulation Library: Efficient Delaunay Triangulation for Complex Shapes."
Expand All @@ -20,14 +20,11 @@ serde = ["dep:serde", "i_overlay/serde"]
[dependencies]
serde = { version = "^1.0", default-features = false, features = ["derive"], optional = true }

#i_overlay = { path = "../../iOverlay/iOverlay" }
#i_tree = { path = "../../iTree" }
#i_key_sort = { path = "../../iKeySort/iKeySort" }

i_overlay = "^7.0.3"
i_overlay = { version = "^8.0.0"}
i_tree = "~0.19.0"
i_key_sort = "~0.11.0"

#i_overlay = { path = "../../iOverlay/iOverlay" }


[dev-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions iTriangle/src/advanced/centroid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ impl<I: IntNumber> IntTriangle<I> {
let b = self.vertices[1].point;
let c = self.vertices[2].point;

let x = a.x.wide() + b.x.wide() + c.x.wide();
let y = a.y.wide() + b.y.wide() + c.y.wide();
let x = a.x.to_wide() + b.x.to_wide() + c.x.to_wide();
let y = a.y.to_wide() + b.y.to_wide() + c.y.to_wide();

IntPoint::new(
I::from_wide(x / I::Wide::from_usize(3)),
Expand All @@ -144,8 +144,8 @@ impl<I: IntNumber> IntTriangle<I> {

#[inline]
fn middle<I: IntNumber>(a: IntPoint<I>, b: IntPoint<I>) -> IntPoint<I> {
let x = a.x.wide() + b.x.wide();
let y = a.y.wide() + b.y.wide();
let x = a.x.to_wide() + b.x.to_wide();
let y = a.y.to_wide() + b.y.to_wide();
IntPoint::new(
I::from_wide(x / I::Wide::TWO),
I::from_wide(y / I::Wide::TWO),
Expand Down
20 changes: 9 additions & 11 deletions iTriangle/src/float/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ use crate::float::triangulation::RawTriangulation;
use crate::int::custom::IntCustomTriangulatable;
use crate::int::triangulation::RawIntTriangulation;
use crate::int::validation::Validation;
use i_key_sort::sort::key::SortKey;
use i_overlay::core::integer::OverlayInt;
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::base::data::{Contour, Shape};
use i_overlay::i_shape::float::adapter::{PathToInt, ShapeToInt, ShapesToInt};
use i_overlay::i_shape::float::rect::RectInit;
use i_tree::{Expiration, LayoutNumber};

/// A trait for triangulating float geometry with user-defined validation rules.
///
Expand All @@ -24,7 +22,7 @@ pub trait CustomTriangulatable<P: FloatPointCompatible> {
/// Performs triangulation using the requested integer coordinate type.
fn custom_triangulate_as<I>(&self, validation: Validation<I>) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey;
I: OverlayInt;

/// Performs triangulation with Steiner points and a custom [`Validation`] config.
fn custom_triangulate_with_steiner_points(
Expand All @@ -42,7 +40,7 @@ pub trait CustomTriangulatable<P: FloatPointCompatible> {
validation: Validation<I>,
) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey;
I: OverlayInt;
}

impl<P> CustomTriangulatable<P> for Contour<P>
Expand All @@ -51,7 +49,7 @@ where
{
fn custom_triangulate_as<I>(&self, validation: Validation<I>) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_path(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -71,7 +69,7 @@ where
validation: Validation<I>,
) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_path(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -95,7 +93,7 @@ where
{
fn custom_triangulate_as<I>(&self, validation: Validation<I>) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -115,7 +113,7 @@ where
validation: Validation<I>,
) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -139,7 +137,7 @@ where
{
fn custom_triangulate_as<I>(&self, validation: Validation<I>) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_list_of_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -159,7 +157,7 @@ where
validation: Validation<I>,
) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_list_of_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand Down
20 changes: 9 additions & 11 deletions iTriangle/src/float/triangulatable.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use crate::float::triangulation::RawTriangulation;
use crate::int::triangulatable::IntTriangulatable;
use crate::int::triangulation::RawIntTriangulation;
use i_key_sort::sort::key::SortKey;
use i_overlay::core::integer::OverlayInt;
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::base::data::{Contour, Shape};
use i_overlay::i_shape::float::adapter::{PathToInt, ShapeToInt, ShapesToInt};
use i_overlay::i_shape::float::rect::RectInit;
use i_tree::{Expiration, LayoutNumber};

/// A trait for triangulating float-based geometry with default validation.
///
Expand All @@ -31,7 +29,7 @@ pub trait Triangulatable<P: FloatPointCompatible> {
/// Triangulates the shape(s) using the requested integer coordinate type.
fn triangulate_as<I>(&self) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey;
I: OverlayInt;

/// Triangulates the shape(s) and inserts the given Steiner points.
///
Expand All @@ -43,7 +41,7 @@ pub trait Triangulatable<P: FloatPointCompatible> {
/// Triangulates the shape(s) with Steiner points using the requested integer coordinate type.
fn triangulate_with_steiner_points_as<I>(&self, points: &[P]) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey;
I: OverlayInt;
}

impl<P> Triangulatable<P> for [P]
Expand All @@ -52,7 +50,7 @@ where
{
fn triangulate_as<I>(&self) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_path(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -68,7 +66,7 @@ where

fn triangulate_with_steiner_points_as<I>(&self, points: &[P]) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_path(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -92,7 +90,7 @@ where
{
fn triangulate_as<I>(&self) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -108,7 +106,7 @@ where

fn triangulate_with_steiner_points_as<I>(&self, points: &[P]) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -132,7 +130,7 @@ where
{
fn triangulate_as<I>(&self) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_list_of_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand All @@ -148,7 +146,7 @@ where

fn triangulate_with_steiner_points_as<I>(&self, points: &[P]) -> RawTriangulation<P, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
if let Some(rect) = FloatRect::with_list_of_paths(self) {
let adapter = FloatPointAdapter::<P, I>::new(rect);
Expand Down
4 changes: 1 addition & 3 deletions iTriangle/src/float/triangulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use i_overlay::i_float::float::compatible::FloatPointCompatible;
use i_overlay::i_float::float::number::FloatNumber;
use i_overlay::i_float::int::number::int::IntNumber;
use i_overlay::i_shape::float::adapter::PathToFloat;
use i_overlay::i_shape::util::reserve::Reserve;

/// A triangulation result based on integer computation, with float mapping.
///
Expand Down Expand Up @@ -72,8 +71,7 @@ impl<P, N: IndexType> Triangulation<P, N> {
P: FloatPointCompatible,
{
self.points.clear();
self.points
.reserve_capacity(triangulation.points.capacity());
self.points.reserve(triangulation.points.capacity());
self.points
.extend(triangulation.points.iter().map(|p| adapter.int_to_float(p)));

Expand Down
12 changes: 5 additions & 7 deletions iTriangle/src/float/triangulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ use crate::float::triangulation::Triangulation;
use crate::int::triangulation::{IndexType, IntTriangulation};
use crate::int::triangulator::IntTriangulator;
use crate::int::validation::Validation;
use i_key_sort::sort::key::SortKey;
use i_overlay::core::integer::OverlayInt;
use i_overlay::core::solver::Solver;
use i_overlay::i_float::float::compatible::FloatPointCompatible;
use i_overlay::i_float::int::number::int::IntNumber;
use i_overlay::i_shape::flat::buffer::FlatContoursBuffer;
use i_overlay::i_shape::source::resource::ShapeResource;
use i_tree::{Expiration, LayoutNumber};

/// A reusable triangulator that converts float-based shapes into triangle meshes.
pub struct Triangulator<N = u16, I = i32>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
{
flat_buffer: Option<FlatContoursBuffer<I>>,
int_buffer: Option<IntTriangulation<I, N>>,
Expand All @@ -22,7 +20,7 @@ where

impl<N, I> Triangulator<N, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
N: IndexType,
{
/// Enables or disables Delaunay refinement for triangulation.
Expand Down Expand Up @@ -73,7 +71,7 @@ where

impl<N, I> Default for Triangulator<N, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
N: IndexType,
{
#[inline]
Expand All @@ -84,7 +82,7 @@ where

impl<N, I> Triangulator<N, I>
where
I: IntNumber + Expiration + LayoutNumber + SortKey,
I: OverlayInt,
N: IndexType,
{
/// Performs triangulation on the provided shape resource and returns a new `Triangulation`.
Expand Down
15 changes: 4 additions & 11 deletions iTriangle/src/int/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use crate::int::solver::ShapesSolver;
use crate::int::solver::{ContourSolver, ShapeSolver};
use crate::int::triangulation::RawIntTriangulation;
use crate::int::validation::Validation;
use i_key_sort::sort::key::SortKey;
use i_overlay::core::integer::OverlayInt;
use i_overlay::i_float::int::number::int::IntNumber;
use i_overlay::i_float::int::point::IntPoint;
use i_overlay::i_shape::int::shape::{IntContour, IntShape, IntShapes};
use i_tree::{Expiration, LayoutNumber};

/// A trait for performing triangulation with custom validation settings.
///
Expand All @@ -29,9 +28,7 @@ pub trait IntCustomTriangulatable<I: IntNumber> {
) -> RawIntTriangulation<I>;
}

impl<I: IntNumber + Expiration + LayoutNumber + SortKey> IntCustomTriangulatable<I>
for IntContour<I>
{
impl<I: OverlayInt> IntCustomTriangulatable<I> for IntContour<I> {
#[inline]
fn custom_triangulate(&self, validation: Validation<I>) -> RawIntTriangulation<I> {
ContourSolver::triangulate(validation, self)
Expand All @@ -47,9 +44,7 @@ impl<I: IntNumber + Expiration + LayoutNumber + SortKey> IntCustomTriangulatable
}
}

impl<I: IntNumber + Expiration + LayoutNumber + SortKey> IntCustomTriangulatable<I>
for IntShape<I>
{
impl<I: OverlayInt> IntCustomTriangulatable<I> for IntShape<I> {
#[inline]
fn custom_triangulate(&self, validation: Validation<I>) -> RawIntTriangulation<I> {
ShapeSolver::triangulate(validation, self)
Expand All @@ -65,9 +60,7 @@ impl<I: IntNumber + Expiration + LayoutNumber + SortKey> IntCustomTriangulatable
}
}

impl<I: IntNumber + Expiration + LayoutNumber + SortKey> IntCustomTriangulatable<I>
for IntShapes<I>
{
impl<I: OverlayInt> IntCustomTriangulatable<I> for IntShapes<I> {
#[inline]
fn custom_triangulate(&self, validation: Validation<I>) -> RawIntTriangulation<I> {
ShapesSolver::triangulate(validation, self)
Expand Down
9 changes: 2 additions & 7 deletions iTriangle/src/int/earcut/earcut_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use i_overlay::i_float::int::number::int::IntNumber;
use i_overlay::i_float::int::number::wide_int::WideIntNumber;
use i_overlay::i_float::int::point::IntPoint;
use i_overlay::i_float::int::rect::IntRect;
use i_overlay::i_shape::util::reserve::Reserve;

pub(super) trait EarcutStore<I: IntNumber> {
fn collect_triangles(&mut self, contour: &[IntPoint<I>], start: usize, bits: u64, count: u32);
Expand Down Expand Up @@ -38,10 +37,8 @@ impl<I: IntNumber> Earcut64<I> for [IntPoint<I>] {
) {
debug_assert!(self.len() <= 64);

triangulation
.indices
.reserve_capacity(self.triangles_count(0));
triangulation.indices.clear();
triangulation.indices.reserve(self.triangles_count(0));

EarcutSolver::new(self, FlatEarcutStore::new(triangulation)).triangulate();

Expand All @@ -52,10 +49,8 @@ impl<I: IntNumber> Earcut64<I> for [IntPoint<I>] {
fn earcut_net_triangulate_into(&self, triangulation: &mut RawIntTriangulation<I>) {
debug_assert!(self.len() <= 64);

triangulation
.triangles
.reserve_capacity(self.triangles_count(0));
triangulation.triangles.clear();
triangulation.triangles.reserve(self.triangles_count(0));

EarcutSolver::new(self, NetEarcutStore::new(self.len(), triangulation)).triangulate();

Expand Down
3 changes: 1 addition & 2 deletions iTriangle/src/int/monotone/chain/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use i_overlay::i_float::int::point::IntPoint;
use i_overlay::i_float::triangle::Triangle;
use i_overlay::i_shape::flat::buffer::FlatContoursBuffer;
use i_overlay::i_shape::int::shape::{IntContour, IntShape};
use i_overlay::i_shape::util::reserve::Reserve;

pub(crate) struct ChainBuilder;

Expand Down Expand Up @@ -99,8 +98,8 @@ impl<I: IntNumber> ChainVertexExport for [ChainVertex<I>] {

#[inline]
fn feed_points(&self, points: &mut Vec<IntPoint<I>>) {
points.reserve_capacity(self.len());
points.clear();
points.reserve(self.len());
let mut index = usize::MAX;
for v in self.iter() {
if v.index != index {
Expand Down
Loading
Loading