Write in the line segment intersection code in matrix form
This commit is contained in:
parent
c6fc853579
commit
197f01d56a
|
@ -11,6 +11,7 @@
|
||||||
//! Line segment types, optimized with SIMD.
|
//! Line segment types, optimized with SIMD.
|
||||||
|
|
||||||
use crate::basic::point::Point2DF32;
|
use crate::basic::point::Point2DF32;
|
||||||
|
use crate::basic::transform2d::Matrix2x2F32;
|
||||||
use crate::util;
|
use crate::util;
|
||||||
use pathfinder_simd::default::F32x4;
|
use pathfinder_simd::default::F32x4;
|
||||||
use std::ops::{Add, Sub};
|
use std::ops::{Add, Sub};
|
||||||
|
@ -227,15 +228,12 @@ impl LineSegmentF32 {
|
||||||
|
|
||||||
// http://www.cs.swan.ac.uk/~cssimon/line_intersection.html
|
// http://www.cs.swan.ac.uk/~cssimon/line_intersection.html
|
||||||
pub fn intersection_t(&self, other: &LineSegmentF32) -> Option<f32> {
|
pub fn intersection_t(&self, other: &LineSegmentF32) -> Option<f32> {
|
||||||
let d0d1 = self.vector().0.concat_xy_xy(other.vector().0);
|
let p0p1 = self.vector();
|
||||||
let offset = other.from() - self.from();
|
let matrix = Matrix2x2F32(other.vector().0.concat_xy_xy((-p0p1).0));
|
||||||
let factors = d0d1.concat_wz_yx(offset.0);
|
if f32::abs(matrix.det()) < EPSILON {
|
||||||
let terms = d0d1 * factors;
|
|
||||||
let denom = terms[0] - terms[1];
|
|
||||||
if f32::abs(denom) < EPSILON {
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
return Some((terms[3] - terms[2]) / denom);
|
return Some(matrix.inverse().transform_point(self.from() - other.from()).y());
|
||||||
|
|
||||||
const EPSILON: f32 = 0.0001;
|
const EPSILON: f32 = 0.0001;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue