Skip to content

Commit

Permalink
Fix some formatting and clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
untoldwind committed Feb 3, 2020
1 parent a99cac8 commit 35a2cb9
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 88 deletions.
2 changes: 1 addition & 1 deletion lib/src/boolean/compare_segments.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::helper::Float;
use super::signed_area::signed_area;
use super::sweep_event::SweepEvent;
use super::helper::Float;
use std::cmp::Ordering;
use std::rc::Rc;

Expand Down
22 changes: 14 additions & 8 deletions lib/src/boolean/compute_fields.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::sweep_event::{EdgeType, SweepEvent, ResultTransition};
use super::Operation;
use super::helper::Float;
use super::sweep_event::{EdgeType, ResultTransition, SweepEvent};
use super::Operation;
use std::rc::Rc;

pub fn compute_fields<F>(event: &Rc<SweepEvent<F>>, maybe_prev: Option<&Rc<SweepEvent<F>>>, operation: Operation)
Expand Down Expand Up @@ -66,15 +66,21 @@ where
let that_in = !event.is_other_in_out();
let is_in = match operation {
Operation::Intersection => this_in && that_in,
Operation::Union => this_in || that_in,
Operation::Xor => this_in ^ that_in,
Operation::Difference =>
// Difference is assymmetric, so subject vs clipping matters.
Operation::Union => this_in || that_in,
Operation::Xor => this_in ^ that_in,
Operation::Difference =>
// Difference is assymmetric, so subject vs clipping matters.
{
if event.is_subject {
this_in && !that_in
} else {
that_in && !this_in
}
}
};
if is_in { ResultTransition::OutIn } else { ResultTransition::InOut }
}
if is_in {
ResultTransition::OutIn
} else {
ResultTransition::InOut
}
}
32 changes: 14 additions & 18 deletions lib/src/boolean/connect_edges.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::sweep_event::{SweepEvent, ResultTransition};
use geo_types::{Coordinate};
use super::helper::Float;
use super::sweep_event::{ResultTransition, SweepEvent};
use geo_types::Coordinate;
use std::collections::HashSet;
use std::rc::Rc;

Expand Down Expand Up @@ -46,7 +46,6 @@ where
result_events
}


fn next_pos<F>(pos: i32, result_events: &[Rc<SweepEvent<F>>], processed: &HashSet<i32>, orig_pos: i32) -> i32
where
F: Float,
Expand Down Expand Up @@ -79,10 +78,9 @@ where
new_pos
}


pub struct Contour<F>
where
F: Float
F: Float,
{
/// Raw coordinates of contour
pub points: Vec<Coordinate<F>>,
Expand All @@ -98,19 +96,23 @@ where

impl<F> Contour<F>
where
F: Float
F: Float,
{
pub fn new(hole_of: Option<i32>, depth: i32) -> Contour<F> {
Contour {
points: Vec::new(),
hole_ids: Vec::new(),
hole_of: hole_of,
depth: depth,
hole_of,
depth,
}
}

/// This logic implements the 4 cases of parent contours from Fig. 4 in the Martinez paper.
pub fn initialize_from_context(event: &Rc<SweepEvent<F>>, contours: &mut [Contour<F>], contour_id: i32) -> Contour<F> {
pub fn initialize_from_context(
event: &Rc<SweepEvent<F>>,
contours: &mut [Contour<F>],
contour_id: i32,
) -> Contour<F> {
if let Some(prev_in_result) = event.get_prev_in_result() {
// Note that it is valid to query the "previous in result" for its output contour id,
// because we must have already processed it (i.e., assigned an output contour id)
Expand Down Expand Up @@ -158,7 +160,6 @@ where
}
}


fn mark_as_processed<F>(processed: &mut HashSet<i32>, result_events: &[Rc<SweepEvent<F>>], pos: i32, contour_id: i32)
where
F: Float,
Expand All @@ -167,7 +168,6 @@ where
result_events[pos as usize].set_output_contour_id(contour_id);
}


pub fn connect_edges<F>(sorted_events: &[Rc<SweepEvent<F>>]) -> Vec<Contour<F>>
where
F: Float,
Expand All @@ -183,11 +183,7 @@ where
}

let contour_id = contours.len() as i32;
let mut contour = Contour::initialize_from_context(
&result_events[i as usize],
&mut contours,
contour_id,
);
let mut contour = Contour::initialize_from_context(&result_events[i as usize], &mut contours, contour_id);

let orig_pos = i; // Alias just for clarity
let mut pos = i;
Expand All @@ -207,12 +203,12 @@ where
// terminates the loop.
mark_as_processed(&mut processed, &result_events, pos, contour_id);

pos = result_events[pos as usize].get_other_pos(); // pos advancement (A)
pos = result_events[pos as usize].get_other_pos(); // pos advancement (A)

mark_as_processed(&mut processed, &result_events, pos, contour_id);
contour.points.push(result_events[pos as usize].point);

pos = next_pos(pos, &result_events, &processed, orig_pos); // pos advancement (B)
pos = next_pos(pos, &result_events, &processed, orig_pos); // pos advancement (B)

if pos == orig_pos {
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boolean/divide_segment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::helper::Float;
use super::sweep_event::SweepEvent;
use geo_types::Coordinate;
use super::helper::Float;
use std::collections::BinaryHeap;
use std::rc::Rc;

Expand Down
11 changes: 9 additions & 2 deletions lib/src/boolean/fill_queue.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use geo_types::{LineString, Polygon, Rect};
use super::helper::Float;
use geo_types::{LineString, Polygon, Rect};
use std::collections::BinaryHeap;
use std::rc::{Rc, Weak};

Expand Down Expand Up @@ -32,7 +32,14 @@ where
if exterior {
contour_id += 1;
}
process_polygon(&polygon.exterior(), false, contour_id, &mut event_queue, cbbox, exterior);
process_polygon(
&polygon.exterior(),
false,
contour_id,
&mut event_queue,
cbbox,
exterior,
);
for interior in polygon.interiors() {
process_polygon(interior, false, contour_id, &mut event_queue, cbbox, false);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boolean/helper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use num_traits::Float as NumTraitsFloat;
use std::cmp::Ordering;
use std::fmt::{Debug, Display};
use num_traits::Float as NumTraitsFloat;

pub trait Float: NumTraitsFloat + Debug + Display {}
impl<T: NumTraitsFloat + Debug + Display> Float for T {}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boolean/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use geo_types::{Coordinate, MultiPolygon, Polygon, LineString, Rect};
use geo_types::{Coordinate, LineString, MultiPolygon, Polygon, Rect};

pub mod compare_segments;
pub mod compute_fields;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boolean/possible_intersection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::divide_segment::divide_segment;
use super::helper::Float;
use super::segment_intersection::{intersection, LineIntersection};
use super::sweep_event::{EdgeType, SweepEvent};
use super::helper::Float;
use std::collections::BinaryHeap;
use std::rc::Rc;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/boolean/segment_intersection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use geo_types::Coordinate;
use super::helper::Float;
use geo_types::Coordinate;

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineIntersection<F>
Expand Down
11 changes: 7 additions & 4 deletions lib/src/boolean/signed_area.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use geo_types::Coordinate;
use super::helper::Float;
use robust::{Coord, orient2d};
use geo_types::Coordinate;
use robust::{orient2d, Coord};

#[inline]
pub fn coordinate_to_robust<F>(p : Coordinate<F>) -> Coord
pub fn coordinate_to_robust<F>(p: Coordinate<F>) -> Coord
where
F: Float,
{
Coord{x: p.x.to_f64().unwrap(), y: p.y.to_f64().unwrap()}
Coord {
x: p.x.to_f64().unwrap(),
y: p.y.to_f64().unwrap(),
}
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boolean/subdivide_segments.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::compare_segments::compare_segments;
use super::compute_fields::compute_fields;
use super::helper::Float;
use super::possible_intersection::possible_intersection;
use super::sweep_event::SweepEvent;
use super::Operation;
use crate::splay::SplaySet;
use geo_types::Rect;
use super::helper::Float;
use std::collections::BinaryHeap;
use std::rc::Rc;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/boolean/sweep_event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use geo_types::Coordinate;
use super::helper::Float;
use geo_types::Coordinate;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::rc::{Rc, Weak};
Expand Down
4 changes: 2 additions & 2 deletions tests/src/bin/run_single_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate geo_booleanop_tests;

use geo_booleanop_tests::helper::run_generic_test_case;
use std::fs;
use std::path::Path;
use std::process::Command;
use geo_booleanop_tests::helper::run_generic_test_case;

fn main() {
let args: Vec<String> = std::env::args().collect();
Expand All @@ -27,4 +27,4 @@ fn main() {
.arg(&filename_out)
.spawn()
.expect("Failed to run Python plot.");
}
}
Loading

0 comments on commit 35a2cb9

Please sign in to comment.