Skip to content

Commit 6bb1c75

Browse files
Offset trait testing improvements
1 parent 47c5a6a commit 6bb1c75

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

geo/src/algorithm/offset/line_intersection.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub(super) enum FalseIntersectionPointType {
88
/// ray defined by the line segment, but before the start of the line segment.
99
///
1010
/// Abbreviated to `NFIP` in original paper (Negative)
11+
/// (also referred to as `FFIP` in Figure 6, but i think this is an
12+
/// error?)
1113
BeforeStart,
1214
/// The intersection point is 'false' or 'virtual': it lies on the infinite
1315
/// ray defined by the line segment, but after the end of the line segment.
@@ -172,6 +174,8 @@ where
172174
}
173175
}
174176

177+
/// Return the intersection point as well as the relationship between the point
178+
/// and each of the input line segments. See [LineSegmentIntersectionType]
175179
pub(super) fn line_segment_intersection_with_relationships<T>(
176180
a: &Coord<T>,
177181
b: &Coord<T>,

geo/src/algorithm/offset/offset_trait.rs

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use super::line_intersection::FalseIntersectionPointType::AfterEnd;
1+
use super::line_intersection::FalseIntersectionPointType::{
2+
BeforeStart,
3+
AfterEnd,
4+
};
25
use super::line_intersection::LineSegmentIntersectionType::{
36
FalseIntersectionPoint, TrueIntersectionPoint,
47
};
@@ -51,7 +54,9 @@ where
5154
/// negative.
5255
///
5356
/// Negative `distance` values will offset the edges of the geometry to the
54-
/// left, when facing the direction of increasing coordinate index.
57+
/// left, when facing the direction of increasing coordinate index. For a
58+
/// polygon with clockwise winding order, a positive 'offset' corresponds with
59+
/// an 'inset'.
5560
///
5661
/// ```
5762
/// #use crate::{line_string, Coord};
@@ -86,6 +91,13 @@ where
8691
}
8792
}
8893

94+
95+
/// # Offset for LineString
96+
/// ## Algorithm
97+
/// Loosely follows the algorithm described by
98+
/// [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]
99+
/// (https://hal.inria.fr/inria-00518005/document)
100+
/// This was the first google result for 'line offset algorithm'
89101
impl<T> Offset<T> for LineString<T>
90102
where
91103
T: CoordFloat,
@@ -102,6 +114,7 @@ where
102114
if offset_segments.len() == 1 {
103115
return offset_segments[0].into();
104116
}
117+
// First and last will always work:
105118
let first_point = offset_segments.first().unwrap().start;
106119
let last_point = offset_segments.last().unwrap().end;
107120

@@ -127,13 +140,23 @@ where
127140
//println!("CASE 1 - extend");
128141
vec![intersection]
129142
},
130-
(FalseIntersectionPoint(AfterEnd), FalseIntersectionPoint(_)) => {
143+
144+
(TrueIntersectionPoint, FalseIntersectionPoint(_)) => {
145+
//println!("CASE 1 - extend");
146+
vec![intersection]
147+
},
148+
(FalseIntersectionPoint(_), TrueIntersectionPoint) => {
149+
//println!("CASE 1 - extend");
150+
vec![intersection]
151+
},
152+
(FalseIntersectionPoint(BeforeStart), FalseIntersectionPoint(_)) => {
131153
// TODO: Mitre limit logic goes here
132154
//println!("CASE 2 - extend");
133155
vec![intersection]
134-
}
156+
},
135157
_ => {
136-
println!("CASE 3 - bridge");
158+
//println!("CASE 3 - bridge");
159+
//vec![intersection]
137160
vec![*b, *c]
138161
},
139162

rfcs/2022-11-11-offset.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Priority for implementing the trait is as follows:
2323
- [ ] If some of the limitations discussed below can be addressed
2424
- [ ] `Polygon`
2525
- [ ] `MultiPolygon`
26-
- [ ] `Geometry` & `GeometryCollection`
26+
- [ ] `Geometry` & `GeometryCollection
2727

2828
## Limitations
2929

@@ -44,11 +44,11 @@ and potentially a better algorithm is needed:
4444

4545
### References
4646

47-
Loosely follows the algorithim described by
47+
Loosely follows the algorithm described by
4848
[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)
4949
This was the first google result for 'line offset algorithm'
5050

51-
### Definitions (For the psudocode in this readme only)
51+
### Definitions (For the psudo-code in this readme only)
5252

5353
Type definitions
5454
```python

0 commit comments

Comments
 (0)