From f3c2308dfccd0d09768510d959a424e28c04e3d1 Mon Sep 17 00:00:00 2001 From: Doug Lau Date: Tue, 29 Sep 2020 12:19:48 -0500 Subject: [PATCH] Use Line32.intersection from pointy crate --- src/geom.rs | 22 ---------------------- src/stroker.rs | 8 +++++--- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/geom.rs b/src/geom.rs index c02f960..479feb1 100644 --- a/src/geom.rs +++ b/src/geom.rs @@ -15,28 +15,6 @@ pub fn float_lerp(a: f32, b: f32, t: f32) -> f32 { b + (a - b) * t } -/// Calculate intersection point of two lines. -/// -/// * `a0` First point on line a. -/// * `a1` Second point on line a. -/// * `b0` First point on line b. -/// * `b1` Second point on line b. -/// Returns None if the lines are colinear. -pub fn intersection(a0: Pt32, a1: Pt32, b0: Pt32, b1: Pt32) -> Option { - let av = a0 - a1; - let bv = b0 - b1; - let den = av * bv; - if den != 0.0 { - let ca = a0 * a1; - let cb = b0 * b1; - let xn = bv.x() * ca - av.x() * cb; - let yn = bv.y() * ca - av.y() * cb; - Some(Pt32(xn / den, yn / den)) - } else { - None - } -} - impl Default for WidePt { fn default() -> Self { WidePt(Pt32::default(), 1.0) diff --git a/src/stroker.rs b/src/stroker.rs index da2834a..1990f34 100644 --- a/src/stroker.rs +++ b/src/stroker.rs @@ -2,10 +2,10 @@ // // Copyright (c) 2017-2020 Douglas P Lau // -use crate::geom::{intersection, WidePt}; +use crate::geom::WidePt; use crate::path::PathOp; use crate::vid::Vid; -use pointy::Pt32; +use pointy::{Line32, Pt32}; use std::fmt; /// Style for stroke joins. @@ -354,8 +354,10 @@ impl Stroke { let th = (a1 - a0).angle_rel(b0 - b1); let sm = (th / 2.0).sin().abs(); if sm >= sm_min && sm < 1.0 { + let lna = Line32::new(a0, a1); + let lnb = Line32::new(b0, b1); // Calculate miter point - if let Some(xp) = intersection(a0, a1, b0, b1) { + if let Some(xp) = lna.intersection(lnb) { self.stroke_point(ops, xp); return; }