tuning EPSILON_DIST to make large.abst closer to loading

This commit is contained in:
Dustin Carlino 2018-09-08 15:35:30 -07:00
parent dc4806bbcc
commit f386278343
3 changed files with 39 additions and 1 deletions

View File

@ -24,8 +24,9 @@ pub use polyline::PolyLine;
pub use pt::{HashablePt2D, Pt2D}; pub use pt::{HashablePt2D, Pt2D};
use std::marker; use std::marker;
// About .0 inches... which is quite tiny on the scale of things. :)
pub const EPSILON_DIST: si::Meter<f64> = si::Meter { pub const EPSILON_DIST: si::Meter<f64> = si::Meter {
value_unsafe: 0.00001, value_unsafe: 0.01,
_marker: marker::PhantomData, _marker: marker::PhantomData,
}; };

View File

@ -1,4 +1,5 @@
use dimensioned::si; use dimensioned::si;
use std::fmt;
use {line_intersection, Angle, Pt2D, EPSILON_DIST}; use {line_intersection, Angle, Pt2D, EPSILON_DIST};
// Segment, technically // Segment, technically
@ -141,6 +142,15 @@ impl Line {
} }
} }
impl fmt::Display for Line {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Line::new(\n")?;
write!(f, " Pt2D::new({}, {}),\n", self.0.x(), self.0.y())?;
write!(f, " Pt2D::new({}, {}),\n", self.1.x(), self.1.y())?;
write!(f, ")")
}
}
fn is_counter_clockwise(pt1: Pt2D, pt2: Pt2D, pt3: Pt2D) -> bool { fn is_counter_clockwise(pt1: Pt2D, pt2: Pt2D, pt3: Pt2D) -> bool {
(pt3.y() - pt1.y()) * (pt2.x() - pt1.x()) > (pt2.y() - pt1.y()) * (pt3.x() - pt1.x()) (pt3.y() - pt1.y()) * (pt2.x() - pt1.x()) > (pt2.y() - pt1.y()) * (pt3.x() - pt1.x())
} }

View File

@ -373,4 +373,31 @@ fn shift_short_polyline_equivalence() {
); );
} }
#[test]
fn trim_with_epsilon() {
/*
// EPSILON_DIST needs to be tuned correctly, or this point seems like it's not on the line.
let mut pl = PolyLine::new(vec![
Pt2D::new(1130.2653468611902, 2124.099702776818),
Pt2D::new(1175.9652436108408, 2124.1094748373457),
Pt2D::new(1225.8319649025132, 2124.120594334445),
]);
let pt = Pt2D::new(1225.8319721124885, 2124.1205943360505);*/
let mut pl = PolyLine::new(vec![
Pt2D::new(1725.295220788561, 1414.2752785686052),
Pt2D::new(1724.6291929910137, 1414.8246144364846),
Pt2D::new(1723.888820814687, 1415.6240169312443),
Pt2D::new(1723.276510998312, 1416.4750455089877),
Pt2D::new(1722.7586731922217, 1417.4015448461048),
Pt2D::new(1722.353627188061, 1418.4238284182732),
Pt2D::new(1722.086748762076, 1419.4737997607863),
Pt2D::new(1721.9540106814163, 1420.5379609077854),
Pt2D::new(1721.954010681534, 1421.1267599802409),
]);
let pt = Pt2D::new(1721.9540106813197, 1420.2372293808348);
pl.trim_to_pt(pt);
}
// TODO test that shifting lines and polylines is a reversible operation // TODO test that shifting lines and polylines is a reversible operation