Skip to content

Commit c17b9bb

Browse files
committed
Crate remade to be no_std with alloc. By default std still required for one Error trait, but can be turned off using features.
1 parent c9ff8dd commit c17b9bb

29 files changed

Lines changed: 105 additions & 57 deletions

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ autobenches = false
1212
[lib]
1313
bench = false
1414

15+
[features]
16+
default = [ "std" ]
17+
std = []
18+
1519
[dependencies]
1620
smallvec = "1"
1721
robust = "1.1.0"
1822
num-traits = "0.2"
23+
hashbrown = "0.14.2"
1924

2025
[dependencies.serde]
2126
package = "serde"
2227
optional = true
2328
version = "1"
24-
features = ["derive"]
29+
features = ["derive", "alloc"]
2530

2631
[workspace]
2732
members = ["delaunay_compare"]

benches/benchmark_utilities.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::{self, Display, Formatter};
1+
use core::fmt::{self, Display, Formatter};
22

33
use criterion::{measurement::WallTime, BenchmarkGroup, BenchmarkId, Throughput};
44
use rand::{distributions::uniform::SampleUniform, Rng, SeedableRng};
@@ -29,7 +29,7 @@ where
2929
{
3030
let range = rand::distributions::Uniform::new_inclusive(-range, range);
3131
let mut rng = rand::rngs::StdRng::from_seed(seed);
32-
std::iter::from_fn(move || Some(Point2::new(rng.sample(range), rng.sample(range))))
32+
core::iter::from_fn(move || Some(Point2::new(rng.sample(range), rng.sample(range))))
3333
}
3434

3535
pub fn uniform_f64() -> impl Iterator<Item = Point2<f64>> {
@@ -54,7 +54,7 @@ where
5454

5555
Some(Point2::new(last_x, last_y))
5656
};
57-
std::iter::from_fn(step_fn)
57+
core::iter::from_fn(step_fn)
5858
}
5959

6060
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]

delaunay_compare/benches/bench_utilities.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ where
1414
{
1515
let range = rand::distributions::Uniform::new_inclusive(-range, range);
1616
let mut rng = StdRng::from_seed(seed);
17-
std::iter::from_fn(move || Some([rng.sample(range), rng.sample(range)]))
17+
core::iter::from_fn(move || Some([rng.sample(range), rng.sample(range)]))
1818
}
1919

2020
pub fn uniform_f64() -> impl Iterator<Item = [f64; 2]> {
@@ -41,5 +41,5 @@ where
4141

4242
Some([last_x, last_y])
4343
};
44-
std::iter::from_fn(step_fn)
44+
core::iter::from_fn(step_fn)
4545
}

delaunay_compare/src/spade_crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type SpadePoint = spade::Point2<f64>;
55
#[derive(Default)]
66
pub struct SpadeCrateWithHintGenerator<HintGeneratorType> {
77
vertices: Vec<SpadePoint>,
8-
_hint_generator_type: std::marker::PhantomData<HintGeneratorType>,
8+
_hint_generator_type: core::marker::PhantomData<HintGeneratorType>,
99
}
1010

1111
pub type SpadeCrate = SpadeCrateWithHintGenerator<spade::LastUsedVertexHintGenerator>;

examples/svg_renderer/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod quicksketch;
22
mod scenario;
33
mod scenario_list;
44

5-
type Result = std::result::Result<(), Box<dyn std::error::Error>>;
5+
type Result = core::result::Result<(), Box<dyn std::error::Error>>;
66

77
/// Used for rendering SVGs for documentation. These are inlined (via #[doc = include_str!(...)])
88
/// into the doc comment of a few items. That makes sure they will be visible even for offline users.

examples/svg_renderer/quicksketch/color.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt::Display;
1+
use core::fmt::Display;
22

33
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Copy)]
44
pub struct SketchColor {
@@ -8,7 +8,7 @@ pub struct SketchColor {
88
}
99

1010
impl Display for SketchColor {
11-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1212
write!(f, "rgb({} {} {})", self.red, self.green, self.blue)
1313
}
1414
}

examples/svg_renderer/quicksketch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl Style {
178178
stroke_dash_array,
179179
])
180180
.flatten()
181-
.chain(std::iter::once(fill))
181+
.chain(core::iter::once(fill))
182182
.collect::<Vec<_>>()
183183
.join("; ")
184184
}

fuzz/fuzz_targets/bulk_load_fuzz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub struct FuzzPoint {
2727
y: f64,
2828
}
2929

30-
impl std::fmt::Debug for FuzzPoint {
31-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30+
impl core::fmt::Debug for FuzzPoint {
31+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
3232
f.write_fmt(format_args!("Point2::new({:?}, {:?})", self.x, self.y))
3333
}
3434
}

fuzz/fuzz_targets/bulk_load_int_fuzz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub struct IntFuzzPoint {
2626
y: i32,
2727
}
2828

29-
impl std::fmt::Debug for IntFuzzPoint {
30-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29+
impl core::fmt::Debug for IntFuzzPoint {
30+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
3131
f.write_fmt(format_args!("Point2::new({:?}.0, {:?}.0)", self.x, self.y))
3232
}
3333
}

src/cdt.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::{
77
#[cfg(feature = "serde")]
88
use serde::{Deserialize, Serialize};
99

10+
use alloc::{vec, vec::Vec};
11+
1012
/// Undirected edge type of a [ConstrainedDelaunayTriangulation] (CDT).
1113
///
1214
/// CDTs need to store if an undirected edge is a constrained edge. To do so, CDTs don't use
@@ -362,7 +364,7 @@ where
362364
VertexOutDirection::EdgeIntersection(edge) => edge,
363365
};
364366

365-
let mut border_loop = std::collections::VecDeque::new();
367+
let mut border_loop = alloc::collections::VecDeque::new();
366368

367369
border_loop.push_back(first_edge.rev().next().fix());
368370
border_loop.push_front(first_edge.rev().prev().fix());
@@ -552,6 +554,8 @@ mod test {
552554
type Cdt = ConstrainedDelaunayTriangulation<Point2<f64>>;
553555
type Delaunay = DelaunayTriangulation<Point2<f64>>;
554556

557+
use alloc::{vec, vec::Vec};
558+
555559
#[test]
556560
fn test_add_single_simple_constraint() -> Result<(), InsertionError> {
557561
let mut cdt = Cdt::new();
@@ -657,7 +661,7 @@ mod test {
657661
fn test_add_border_constraint() -> Result<(), InsertionError> {
658662
let points = random_points_with_seed(1000, SEED);
659663
let mut cdt = Cdt::new();
660-
let mut max_y = -::std::f64::MAX;
664+
let mut max_y = -::core::f64::MAX;
661665
for point in points {
662666
max_y = max_y.max(point.y);
663667
cdt.insert(point)?;
@@ -695,7 +699,8 @@ mod test {
695699
for p in delaunay_points {
696700
d.insert(p)?;
697701
}
698-
let mut used_vertices = ::std::collections::HashSet::new();
702+
let mut used_vertices = ::hashbrown::HashSet::new();
703+
699704
let mut inserted_constraints = Vec::new();
700705
for v in d.vertices() {
701706
// Insert only edges that do not touch at the end points if

0 commit comments

Comments
 (0)