Skip to content

replace relate-based contains_properly for Line#1495

Draft
cookiedan42 wants to merge 1 commit intogeorust:mainfrom
cookiedan42:contains_properly_line
Draft

replace relate-based contains_properly for Line#1495
cookiedan42 wants to merge 1 commit intogeorust:mainfrom
cookiedan42:contains_properly_line

Conversation

@cookiedan42
Copy link
Copy Markdown
Contributor

So this is definitely faster than the current Relate-derive baseline, but its Line.contains_properly(Point) is also slightly faster than the existing Line.contains(Point), which have the same result. (pt intersect boundary == pt in boundary)

This speedup comes from doing a little less work than running Line.intersects(Point) N times by extracting the repeated bound ordering checks from the loop

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

small bench speedups

multipoint/contains multipoint (Trait)
                        time:   [1.5456 µs 1.5501 µs 1.5550 µs]
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe
multipoint/contains_properly multipoint (Trait)
                        time:   [1.4951 µs 1.4990 µs 1.5032 µs]
Found 7 outliers among 100 measurements (7.00%)
  2 (2.00%) low mild
  3 (3.00%) high mild
  2 (2.00%) high severe



mid/contains pt (Trait)
                        time:   [7.2867 ns 7.2974 ns 7.3088 ns]
Found 9 outliers among 100 measurements (9.00%)
  4 (4.00%) low severe
  4 (4.00%) low mild
  1 (1.00%) high severe
mid/contains_properly pt (Trait)
                        time:   [6.8381 ns 6.8494 ns 6.8602 ns]
Found 9 outliers among 100 measurements (9.00%)
  2 (2.00%) low severe
  5 (5.00%) low mild
  1 (1.00%) high mild
  1 (1.00%) high severe



end/contains pt (Trait)
                        time:   [7.3035 ns 7.3240 ns 7.3553 ns]
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low severe
  4 (4.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe
end/contains_properly pt (Trait)
                        time:   [6.8105 ns 6.8280 ns 6.8476 ns]
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low severe
  2 (2.00%) low mild
  3 (3.00%) high mild
  1 (1.00%) high severe

@cookiedan42
Copy link
Copy Markdown
Contributor Author

This orient optimization could also be applied to Line.covers(), which currently uses repeated intersects

Copy link
Copy Markdown
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good, but we should have some tests for this functionality. It was arguably less important before, when we were delegating to Relate which has some existing coverage.

};

rhs.coords_iter().all(|c| {
value_in_range_exclusive(c.x, x_bound.0, x_bound.1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any tests for line.contains_properly — that was my mistake from the original PR review. Can you add some now?

use impl_contains_properly_geometry_for;

// Helper function to check value lies between min and max.
// Only makes sense if min <= max (or always false)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a debug_assert to enforce a calling contract.

@cookiedan42 cookiedan42 marked this pull request as draft February 11, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants