Skip to content

Commit

Permalink
Fixes various smaller lints reported by RustRover
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoeoef committed Jun 14, 2024
1 parent a6677c3 commit ecc9ce7
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 155 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
/Cargo.lock
.vscode
.vscode
.idea
2 changes: 1 addition & 1 deletion Architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Trait `Triangulation` contains *publicly visible* functions that are common for
`DCEL` (in `dcel.rs`) implements the underlying doubly connected edge list and all of its major accessor methods (e.g., for accessing vertices, edges and faces).
`dcel_operations.rs` implements several common operations on a DCEL, e.g. flipping an edge.

`DCEL`, and `dcel_operations` should, in contrast to `Triangulation`, not require a `V: HasPosition` bound anywhere. In other words: DCEL's only care about the *topology* of their elements, not about their actual position. The position is only required once the Delaunay property is evaluated (as part of `TriangulationExt`)
`DCEL`, and `dcel_operations` should, in contrast to `Triangulation`, not require a `V: HasPosition` bound anywhere. In other words: DCELs only care about the *topology* of their elements, not about their actual position. The position is only required once the Delaunay property is evaluated (as part of `TriangulationExt`)

# Module dependency graph

Expand Down
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.2.0] - 2017-05-13
### Changed
- Bumped compatible `cgmath` and `nalgebra` versions. Unfortunately, due to the way Cargo handles "external dependencies" (thus, dependencies whose types are part of spade's public API like `cgmath` and `nalgebra` Points), this must be considered a breaking change.
- `FloatKernel` now works happily with `f32` coordinates. They will be casted to double precision before the kernel evaluates any query, thus, no performance gain results from this. Only the space requirements will differ.
- `FloatKernel` now works happily with `f32` coordinates. They will be cast to double precision before the kernel evaluates any query, thus, no performance gain results from this. Only the space requirements will differ.

## [1.1.0] - 2017-04-12
### Deprecated
Expand Down Expand Up @@ -313,9 +313,8 @@ A lot has changed for the 1.0. release, only larger changes are shown.

### Changed
- cgmath dependency bumped to 0.12.*
- DelaunayTriangulations and some primitives now will only work with two
dimensional coordinates. Using higher dimensions actually yielded unspecified
results.
- DelaunayTriangulations and some primitives now will only work with two-dimensional
coordinates. Using higher dimensions actually yielded unspecified results.

## 0.1.0 - 2016-09-23
Initial commit
Expand Down
12 changes: 4 additions & 8 deletions delaunay_compare/examples/real_data_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Instant;

use anyhow::{Context, Ok};
use spade::{ConstrainedDelaunayTriangulation, Point2, Triangulation};
use tiny_skia::{Color, Paint, PathBuilder, Pixmap, Stroke, Transform};
use tiny_skia::{Paint, PathBuilder, Pixmap, Stroke, Transform};

fn main() -> anyhow::Result<()> {
let shape_file_path = "./examples/Europe_coastline.shp";
Expand Down Expand Up @@ -51,8 +51,7 @@ fn load_with_spade(vertices: &Vec<Point2<f64>>, edges: &Vec<[usize; 2]>) -> anyh

println!("Loading triangulation (spade)...");
let now = Instant::now();
let cdt =
spade::ConstrainedDelaunayTriangulation::<_>::bulk_load_cdt(vertices_clone, edges_clone)?;
let cdt = ConstrainedDelaunayTriangulation::<_>::bulk_load_cdt(vertices_clone, edges_clone)?;
println!("Done!");
println!("{} vertices (without duplicates)", cdt.num_vertices());
println!("{} undirected edges", cdt.num_undirected_edges());
Expand All @@ -69,10 +68,7 @@ fn load_with_spade(vertices: &Vec<Point2<f64>>, edges: &Vec<[usize; 2]>) -> anyh
let edges_clone = edges.clone();

let now = Instant::now();
spade::ConstrainedDelaunayTriangulation::<_>::bulk_load_cdt_stable(
vertices_clone,
edges_clone,
)?;
ConstrainedDelaunayTriangulation::<_>::bulk_load_cdt_stable(vertices_clone, edges_clone)?;

println!(
"loading time (spade cdt bulk load stable): {}ms",
Expand All @@ -82,7 +78,7 @@ fn load_with_spade(vertices: &Vec<Point2<f64>>, edges: &Vec<[usize; 2]>) -> anyh
let vertices_clone = vertices.clone();

let now = Instant::now();
spade::ConstrainedDelaunayTriangulation::<_>::bulk_load(vertices_clone)?;
ConstrainedDelaunayTriangulation::<_>::bulk_load(vertices_clone)?;
println!(
"loading time (spade without constraints): {}ms",
now.elapsed().as_millis()
Expand Down
6 changes: 3 additions & 3 deletions examples/interpolation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const VERTICES: &[PointWithHeight] = &[
PointWithHeight::new(5.0, 1.0, 0.2),
];

pub fn main() -> anyhow::Result<()> {
pub fn main() -> Result<()> {
let mut t = TriangulationType::default();
for vertex in VERTICES {
t.insert(*vertex)?;
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn main() -> anyhow::Result<()> {
);
}

fn save_pixmap(pixmap: Pixmap, name: &str) -> anyhow::Result<()> {
fn save_pixmap(pixmap: Pixmap, name: &str) -> Result<()> {
// tiny_skia doesn't support jpg encoding which is required for small file size when embedding this into
// the documentation. We'll have to convert the data into ImageBuffer from the image crate and then do
// the jpeg encoding.
Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn main() -> anyhow::Result<()> {
}

fn float_to_color(value: f64) -> [u8; 3] {
// mostly AI generated..
// mostly AI generated...
// Converts a hue value in the range 0.0 ..= 1.0 from HLS to RGB
let value = value.clamp(0.0, 1.0);

Expand Down
4 changes: 2 additions & 2 deletions examples/svg_renderer/scenario_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ pub fn delaunay_directed_edge_details_scenario() -> Sketch {

sketch.add(rev_label);

let next = edge.prev(); // Use prev since SVG uses a left handed coordinate system
let next = edge.prev(); // Use prev since SVG uses a left-handed coordinate system
let next_label = SketchElement::line(from_pos, convert_point(next.from().position()))
.create_adjacent_text("e.next()")
.font_size(FONT_SIZE)
.dy(DY);

sketch.add(next_label);

let prev = edge.next(); // Use prev since SVG uses a left handed coordinate system
let prev = edge.next(); // Use prev since SVG uses a left-handed coordinate system
let prev_label = SketchElement::line(convert_point(prev.to().position()), to_pos)
.create_adjacent_text("e.prev()")
.font_size(FONT_SIZE)
Expand Down
8 changes: 4 additions & 4 deletions images/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- Repeatedly loads an svg image. Useful for debugging. -->
<script type="text/javascript">
function refresh(node) {
var times = 3000;
const times = 3000;

(function startRefresh() {
var address;
let address;
if (node.src.indexOf('?') > -1)
address = node.src.split('?')[0];
else
Expand All @@ -18,12 +18,12 @@
}

window.onload = function () {
var node = document.getElementById('img');
const node = document.getElementById('img');
refresh(node);

}
</script>
<img src="line_intersection_iterator_scenario.svg" id="img" />
<img src="line_intersection_iterator_scenario.svg" id="img" alt="preview image" />


</html>
34 changes: 19 additions & 15 deletions src/cdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<UE> AsMut<UE> for CdtEdge<UE> {
}
}

/// A two dimensional
/// A two-dimensional
/// [constrained Delaunay triangulation](https://en.wikipedia.org/wiki/Constrained_Delaunay_triangulation).
///
/// A constrained Delaunay triangulation (CDT) is a triangulation that
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<UE> AsMut<UE> for CdtEdge<UE> {
///
/// # See also
/// Refer to [Triangulation] for most implemented methods on this type.
/// Refer to [DelaunayTriangulation](crate::DelaunayTriangulation) for general
/// Refer to [DelaunayTriangulation](DelaunayTriangulation) for general
/// information about using Delaunay triangulations.
#[doc(alias = "CDT")]
#[derive(Clone)]
Expand Down Expand Up @@ -213,13 +213,6 @@ where
&mut self.hint_generator
}

fn clear(&mut self) {
self.num_constraints = 0;
self.s_mut().clear();
let new_hint_generator = HintGenerator::initialize_from_triangulation(self);
*self.hint_generator_mut() = new_hint_generator;
}

fn from_parts(
dcel: Dcel<Self::Vertex, Self::DirectedEdge, Self::UndirectedEdge, Self::Face>,
hint_generator: Self::HintGenerator,
Expand All @@ -241,6 +234,13 @@ where
) {
(self.dcel, self.hint_generator, self.num_constraints)
}

fn clear(&mut self) {
self.num_constraints = 0;
self.s_mut().clear();
let new_hint_generator = HintGenerator::initialize_from_triangulation(self);
*self.hint_generator_mut() = new_hint_generator;
}
}

impl<V, DE, UE, F, L> From<DelaunayTriangulation<V, DE, UE, F, L>>
Expand Down Expand Up @@ -308,6 +308,7 @@ where
/// ```
///
/// # Panics
///
/// Panics if any constraint edges overlap. Panics if the edges contain an invalid index (out of range).
pub fn bulk_load_cdt(vertices: Vec<V>, edges: Vec<[usize; 2]>) -> Result<Self, InsertionError> {
let mut result = bulk_load_cdt(vertices, edges)?;
Expand Down Expand Up @@ -479,6 +480,7 @@ where
/// ```
///
/// # Panics
///
/// Panics if any of the generated constraints intersects with any other constraint edge.
pub fn add_constraint_edges(
&mut self,
Expand Down Expand Up @@ -509,6 +511,7 @@ where
/// Returns `true` if at least one constraint edge was added.
///
/// # Panics
///
/// Panics if the new constraint edge intersects with an existing
/// constraint edge. Use [can_add_constraint](Self::can_add_constraint) to check.
pub fn add_constraint_edge(&mut self, from: V, to: V) -> Result<bool, InsertionError> {
Expand All @@ -520,14 +523,15 @@ where
/// Adds a constraint edge between to vertices.
///
/// Returns `true` if at least one constraint edge was added.
/// Note that the given constraint might be splitted into smaller edges
/// Note that the given constraint might be split into smaller edges
/// if a vertex in the triangulation lies exactly on the constraint edge.
/// Thus, `cdt.exists_constraint(from, to)` is not necessarily `true`
/// after a call to this function.
///
/// Returns false and does nothing if `from == to`.
///
/// # Panics
///
/// Panics if the new constraint edge intersects an existing
/// constraint edge.
pub fn add_constraint(&mut self, from: FixedVertexHandle, to: FixedVertexHandle) -> bool {
Expand Down Expand Up @@ -625,7 +629,7 @@ where
let border_loop_vec: Vec<_> = border_loop.into();

// The last edge of border_loop_vec must be part of the added constraint
// edge. Otherwise remesh_edge_ring will not create an edge between
// edge. Otherwise, remesh_edge_ring will not create an edge between
// cur_from and vertex
assert_eq!(
self.directed_edge(*border_loop_vec.last().unwrap())
Expand Down Expand Up @@ -926,7 +930,7 @@ mod test {
fn test_add_border_constraint() -> Result<(), InsertionError> {
let points = random_points_with_seed(1000, SEED);
let mut cdt = Cdt::new();
let mut max_y = -::core::f64::MAX;
let mut max_y = -f64::MAX;
for point in points {
max_y = max_y.max(point.y);
cdt.insert(point)?;
Expand Down Expand Up @@ -959,12 +963,12 @@ mod test {
}
let seed = if overlapping { SEED } else { SEED2 };
let delaunay_points = random_points_in_range(RANGE * 0.9, 80, seed);
// Use a delaunay triangulation to "generate" non intersecting constraint edges
// Use a delaunay triangulation to "generate" non-intersecting constraint edges
let mut d = Delaunay::new();
for p in delaunay_points {
d.insert(p)?;
}
let mut used_vertices = ::hashbrown::HashSet::new();
let mut used_vertices = hashbrown::HashSet::new();

let mut inserted_constraints = Vec::new();
for v in d.vertices() {
Expand Down Expand Up @@ -1159,7 +1163,7 @@ mod test {
fn fuzz_test_on_grid() -> Result<(), InsertionError> {
use rand::seq::SliceRandom;
// Generates points on a grid and randomly connects
// them with non intersecting constraints
// them with non-intersecting constraints
let seed = SEED;
let mut points = Vec::with_capacity((RANGE * RANGE) as usize);
const RANGE: i64 = 30;
Expand Down
22 changes: 11 additions & 11 deletions src/delaunay_core/bulk_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use alloc::vec::Vec;
///
/// This is only used as part of bulk loading.
/// All input coordinates are checked with `validate_coordinate` before they are used, hence
/// `Ord` and `Eq` should always be well defined.
/// `Ord` and `Eq` should always be well-defined.
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
struct FloatOrd<S>(S);

Expand Down Expand Up @@ -277,7 +277,7 @@ where
//
// This process is certainly confusing and inefficient but, luckily, rarely required for real inputs.

// Push the element again, it will popped directly. This seems to be somewhat simpler than
// Push the element again, it will be popped directly. This seems to be somewhat simpler than
// the alternatives.
elements.push((old_index, skipped));
hull = loop {
Expand Down Expand Up @@ -327,7 +327,7 @@ where

// Note that we don't re-sort the elements according to their distance to the newest center. This doesn't seem to
// be required for the algorithms performance, probably due to the `center` being close to `initial_center`.
// As of now, it is a unclear how to construct point sets that result in a `center` being farther off
// As of now, it is unclear how to construct point sets that result in a `center` being farther off
// `initial center` and what the impact of this would be.
let center = Point2::new(sum_x, sum_y).mul(<V as HasPosition>::Scalar::from(0.25f32));

Expand Down Expand Up @@ -484,7 +484,7 @@ where
let edge = edge.fix();

let new_vertex =
super::dcel_operations::create_new_face_adjacent_to_edge(result.s_mut(), edge, element);
dcel_operations::create_new_face_adjacent_to_edge(result.s_mut(), edge, element);
let ccw_walk_start = result.directed_edge(edge).prev().rev().fix();
let cw_walk_start = result.directed_edge(edge).next().rev().fix();

Expand All @@ -495,7 +495,7 @@ where
// up in a strongly *star shaped* triangulation instead of a nice nearly-convex blob of faces.
//
// To fix this, the algorithm proceeds by connecting some of the adjacent edges and forming new
// faces. A faces is only created if all of its inner angles are less than 90 degrees. This
// faces. A face is only created if all of its inner angles are less than 90 degrees. This
// tends to be a good heuristic that doesn't create too many skewed triangles which would need
// to be fixed later. Refer to the motivating research paper (see method `bulk_load`) for
// more information.
Expand Down Expand Up @@ -707,10 +707,10 @@ struct Node {
/// It implements an efficient mapping of (pseudo-)angles to edges. To do so, it stores all inserted
/// edges in a linked list backed by a vec. Finding an edge belonging to a given angle can always
/// be done by iterating through this list until the target angle is found.
/// The entries are stored in a consistent order (either clockwise or counter clockwise)
/// The entries are stored in a consistent order (either clockwise or counterclockwise)
///
/// This naive sequential search is very slow as it needs to traverse half of the list on average.
/// To speed things up, the space space of valid angles (the half open interval [0, 1) )
/// To speed things up, the space of valid angles (the half open interval [0, 1) )
/// is partitioned into `n` equally sized buckets.
/// For each bucket, `Hull` stores a reference to the list entry with the *biggest angle* that
/// still belongs into that bucket. A sequential search will begin at this bucket and has to traverse
Expand Down Expand Up @@ -825,7 +825,7 @@ impl Hull {
/// Such a vertex is guaranteed to have two outgoing edges that are adjacent to the convex hull,
/// e.g. `e0 -> v -> e1`
///
/// In this scenarios, the parameters should be set as follows:
/// In these scenarios, the parameters should be set as follows:
/// * `left_angle`: `pseudo_angle(e0.from())`
/// * `middle_angle`: `pseudo_angle(v.position())`
/// * `right_angle`: `pseudo_angle(e1.to())`
Expand Down Expand Up @@ -896,7 +896,7 @@ impl Hull {
right_angle = self.data[right_index].angle;
}

// Stich the vertex between left_index and right_index
// Stitch the vertex between left_index and right_index
self.data[left_index].right = new_index;
self.data[right_index].left = new_index;

Expand Down Expand Up @@ -970,11 +970,11 @@ impl Hull {

/// Looks up what bucket a given pseudo-angle will fall into.
fn floored_bucket(&self, angle: FloatOrd<f64>) -> usize {
((angle.0 * (self.buckets.len()) as f64).floor() as usize) % self.buckets.len()
((angle.0 * self.buckets.len() as f64).floor() as usize) % self.buckets.len()
}

fn ceiled_bucket(&self, angle: FloatOrd<f64>) -> usize {
((angle.0 * (self.buckets.len()) as f64).ceil() as usize) % self.buckets.len()
((angle.0 * self.buckets.len() as f64).ceil() as usize) % self.buckets.len()
}

fn segment(&self, node: &Node) -> Segment {
Expand Down
2 changes: 1 addition & 1 deletion src/delaunay_core/dcel_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ where
UE: Default,
F: Default,
{
// All edges are oriented counter clockwise
// All edges are oriented counterclockwise
//
// Original triangle:
// v1
Expand Down
4 changes: 2 additions & 2 deletions src/delaunay_core/handles/handle_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub trait DelaunayElementType: Sized + Default {
}
/// Internal type definition that is only exposed for documentation purposes.
///
/// Rust will currently not generate documentation for type definitions depending
/// Rust will currently not generate documentation for type definitions depending on
/// `pub(crate)` types, see [#32077](https://github.com/rust-lang/rust/issues/32077).
///
/// Do not use these types. Their removal will not be considered a breaking change.
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<Type: Default, InnerOuter: InnerOuterMarker> FixedHandleImpl<Type, InnerOut

/// Internal type definition that is only exposed for documentation purposes.
///
/// Rust will currently not generate documentation for type definitions depending
/// Rust will currently not generate documentation for type definitions depending on
/// `pub(crate)` types, see [#32077](https://github.com/rust-lang/rust/issues/32077).
///
/// Do not use these types. Their removal from the public API will not be considered a
Expand Down
Loading

0 comments on commit ecc9ce7

Please sign in to comment.