Skip to content

Commit

Permalink
Offset trait testing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
thehappycheese committed Nov 18, 2022
1 parent 47c5a6a commit 6bb1c75
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions geo/src/algorithm/offset/line_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<T>(
a: &Coord<T>,
b: &Coord<T>,
Expand Down
33 changes: 28 additions & 5 deletions geo/src/algorithm/offset/offset_trait.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::line_intersection::FalseIntersectionPointType::AfterEnd;
use super::line_intersection::FalseIntersectionPointType::{
BeforeStart,
AfterEnd,
};
use super::line_intersection::LineSegmentIntersectionType::{
FalseIntersectionPoint, TrueIntersectionPoint,
};
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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<T> Offset<T> for LineString<T>
where
T: CoordFloat,
Expand All @@ -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;

Expand All @@ -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]
},

Expand Down
6 changes: 3 additions & 3 deletions rfcs/2022-11-11-offset.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 6bb1c75

Please sign in to comment.