Skip to content

Commit

Permalink
Fix orientation of boolops geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Jan 30, 2025
1 parent ef55eab commit 59438c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
println!("{}", errors[0]);
```
- BREAKING: update proj to 0.28.0
- Polygons returned by Boolean Ops are now oriented correctly (ccw shell, cw inner rings)

## 0.29.3 - 2024.12.03

Expand Down
7 changes: 5 additions & 2 deletions geo/src/algorithm/bool_ops/i_overlay_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub(super) mod convert {
use super::BoolOpsNum;
use crate::bool_ops::i_overlay_integration::BoolOpsCoord;
use crate::geometry::{LineString, MultiLineString, MultiPolygon, Polygon};
use crate::orient::Direction;
use crate::Orient;
use i_overlay::core::overlay_rule::OverlayRule;

pub fn line_string_from_path<T: BoolOpsNum>(path: Vec<BoolOpsCoord<T>>) -> LineString<T> {
Expand All @@ -48,7 +50,7 @@ pub(super) mod convert {
pub fn polygon_from_shape<T: BoolOpsNum>(shape: Vec<Vec<BoolOpsCoord<T>>>) -> Polygon<T> {
let mut rings = shape.into_iter().map(|p| line_string_from_path(p));
let exterior = rings.next().unwrap_or(LineString::new(vec![]));
Polygon::new(exterior, rings.collect())
Polygon::new(exterior, rings.collect()).orient(Direction::Default)
}

pub fn multi_polygon_from_shapes<T: BoolOpsNum>(
Expand Down Expand Up @@ -96,7 +98,8 @@ mod tests {

#[test]
fn one_empty_polygon() {
let p1: Polygon = wkt!(POLYGON((0. 0., 0. 1., 1. 1., 1. 0., 0. 0.)));
// let p1: Polygon = wkt!(POLYGON((0. 0., 0. 1., 1. 1., 1. 0., 0. 0.)));
let p1: Polygon = wkt!(POLYGON((0.0 0.0,1.0 0.0,1.0 1.0,0.0 1.0,0.0 0.0)));
let p2: Polygon = wkt!(POLYGON EMPTY);
assert_eq!(&p1.union(&p2), &MultiPolygon(vec![p1.clone()]));
assert_eq!(&p1.intersection(&p2), &wkt!(MULTIPOLYGON EMPTY));
Expand Down
4 changes: 2 additions & 2 deletions geo/src/algorithm/bool_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ pub enum OpType {
///
/// let expected_output = wkt!(MULTIPOLYGON(
/// // left and right piece have been combined
/// ((0. 0., 0. 4., 8. 4., 8. 0., 0. 0.)),
/// ((0.0 0.0, 8.0 0.0, 8.0 4.0, 0.0 4.0, 0.0 0.0)),
/// // separate piece remains separate
/// ((14. 10., 14. 14., 18. 14.,18. 10., 14. 10.))
/// ((14.0 10.0, 18.0 10.0, 18.0 14.0, 14.0 14.0, 14.0 10.0))
/// ));
/// assert_eq!(actual_output, expected_output);
/// ```
Expand Down
6 changes: 3 additions & 3 deletions geo/src/algorithm/bool_ops/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@ mod gh_issues {
let expected_c = wkt!(MULTIPOLYGON(
((
-22.058823 - 3.623188,
-19.458324 - 3.623188,
-19.064932 - 6.57369,
-19.458324 - 3.623188,
-22.058823 - 3.623188
)),
((
-17.60358 - 8.013862,
-14.705883 - 7.649791,
-14.705883 - 7.6497912,
-17.60358 - 8.013863,
-14.705883 - 7.6497912,
-14.705883 - 7.649791,
-17.60358 - 8.013862
))
));
Expand Down

0 comments on commit 59438c1

Please sign in to comment.