Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
luiswirth authored and nical committed Apr 18, 2021
1 parent 7339f7f commit 22e3f83
Show file tree
Hide file tree
Showing 42 changed files with 860 additions and 639 deletions.
2 changes: 1 addition & 1 deletion algorithms/src/advanced_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// - simplify/remove it.

use crate::math::*;
use crate::path::{Path, PathEvent};
use crate::path::polygon::Polygon;
use crate::path::{Path, PathEvent};
use sid::{Id, IdRange, IdSlice, IdVec};
use std::ops;
use std::u16;
Expand Down
6 changes: 3 additions & 3 deletions algorithms/src/hatching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
//! let hatched_path = hatches.build();
//! ```
use crate::math::{point, vector, Angle, Point, Rotation, Vector};
use crate::geom::LineSegment;
use crate::math::{point, vector, Angle, Point, Rotation, Vector};
use crate::path::builder::{Build, PathBuilder};
use crate::path::private::DebugValidator;
use crate::path::{self, PathEvent, EndpointId};
use crate::path::{self, EndpointId, PathEvent};
use std::marker::PhantomData;

use std::cmp::Ordering;
Expand Down Expand Up @@ -705,7 +705,7 @@ fn simple_hatching() {
&HatchingOptions::DEFAULT,
&mut RegularHatchingPattern {
interval: 1.0,
callback: &mut|segment: &HatchSegment| {
callback: &mut |segment: &HatchSegment| {
hatches.add_line_segment(&LineSegment {
from: segment.a.position,
to: segment.b.position,
Expand Down
57 changes: 45 additions & 12 deletions algorithms/src/hit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ where
prev_winding = None;
}
PathEvent::Line { from, to } => {
test_segment(*point, &LineSegment { from, to }, &mut winding, &mut prev_winding);
test_segment(
*point,
&LineSegment { from, to },
&mut winding,
&mut prev_winding,
);
}
PathEvent::End { last, first, .. } => {
test_segment(
Expand All @@ -56,7 +61,12 @@ where
}
let mut prev = segment.from;
segment.for_each_flattened(tolerance, &mut |p| {
test_segment(*point, &LineSegment { from: prev, to: p }, &mut winding, &mut prev_winding);
test_segment(
*point,
&LineSegment { from: prev, to: p },
&mut winding,
&mut prev_winding,
);
prev = p;
});
}
Expand All @@ -78,7 +88,12 @@ where
}
let mut prev = segment.from;
segment.for_each_flattened(tolerance, &mut |p| {
test_segment(*point, &LineSegment { from: prev, to: p }, &mut winding, &mut prev_winding);
test_segment(
*point,
&LineSegment { from: prev, to: p },
&mut winding,
&mut prev_winding,
);
prev = p;
});
}
Expand All @@ -88,14 +103,19 @@ where
winding
}

fn test_segment(point: Point, segment: &LineSegment<f32>, winding: &mut i32, prev_winding: &mut Option<i32>) {
let y0 = segment.from.y;
let y1 = segment.to.y;
fn test_segment(
point: Point,
segment: &LineSegment<f32>,
winding: &mut i32,
prev_winding: &mut Option<i32>,
) {
let y0 = segment.from.y;
let y1 = segment.to.y;
if f32::min(y0, y1) > point.y
|| f32::max(y0, y1) < point.y
|| f32::min(segment.from.x, segment.to.x) > point.x
|| y0 == y1 {

|| y0 == y1
{
return;
}

Expand Down Expand Up @@ -142,7 +162,7 @@ fn test_segment(point: Point, segment: &LineSegment<f32>, winding: &mut i32, pre
//
// The main idea is that within a sub-path we can't have consecutive affecting edges
// of the same winding sign, so if we find some it means we are double-counting.
if *prev_winding != Some(w) {
if *prev_winding != Some(w) {
*winding += w;
}

Expand Down Expand Up @@ -180,7 +200,10 @@ fn test_hit_test() {
FillRule::EvenOdd,
0.1
));
println!("winding {:?}", path_winding_number_at_position(&point(2.0, 0.0), path.iter(), 0.1));
println!(
"winding {:?}",
path_winding_number_at_position(&point(2.0, 0.0), path.iter(), 0.1)
);
assert!(!hit_test_path(
&point(2.0, 0.0),
path.iter(),
Expand Down Expand Up @@ -242,6 +265,16 @@ fn hit_test_point_aligned() {
closed: true,
};

assert!(hit_test_path(&point(0.0, 5.0), poly.path_events(), FillRule::NonZero, 0.1));
assert!(!hit_test_path(&point(15.0, 5.0), poly.path_events(), FillRule::NonZero, 0.1));
assert!(hit_test_path(
&point(0.0, 5.0),
poly.path_events(),
FillRule::NonZero,
0.1
));
assert!(!hit_test_path(
&point(15.0, 5.0),
poly.path_events(),
FillRule::NonZero,
0.1
));
}
5 changes: 2 additions & 3 deletions algorithms/src/splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::advanced_path::*;
use crate::geom::{Line, LineSegment};
/// Split paths with a line or line segment.
use crate::math::*;
use crate::path::*;
use crate::path::polygon::Polygon;
use crate::path::iterator::PathIterator;
use crate::path::polygon::Polygon;
use crate::path::*;
use std::cmp::PartialOrd;
use std::mem;

Expand Down Expand Up @@ -749,7 +749,6 @@ fn split_with_segment_3() {

#[test]
fn split_with_segment_4() {

// ________
// | |
//-+--+-----+-
Expand Down
4 changes: 2 additions & 2 deletions algorithms/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
use crate::geom::{CubicBezierSegment, QuadraticBezierSegment};
use crate::math::*;
use crate::path::builder::*;
use crate::path::{PathEvent, EndpointId};
use crate::path::{EndpointId, PathEvent};

use std::f32;

Expand Down Expand Up @@ -171,7 +171,7 @@ impl<'l> PathBuilder for PathWalker<'l> {
if close {
let first = self.first;
self.line_to(first);
self.need_moveto = true;
self.need_moveto = true;
}
}

Expand Down
3 changes: 1 addition & 2 deletions bench/path/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ extern crate bencher;
use lyon::extra::rust_logo::build_logo_path;
use lyon::math::point;
use lyon::path::commands;
use lyon::path::PathBuffer;
use lyon::path::traits::*;
use lyon::path::PathBuffer;
use lyon::path::{ControlPointId, EndpointId, Event, IdEvent, Path, PathEvent};

use bencher::Bencher;
Expand All @@ -24,7 +24,6 @@ fn path_buffer_logo(bench: &mut Bencher) {
});
}


fn simple_path_build_empty(bench: &mut Bencher) {
bench.iter(|| {
let mut path = Path::builder();
Expand Down
16 changes: 4 additions & 12 deletions bench/tess/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,8 @@ fn fill_tess_03_logo_no_intersections(bench: &mut Bencher) {
bench.iter(|| {
for _ in 0..N {
let mut buffers: VertexBuffers<Point, u16> = VertexBuffers::new();
tess.tessellate_path(
&path,
&options,
&mut simple_builder(&mut buffers),
)
.unwrap();
tess.tessellate_path(&path, &options, &mut simple_builder(&mut buffers))
.unwrap();
}
})
}
Expand All @@ -139,12 +135,8 @@ fn fill_tess_05_logo_no_curve(bench: &mut Bencher) {
bench.iter(|| {
for _ in 0..N {
let mut buffers: VertexBuffers<Point, u16> = VertexBuffers::new();
tess.tessellate_path(
&path,
&options,
&mut simple_builder(&mut buffers),
)
.unwrap();
tess.tessellate_path(&path, &options, &mut simple_builder(&mut buffers))
.unwrap();
}
})
}
Expand Down
41 changes: 18 additions & 23 deletions cli/src/fuzzing.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::commands::{FuzzCmd, Tessellator};
use lyon::algorithms::hatching::*;
use lyon::extra::debugging::find_reduced_test_case;
use lyon::geom::LineSegment;
use lyon::math::*;
use lyon::path::Path;
use lyon::path::traits::PathBuilder;
use lyon::path::Path;
use lyon::tess2;
use lyon::tessellation::geometry_builder::NoOutput;
use lyon::tessellation::{FillTessellator, StrokeTessellator};
use lyon::algorithms::hatching::*;
use lyon::geom::LineSegment;
use rand;
use std::cmp::{max, min};

Expand Down Expand Up @@ -67,27 +67,22 @@ pub fn run(cmd: FuzzCmd) -> bool {
loop {
let path = generate_path(&cmd, i);
if let Some(options) = cmd.tess.fill {
let status = ::std::panic::catch_unwind(|| {
match cmd.tess.tessellator {
Tessellator::Default => {
let result = FillTessellator::new().tessellate(
&path,
&options,
&mut NoOutput::new(),
);
if !cmd.ignore_errors {
result.unwrap();
}
let status = ::std::panic::catch_unwind(|| match cmd.tess.tessellator {
Tessellator::Default => {
let result =
FillTessellator::new().tessellate(&path, &options, &mut NoOutput::new());
if !cmd.ignore_errors {
result.unwrap();
}
Tessellator::Tess2 => {
let result = tess2::FillTessellator::new().tessellate(
&path,
&options,
&mut NoOutput::new(),
);
if !cmd.ignore_errors {
result.unwrap();
}
}
Tessellator::Tess2 => {
let result = tess2::FillTessellator::new().tessellate(
&path,
&options,
&mut NoOutput::new(),
);
if !cmd.ignore_errors {
result.unwrap();
}
}
});
Expand Down
Loading

0 comments on commit 22e3f83

Please sign in to comment.