georust / geo

Geospatial primitives and algorithms for Rust
https://crates.io/crates/geo
Other
1.54k stars 197 forks source link

Vector2DOps Trait - Proposal #1025

Closed thehappycheese closed 1 year ago

thehappycheese commented 1 year ago

Proposal to define Vector2DOps trait and implement it for the Coord struct. Intention is to facilitate general purpose linear algebra operations such as 'dot product' etc all in one place.

Most of these functions are are already implemented in various places throughout the crate or sometimes hard-coded in place. This would bring them all together.

For example

For more discussion about motivation for this proposal, see this comment on PR #935 .

Possibly the timing of this proposal is weird, I am sure that the geotraits::CoordTrait will affect how this should be implemented. I suspect it may allow the Vector2DOps to define default implementations?

Note:

Many thanks for your time and any feedback you can provide

kylebarron commented 1 year ago

Possibly the timing of this proposal is weird, I am sure that the geotraits::CoordTrait will affect how this should be implemented.

I think coordinate traits will take a while to get stabilized, so I wouldn't put too much thought in that work for your PR

michaelkirk commented 1 year ago

bors r+

bors[bot] commented 1 year ago

Build failed:

michaelkirk commented 1 year ago

Can you please run cargo fmt and push back up? It doesn't like your CRLF line terminators and a couple other things.

thehappycheese commented 1 year ago

Can you please run cargo fmt and push back up? It doesn't like your CRLF line terminators and a couple other things.

Hi @michaelkirk, appologies for that, I ran cargo fmt again and I think it is fixed now in 12155aa

I'm pretty sure it has been committed using LF and not CRLF. The git docs say 'You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input' so i have done that. I am surprised github has no built-in way to verify if it worked.

urschrei commented 1 year ago

Bors try

bors[bot] commented 1 year ago

try

Build failed:

urschrei commented 1 year ago

This is a spurious Clippy lint failure imo, because the suggested change:

--- a/geo/src/algorithm/vector_ops.rs
+++ b/geo/src/algorithm/vector_ops.rs
@@ -111,7 +111,7 @@ where
     fn try_normalize(self) -> Option<Self>;

     /// Returns true if both the x and y components are finite
-    fn is_finite(self) -> bool;
+    fn is_finite(&self) -> bool;
 }

 impl<T> Vector2DOps for Coord<T>
@@ -165,7 +165,7 @@ where
         }
     }

-    fn is_finite(self) -> bool {
+    fn is_finite(self: &geo_types::Coord<T>) -> bool {
         self.x.is_finite() && self.y.is_finite()
     }
 }

Introduces an unnecessary borrow of Coord (a Copy type).

If you annotate the trait fn instead:

--- a/geo/src/algorithm/vector_ops.rs
+++ b/geo/src/algorithm/vector_ops.rs
@@ -111,6 +111,7 @@ where
     fn try_normalize(self) -> Option<Self>;

     /// Returns true if both the x and y components are finite
+    #[allow(clippy::wrong_self_convention)]
     fn is_finite(self) -> bool;
 }

All should be well.

urschrei commented 1 year ago

bors try

bors[bot] commented 1 year ago

try

Build failed:

thehappycheese commented 1 year ago

I am confused... There should be a 12th commit where I added the annotation, but it is not showing up in this PR. Is it because it happened while bors was doing something?

urschrei commented 1 year ago

I'm confused too. I don't think it was bors, and it's…somewhere:

https://github.com/georust/geo/commit/006a48c1be8430a74ad916674790cb9cc8ae2f1d

urschrei commented 1 year ago

Can you pull your remote branch and then push again, just to be sure? I can see the commit on your remote, but it's now not in the PR for some reason.

thehappycheese commented 1 year ago

I cant find a way to trigger it manually. I tried the open pull request button but it just navigates to this existing PR. I can try commit some minor change to a comment or something and see if that triggers it to get included? Maybe I need to rebase it or something? It still says it can be merged tho.

urschrei commented 1 year ago

Yeah, try an inconsequential commit.

thehappycheese commented 1 year ago

Ah I clicked "Sync Fork" and that created a 13th commit... so far that hasn't been needed. I wonder why it was needed this time

urschrei commented 1 year ago

bors r=michaelkirk

bors[bot] commented 1 year ago

Build failed:

urschrei commented 1 year ago

Now it's timing out. This is hilarious.

urschrei commented 1 year ago

bors retry

bors[bot] commented 1 year ago

This PR was included in a batch that successfully built, but then failed to merge into main. It will not be retried.

Additional information:

Response status code: 422
{"message":"Changes must be made through the merge queue","documentation_url":"https://docs.github.com/articles/about-protected-branches"}
urschrei commented 1 year ago

I though we turned off the merge queue, but apparently not, and it's now conflicting with bors. The PR passes so I'm merging using the queue, then going for a little walk.

thehappycheese commented 1 year ago

Hooray, thanks for all the help to get it merged, I'm looking forward to working on the next part of the other offset curve PR 😄

michaelkirk commented 1 year ago

I hadn't turned it off - I just never got it to work.

I did, just now, turn it off though. For the record it's under Settings > Branches (branch protection rules) > Edit

Screenshot 2023-07-31 at 10 57 11