aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlotte Pabst <charlotte.pabst@stud.tu-darmstadt.de>2024-03-24 16:52:24 +0100
committerCharlotte Pabst <charlotte.pabst@stud.tu-darmstadt.de>2024-03-24 17:20:07 +0100
commit68a72735be76a8782e03c986849da47cd2601f13 (patch)
treecb769c9b1af24880d9775a99f089760ae3b56c7b
parentf552c45b5f08c4cf7af9dda1f4251d130b38ab15 (diff)
downloaddcel-68a72735be76a8782e03c986849da47cd2601f13.tar.xz
cleanup
-rw-r--r--Cargo.toml2
-rw-r--r--examples/cairo.rs2
-rw-r--r--src/dot.rs121
-rw-r--r--src/entity_iterator.rs2
-rw-r--r--src/img.rs90
-rw-r--r--src/lib.rs20
-rw-r--r--src/obj_import.rs21
-rw-r--r--src/tests.rs4
8 files changed, 38 insertions, 224 deletions
diff --git a/Cargo.toml b/Cargo.toml
index eb10c49..e0e62c9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ edition = "2021"
license = "MIT"
[features]
-test = ["obj_import", "img", "cairo-rs/svg", "cairo-rs/png"]
+test = ["obj_import", "img", "cairo-rs/svg"]
img = ["dep:cairo-rs", "dep:enumset"]
obj_import = ["dep:obj-rs", "dep:either"]
diff --git a/examples/cairo.rs b/examples/cairo.rs
index 3114136..cebd755 100644
--- a/examples/cairo.rs
+++ b/examples/cairo.rs
@@ -1,6 +1,5 @@
use cairo::{Context, SvgSurface};
use dcel::Dcel;
-use enumset::EnumSet;
use std::borrow::Cow;
fn main() {
@@ -17,7 +16,6 @@ fn main() {
dcel::write_img(
&dcel,
&ctx,
- EnumSet::all(),
|v| {
[
v.1[0] as f64 * width / 3.0 + width / 2.0,
diff --git a/src/dot.rs b/src/dot.rs
deleted file mode 100644
index 97f4ab1..0000000
--- a/src/dot.rs
+++ /dev/null
@@ -1,121 +0,0 @@
-use crate::*;
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct DcelDotOptions {
- pub twin: bool,
- pub next: bool,
- pub prev: bool,
-}
-
-impl DcelDotOptions {
- pub fn none() -> Self {
- Self {
- twin: false,
- next: false,
- prev: false,
- }
- }
-
- pub fn all() -> Self {
- Self {
- twin: true,
- next: true,
- prev: true,
- }
- }
-}
-
-pub fn dcel_write_dot<V>(
- dcel: &Dcel<V>,
- pos: impl Fn(&V) -> [f64; 2],
- name: impl Fn(&V, &mut Formatter) -> fmt::Result,
- f: &mut Formatter,
- opt: DcelDotOptions,
-) -> fmt::Result {
- writeln!(f, "digraph DCEL {{")?;
- writeln!(f, "node [shape = circle]")?;
- //writeln!(f, "nodesep = 1")?;
-
- for shell in dcel.iter_bodies().flat_map(Lens::iter_shells) {
- for vertex in shell.iter_vertices() {
- let p = pos(vertex.data());
-
- writeln!(
- f,
- "vertex_{} [label=\"{}\", pos=\"{},{}!\"]",
- vertex.id(),
- DisplayFn(|f| name(vertex.data(), f)),
- p[0],
- p[1]
- )?;
- }
-
- for hedges in shell
- .iter_edges()
- .map(|x| x.half_edges())
- .flat_map(|[he1, he2]| [[he1, he2], [he2, he1]])
- {
- let ids = hedges.map(Lens::id);
- let vertices = hedges.map(|h| h.origin());
- let points = vertices.map(|v| pos(v.data()));
-
- let mut diff = [points[1][1] - points[0][1], points[1][0] - points[0][0]];
-
- // let len = (diff[0] * diff[0] + diff[1] * diff[1]).sqrt();
- diff[0] *= -0.075;
- diff[1] *= 0.075;
-
- let mid = [
- (points[1][0] + points[0][0]) / 2.0 + diff[0],
- (points[1][1] + points[0][1]) / 2.0 + diff[1],
- ];
-
- writeln!(
- f,
- "half_edge_{} [pos=\"{},{}!\", shape=point, width=0.01, height=0.01]",
- ids[0], mid[0], mid[1]
- )?;
- writeln!(
- f,
- "vertex_{} -> half_edge_{} [arrowhead=none]",
- vertices[0].id(),
- ids[0]
- )?;
- writeln!(
- f,
- "half_edge_{} -> vertex_{} [label=\"{}\"]",
- ids[0],
- vertices[1].id(),
- ids[0]
- )?;
-
- if opt.twin {
- writeln!(
- f,
- "half_edge_{} -> half_edge_{} [color=\"red\"]",
- ids[0], ids[1]
- )?;
- }
-
- if opt.next {
- writeln!(
- f,
- "half_edge_{} -> half_edge_{} [color=\"green\"]",
- ids[0],
- hedges[0].next().id(),
- )?;
- }
-
- if opt.prev {
- writeln!(
- f,
- "half_edge_{} -> half_edge_{} [color=\"blue\"]",
- ids[0],
- hedges[0].prev().id(),
- )?;
- }
- }
- }
-
- writeln!(f, "}}")
-}
diff --git a/src/entity_iterator.rs b/src/entity_iterator.rs
index 58cd2a9..2e8c906 100644
--- a/src/entity_iterator.rs
+++ b/src/entity_iterator.rs
@@ -4,7 +4,7 @@ pub struct EntityIterator<'tok, 'brand, 'arena, T>(Option<(lens_t!(T), lens_t!(T
impl<'tok, 'brand, 'arena, T> Clone for EntityIterator<'tok, 'brand, 'arena, T> {
fn clone(&self) -> Self {
- Self(self.0)
+ *self
}
}
diff --git a/src/img.rs b/src/img.rs
index 5d015ff..4cc4b5a 100644
--- a/src/img.rs
+++ b/src/img.rs
@@ -1,30 +1,17 @@
use crate::*;
pub use cairo;
-pub use enumset::{self, EnumSet};
-use cairo::{Context, Surface};
-use enumset::EnumSetType;
+use cairo::Context;
use std::borrow::{Borrow, Cow};
-#[derive(EnumSetType, Debug)]
-pub enum ImgOption {
- Twin,
- Next,
- Prev,
- EdgeIds,
-}
-
pub fn write_img<V>(
dcel: &Dcel<V>,
ctx: &Context,
- opt: EnumSet<ImgOption>,
pos: impl Fn(&V) -> [f64; 2],
label: impl Fn(&V) -> Cow<str>,
font_size: f64,
) -> Result<(), cairo::Error> {
- // let (_, _, width, height) = ctx.clip_extents()?;
-
ctx.set_font_size(font_size);
for shell in dcel.iter_bodies().flat_map(Lens::iter_shells) {
for hedges in shell
@@ -62,67 +49,18 @@ pub fn write_img<V>(
ctx.close_path();
ctx.fill()?;
- if opt.contains(ImgOption::EdgeIds) {
- //arrow[0]
-
- let num_pos = [arrow[0] + prp[0] * 4.0, arrow[1] + prp[1] * 4.0];
- let num_text = hedges[0].id().to_string();
-
- ctx.set_font_size(font_size / 2.0);
- let ext = ctx.text_extents(&num_text)?;
- ctx.move_to(
- num_pos[0] - ext.x_advance() / 2.0,
- num_pos[1] - ext.y_bearing() - ext.height() / 2.0,
- );
- ctx.show_text(&num_text)?;
- ctx.set_font_size(font_size);
- }
-
- /*
- writeln!(
- f,
- "half_edge_{} [pos=\"{},{}!\", shape=point, width=0.01, height=0.01]",
- ids[0], mid[0], mid[1]
- )?;
- writeln!(
- f,
- "vertex_{} -> half_edge_{} [arrowhead=none]",
- vertices[0].id(),
- ids[0]
- )?;
- writeln!(
- f,
- "half_edge_{} -> vertex_{} [label=\"{}\"]",
- ids[0],
- vertices[1].id(),
- ids[0]
- )?;
-
- if opt.twin {
- writeln!(
- f,
- "half_edge_{} -> half_edge_{} [color=\"red\"]",
- ids[0], ids[1]
- )?;
- }
-
- if opt.next {
- writeln!(
- f,
- "half_edge_{} -> half_edge_{} [color=\"green\"]",
- ids[0],
- hedges[0].next().id(),
- )?;
- }
-
- if opt.prev {
- writeln!(
- f,
- "half_edge_{} -> half_edge_{} [color=\"blue\"]",
- ids[0],
- hedges[0].prev().id(),
- )?;
- }*/
+ // edge ids
+ let num_pos = [arrow[0] + prp[0] * 4.0, arrow[1] + prp[1] * 4.0];
+ let num_text = hedges[0].id().to_string();
+
+ ctx.set_font_size(font_size / 2.0);
+ let ext = ctx.text_extents(&num_text)?;
+ ctx.move_to(
+ num_pos[0] - ext.x_advance() / 2.0,
+ num_pos[1] - ext.y_bearing() - ext.height() / 2.0,
+ );
+ ctx.show_text(&num_text)?;
+ ctx.set_font_size(font_size);
}
for vertex in shell.iter_vertices() {
@@ -160,6 +98,4 @@ pub fn write_img<V>(
}
Ok(())
-
- // writeln!(f, "}}")
}
diff --git a/src/lib.rs b/src/lib.rs
index 29e5a12..08af947 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,7 +1,11 @@
#![allow(private_bounds)]
+#![allow(clippy::type_complexity)]
+
+pub use ghost_cell;
+pub use typed_arena;
use core::ops::Deref;
-pub use ghost_cell::{GhostBorrow, GhostCell, GhostToken};
+use ghost_cell::{GhostCell, GhostToken};
use paste::paste;
use std::{
collections::HashMap,
@@ -10,7 +14,7 @@ use std::{
hash::{Hash, Hasher},
};
use thiserror::Error;
-pub use typed_arena::Arena;
+use typed_arena::Arena;
macro_rules! try_check {
($this:ident, $dcel:ident) => {
@@ -28,9 +32,6 @@ use entity::*;
mod entity_iterator;
pub use entity_iterator::*;
-mod dot;
-pub use dot::*;
-
#[cfg(feature = "img")]
mod img;
@@ -190,7 +191,7 @@ pub struct Ptr<'brand, 'arena, T>(pub &'arena GhostCell<'brand, T>);
impl<'brand, 'arena, T> Clone for ptr_t!(T) {
fn clone(&self) -> Self {
- Self(self.0)
+ *self
}
}
impl<'brand, 'arena, T> Copy for ptr_t!(T) {}
@@ -291,7 +292,7 @@ pub struct Lens<'tok, 'brand, 'arena, T> {
impl<'tok, 'brand, 'arena, T> Clone for lens_t!(T) {
fn clone(&self) -> Self {
- Self::new(self.item, self.token)
+ *self
}
}
impl<'tok, 'brand, 'arena, T> Copy for lens_t!(T) {}
@@ -311,7 +312,7 @@ impl<'tok, 'brand, 'arena, T: Hash> Hash for lens_t!(T) {
impl<'tok, 'brand, 'arena, T> ReflAsRef<GhostToken<'brand>> for lens_t!(T) {
fn as_ref(&self) -> &GhostToken<'brand> {
- &self.token
+ self.token
}
}
@@ -370,7 +371,7 @@ pub struct OutgoingIterator<'tok, 'brand, 'arena, V>(Option<(lens!(HalfEdge), le
impl<'tok, 'brand, 'arena, V> Clone for OutgoingIterator<'tok, 'brand, 'arena, V> {
fn clone(&self) -> Self {
- Self(self.0)
+ *self
}
}
@@ -785,6 +786,7 @@ impl<'brand, 'arena, V> Dcel<'brand, 'arena, V> {
}
}
+ #[allow(clippy::new_ret_no_self)]
pub fn new<R, F>(fun: F) -> R
where
for<'new_brand, 'new_arena> F: FnOnce(Dcel<'new_brand, 'new_arena, V>) -> R,
diff --git a/src/obj_import.rs b/src/obj_import.rs
index 577fa1e..339c502 100644
--- a/src/obj_import.rs
+++ b/src/obj_import.rs
@@ -4,16 +4,16 @@ use obj::raw::object::RawObj;
#[derive(Debug, Error)]
pub enum ObjImportError {
- #[error("vertex position index out of bounds")]
- InvalidPositionIndex,
+ #[error("vertex {0} position index out of bounds")]
+ InvalidPositionIndex(usize),
#[error("half-edge between vertices {0} and {1} appears twice")]
SameHalfEdge(usize, usize),
#[error("half-edge between vertices {0} and {1} does not have a twin")]
UnclaimedHalfEdge(usize, usize),
#[error("empty face")]
EmptyFace,
- #[error("vertex is not connected to any edges")]
- StandaloneVertex,
+ #[error("vertex {0} is not connected to any edges")]
+ StandaloneVertex(usize),
}
use ObjImportError::*;
@@ -95,9 +95,7 @@ impl<'tok, 'brand, 'arena, V> ObjImport<'tok, 'brand, 'arena, V> {
}
}
- fn iter_polygon(
- p: &obj::raw::object::Polygon,
- ) -> impl Iterator<Item = usize> + DoubleEndedIterator + '_ {
+ fn iter_polygon(p: &obj::raw::object::Polygon) -> impl DoubleEndedIterator<Item = usize> + '_ {
use either::{Left, Right};
use obj::raw::object::Polygon::*;
@@ -122,12 +120,13 @@ impl<'tok, 'brand, 'arena, V> ObjImport<'tok, 'brand, 'arena, V> {
if let Some((k, _)) = self.half_edges.iter().find(|(_, v)| v.is_some()) {
Err(UnclaimedHalfEdge(k.1 + 1, k.0 + 1))
- } else if self
+ } else if let Some((i, _)) = self
.vertices
.iter()
- .any(|x| x.maybe_outgoing(self.dcel).is_none())
+ .enumerate()
+ .find(|(_, x)| x.maybe_outgoing(self.dcel).is_none())
{
- Err(StandaloneVertex)
+ Err(StandaloneVertex(i + 1))
} else {
Ok(())
}
@@ -142,7 +141,7 @@ impl<'tok, 'brand, 'arena, V> ObjImport<'tok, 'brand, 'arena, V> {
use std::collections::hash_map::Entry::*;
let [a, b] = vertices;
- let v = *self.vertices.get(a).ok_or(InvalidPositionIndex)?;
+ let v = *self.vertices.get(a).ok_or(InvalidPositionIndex(a + 1))?;
let he = match self.half_edges.entry((a, b)) {
Occupied(mut e) => e.get_mut().take().ok_or(SameHalfEdge(a + 1, b + 1))?,
diff --git a/src/tests.rs b/src/tests.rs
index 4102add..5e0ebef 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -44,7 +44,7 @@ fn mev_kve() {
Dcel::<u32>::new(|mut dcel| {
let body = dcel.new_body();
let Kevvlfs {
- vertices: [v0, v1],
+ vertices: [_v0, v1],
edge: old_edge,
loop_,
..
@@ -67,7 +67,7 @@ fn mve_kev() {
Dcel::<u32>::new(|mut dcel| {
let body = dcel.new_body();
let Kevvlfs {
- vertices: [v0, v1],
+ vertices: [_v0, v1],
edge: old_edge,
loop_,
..