georust / geo

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

WIP Implement area functions on geometry traits #1021

Closed kylebarron closed 5 months ago

kylebarron commented 1 year ago

Change list

Questions:

frewsxcv commented 1 year ago

Is there a simple way with lifetimes to fix this temporary value dropped while borrowed error? It's on this line. I'm not sure if this is an issue with the trait design or implementation or with my code

When I run into situations like this, I typically start incrementally loosening lifetime bounds that don't need to be explicitly specified. With these changes, your code compiles: https://gist.github.com/frewsxcv/75e719227b889ee2930ccb59930b26de

kylebarron commented 1 year ago

When I run into situations like this, I typically start incrementally loosening lifetime bounds that don't need to be explicitly specified. With these changes, your code compiles: gist.github.com/frewsxcv/75e719227b889ee2930ccb59930b26de

Thanks! That was helpful! I was able to make some progress. But it seems like the trait methods that really need &'a self are the iterators.

So I can make progress by removing 'a everywhere but that forces me to write ugly code and avoid using the iterators, doing stuff like

for polygon_idx in 0..geom.num_polygons() {

Especially with the GeometryCollection and Geometry traits, it gets complex and it's not clear to me we can fully remove the lifetimes.

I tried to implement unsigned_area_geometry which takes anything that implements GeometryTrait, but there as_type requires 'a.

frewsxcv commented 5 months ago

From what I understand, https://github.com/georust/geo/pull/1115 is a newer version of this so I'm going to close this one. Feel free to reopen if this is wrong