diff --git a/geo/src/algorithm/offset/line_intersection.rs b/geo/src/algorithm/offset/line_intersection.rs index e91d06d6f..9ffe66453 100644 --- a/geo/src/algorithm/offset/line_intersection.rs +++ b/geo/src/algorithm/offset/line_intersection.rs @@ -8,6 +8,8 @@ pub(super) enum FalseIntersectionPointType { /// ray defined by the line segment, but before the start of the line segment. /// /// Abbreviated to `NFIP` in original paper (Negative) + /// (also referred to as `FFIP` in Figure 6, but i think this is an + /// error?) BeforeStart, /// The intersection point is 'false' or 'virtual': it lies on the infinite /// ray defined by the line segment, but after the end of the line segment. @@ -172,6 +174,8 @@ where } } +/// Return the intersection point as well as the relationship between the point +/// and each of the input line segments. See [LineSegmentIntersectionType] pub(super) fn line_segment_intersection_with_relationships( a: &Coord, b: &Coord, diff --git a/geo/src/algorithm/offset/offset_trait.rs b/geo/src/algorithm/offset/offset_trait.rs index 670f6b423..e11431dc0 100644 --- a/geo/src/algorithm/offset/offset_trait.rs +++ b/geo/src/algorithm/offset/offset_trait.rs @@ -1,4 +1,7 @@ -use super::line_intersection::FalseIntersectionPointType::AfterEnd; +use super::line_intersection::FalseIntersectionPointType::{ + BeforeStart, + AfterEnd, +}; use super::line_intersection::LineSegmentIntersectionType::{ FalseIntersectionPoint, TrueIntersectionPoint, }; @@ -51,7 +54,9 @@ where /// negative. /// /// Negative `distance` values will offset the edges of the geometry to the - /// left, when facing the direction of increasing coordinate index. + /// left, when facing the direction of increasing coordinate index. For a + /// polygon with clockwise winding order, a positive 'offset' corresponds with + /// an 'inset'. /// /// ``` /// #use crate::{line_string, Coord}; @@ -86,6 +91,13 @@ where } } + +/// # Offset for LineString +/// ## Algorithm +/// Loosely follows the algorithm described by +/// [Xu-Zheng Liu, Jun-Hai Yong, Guo-Qin Zheng, Jia-Guang Sun. An offset algorithm for polyline curves. Computers in Industry, Elsevier, 2007, 15p. inria-00518005] +/// (https://hal.inria.fr/inria-00518005/document) +/// This was the first google result for 'line offset algorithm' impl Offset for LineString where T: CoordFloat, @@ -102,6 +114,7 @@ where if offset_segments.len() == 1 { return offset_segments[0].into(); } + // First and last will always work: let first_point = offset_segments.first().unwrap().start; let last_point = offset_segments.last().unwrap().end; @@ -127,13 +140,23 @@ where //println!("CASE 1 - extend"); vec![intersection] }, - (FalseIntersectionPoint(AfterEnd), FalseIntersectionPoint(_)) => { + + (TrueIntersectionPoint, FalseIntersectionPoint(_)) => { + //println!("CASE 1 - extend"); + vec![intersection] + }, + (FalseIntersectionPoint(_), TrueIntersectionPoint) => { + //println!("CASE 1 - extend"); + vec![intersection] + }, + (FalseIntersectionPoint(BeforeStart), FalseIntersectionPoint(_)) => { // TODO: Mitre limit logic goes here //println!("CASE 2 - extend"); vec![intersection] - } + }, _ => { - println!("CASE 3 - bridge"); + //println!("CASE 3 - bridge"); + //vec![intersection] vec![*b, *c] }, diff --git a/rfcs/2022-11-11-offset.md b/rfcs/2022-11-11-offset.md index 4c302467f..3696237d3 100644 --- a/rfcs/2022-11-11-offset.md +++ b/rfcs/2022-11-11-offset.md @@ -23,7 +23,7 @@ Priority for implementing the trait is as follows: - [ ] If some of the limitations discussed below can be addressed - [ ] `Polygon` - [ ] `MultiPolygon` - - [ ] `Geometry` & `GeometryCollection` + - [ ] `Geometry` & `GeometryCollection ## Limitations @@ -44,11 +44,11 @@ and potentially a better algorithm is needed: ### References -Loosely follows the algorithim described by +Loosely follows the algorithm described by [Xu-Zheng Liu, Jun-Hai Yong, Guo-Qin Zheng, Jia-Guang Sun. An offset algorithm for polyline curves. Computers in Industry, Elsevier, 2007, 15p. inria-00518005](https://hal.inria.fr/inria-00518005/document) This was the first google result for 'line offset algorithm' -### Definitions (For the psudocode in this readme only) +### Definitions (For the psudo-code in this readme only) Type definitions ```python