-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
From GeoZero (reverse conversion) #4
Conversation
WalkthroughThe updates introduce several improvements and new features. The Changes
Assessment against linked issues
Poem
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
==========================================
+ Coverage 93.92% 96.87% +2.94%
==========================================
Files 7 9 +2
Lines 1349 1566 +217
==========================================
+ Hits 1267 1517 +250
+ Misses 82 49 -33 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 19
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- src/geometry/linestring.rs (1 hunks)
- src/geometry/mod.rs (2 hunks)
- src/geometry/multi_point.rs (1 hunks)
- src/geozero/mod.rs (1 hunks)
- src/geozero/reader.rs (2 hunks)
- src/geozero/writer.rs (1 hunks)
- src/lib.rs (1 hunks)
- tests/geozero.rs (2 hunks)
Files skipped from review due to trivial changes (1)
- src/lib.rs
Additional context used
GitHub Check: codecov/patch
src/geozero/writer.rs
[warning] 18-18: src/geozero/writer.rs#L18
Added line #L18 was not covered by tests
[warning] 30-30: src/geozero/writer.rs#L30
Added line #L30 was not covered by tests
[warning] 32-32: src/geozero/writer.rs#L32
Added line #L32 was not covered by tests
[warning] 38-40: src/geozero/writer.rs#L38-L40
Added lines #L38 - L40 were not covered by tests
[warning] 46-48: src/geozero/writer.rs#L46-L48
Added lines #L46 - L48 were not covered by tests
[warning] 70-70: src/geozero/writer.rs#L70
Added line #L70 was not covered by tests
[warning] 72-72: src/geozero/writer.rs#L72
Added line #L72 was not covered by tests
[warning] 78-78: src/geozero/writer.rs#L78
Added line #L78 was not covered by tests
[warning] 98-118: src/geozero/writer.rs#L98-L118
Added lines #L98 - L118 were not covered by tests
[warning] 120-123: src/geozero/writer.rs#L120-L123
Added lines #L120 - L123 were not covered by tests
[warning] 125-128: src/geozero/writer.rs#L125-L128
Added lines #L125 - L128 were not covered by testssrc/geozero/reader.rs
[warning] 7-8: src/geozero/reader.rs#L7-L8
Added lines #L7 - L8 were not covered by tests
[warning] 11-20: src/geozero/reader.rs#L11-L20
Added lines #L11 - L20 were not covered by tests
[warning] 22-23: src/geozero/reader.rs#L22-L23
Added lines #L22 - L23 were not covered by tests
[warning] 25-29: src/geozero/reader.rs#L25-L29
Added lines #L25 - L29 were not covered by tests
[warning] 50-58: src/geozero/reader.rs#L50-L58
Added lines #L50 - L58 were not covered by tests
[warning] 84-92: src/geozero/reader.rs#L84-L92
Added lines #L84 - L92 were not covered by tests
[warning] 120-128: src/geozero/reader.rs#L120-L128
Added lines #L120 - L128 were not covered by tests
[warning] 158-166: src/geozero/reader.rs#L158-L166
Added lines #L158 - L166 were not covered by tests
[warning] 198-206: src/geozero/reader.rs#L198-L206
Added lines #L198 - L206 were not covered by tests
Additional comments not posted (19)
src/geozero/mod.rs (3)
1-2
: LGTM! Modules made public.The
reader
andwriter
modules are correctly made public to enable interoperability.
8-10
: LGTM! New traitToFlatgeom
introduced.The
ToFlatgeom
trait is appropriately introduced to facilitate the conversion of geometries to a flat representation.
12-20
: LGTM! Implementation ofToFlatgeom
forGeozeroGeometry
.The implementation processes the geometry using
FlatgeomWriter
and handles errors appropriately.src/geometry/mod.rs (1)
60-60
: LGTM! NewGeometryCollection
variant added.The addition of the
GeometryCollection
variant to theGeometry
enum allows handling collections of geometries.tests/geozero.rs (6)
4-7
: LGTM! Import statements updated.The import statements are correctly updated to include
ToFlatgeom
and various geometry types.
Line range hint
12-53
:
LGTM! New test forMultiPolygon2
added.The test correctly verifies the conversion to
geo_types::Geometry::MultiPolygon
and inversion toflatgeom::Geometry::MultiPolygon
.
58-85
: LGTM! New test forPolygon2
added.The test correctly verifies the conversion to
geo_types::Geometry::Polygon
and inversion toflatgeom::Geometry::Polygon
.
89-116
: LGTM! New test forMultiLineString2
added.The test correctly verifies the conversion to
geo_types::Geometry::MultiLineString
and inversion toflatgeom::Geometry::MultiLineString
.
120-143
: LGTM! New test forLineString2
added.The test correctly verifies the conversion to
geo_types::Geometry::LineString
and inversion toflatgeom::Geometry::LineString
.
146-170
: LGTM! New test forMultiPoint2
added.The test correctly verifies the conversion to
geo_types::Geometry::MultiPoint
and inversion toflatgeom::Geometry::MultiPoint
.src/geometry/multi_point.rs (1)
72-75
: LGTM! Newextend
method added.The
extend
method allows extending theMultiPoint
with additional coordinates, enhancing its functionality.src/geozero/writer.rs (8)
8-13
: Ensure all fields are necessary and correctly initialized.The
FlatgeomWriter
struct includes fields for geometries, collections, current geometry, and coordinates. Verify that all fields are necessary and correctly initialized.
20-25
: Ensure the default capacity is appropriate.The
Vec::with_capacity(1)
calls initialize the vectors with a capacity of 1. Verify that this is appropriate for expected use cases.
44-52
: Ensurestart_geometry
handles all geometry types correctly.The
start_geometry
method initializes a geometry or a collection. Verify that all geometry types are handled correctly.Tools
GitHub Check: codecov/patch
[warning] 46-48: src/geozero/writer.rs#L46-L48
Added lines #L46 - L48 were not covered by tests
147-152
: Ensurepolygon_begin
andpolygon_end
handle polygons correctly.The
polygon_begin
andpolygon_end
methods handle the beginning and end of a polygon geometry. Verify that polygons are handled correctly and that test coverage is adequate.Also applies to: 178-183
76-81
: Ensurefinish_geometry
handles nested collections correctly.The
finish_geometry
method finalizes a geometry, including nested collections. Verify that nested collections are handled correctly and that test coverage is adequate.Tools
GitHub Check: codecov/patch
[warning] 78-78: src/geozero/writer.rs#L78
Added line #L78 was not covered by tests
55-74
: Ensurefinish_coords
handles all geometry types correctly.The
finish_coords
method processes coordinates for various geometry types. Verify that all geometry types are handled correctly and that test coverage is adequate.Verification successful
Verified:
finish_coords
handles all geometry types correctly and test coverage is adequate.The
finish_coords
method processes coordinates for various geometry types, and the test functions across thetests/geozero.rs
,tests/serde.rs
, andsrc/geometry/
files involve these geometry types, ensuring indirect coverage.
tests/geozero.rs
: Functionsmultipolygon
,polygon
,multilinestring
,linestring
,multipoint
.tests/serde.rs
: Functiontest_serde_serialize_deserialize
.src/geometry/
: Various test functions inmulti_point.rs
,linestring.rs
,polygon.rs
,multi_polygon.rs
,multi_linestring.rs
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify test coverage for `finish_coords`. # Test: Ensure there are tests for `finish_coords`. rg --type rust 'finish_coords' tests/Length of output: 37
Script:
#!/bin/bash # Search for references to `finish_coords` in the entire codebase. rg 'finish_coords' # Search for test functions that might indirectly test `finish_coords`. rg '#\[test\]' --type rustLength of output: 2082
Script:
#!/bin/bash # Search for references to `finish_coords` and geometries it handles within test functions. rg 'finish_coords' tests/ src/geometry/ rg 'MultiPoint' tests/ src/geometry/ rg 'LineString' tests/ src/geometry/ rg 'MultiLineString' tests/ src/geometry/ rg 'Polygon' tests/ src/geometry/ rg 'MultiPolygon' tests/ src/geometry/Length of output: 23102
Script:
#!/bin/bash # Inspect test functions in the identified files for references to geometries handled by `finish_coords`. # List all test functions in `tests/geozero.rs`. rg '#\[test\]' -A 2 tests/geozero.rs # List all test functions in `tests/serde.rs`. rg '#\[test\]' -A 2 tests/serde.rs # List all test functions in `src/geometry/`. rg '#\[test\]' -A 2 src/geometry/Length of output: 7961
Tools
GitHub Check: codecov/patch
[warning] 70-70: src/geozero/writer.rs#L70
Added line #L70 was not covered by tests
[warning] 72-72: src/geozero/writer.rs#L72
Added line #L72 was not covered by tests
142-145
: Ensuremultilinestring_begin
andmultilinestring_end
handle multilinestrings correctly.The
multilinestring_begin
andmultilinestring_end
methods handle the beginning and end of a multilinestring geometry. Verify that multilinestrings are handled correctly and that test coverage is adequate.Also applies to: 173-176
154-157
: Ensuremultipolygon_begin
andmultipolygon_end
handle multipolygons correctly.The
multipolygon_begin
andmultipolygon_end
methods handle the beginning and end of a multipolygon geometry. Verify that multipolygons are handled correctly and that test coverage is adequate.Also applies to: 185-188
Verification successful
Ensure
multipolygon_begin
andmultipolygon_end
handle multipolygons correctly.The
multipolygon_begin
andmultipolygon_end
methods are indirectly tested through themultipolygon
function intests/geozero.rs
, which covers the creation, conversion, and validation of multipolygons.
tests/geozero.rs
:multipolygon
functionScripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify test coverage for `multipolygon_begin` and `multipolygon_end`. # Test: Ensure there are tests for `multipolygon_begin` and `multipolygon_end`. rg --type rust 'multipolygon_begin|multipolygon_end' tests/Length of output: 61
Script:
#!/bin/bash # Description: Verify usage and test coverage for `multipolygon_begin` and `multipolygon_end`. # Search for all instances of `multipolygon_begin` in the codebase. rg --type rust 'multipolygon_begin' # Search for all instances of `multipolygon_end` in the codebase. rg --type rust 'multipolygon_end'Length of output: 391
Script:
#!/bin/bash # Description: Verify test coverage for `multipolygon_begin` and `multipolygon_end` through reader tests. # Search for test cases related to `src/geozero/reader.rs`. rg --type rust 'reader' tests/Length of output: 30
Script:
#!/bin/bash # Description: Verify test coverage for multipolygon handling. # Search for test files that might contain tests for multipolygon handling. rg --type rust 'multipolygon' tests/Length of output: 73
Script:
#!/bin/bash # Description: Display the contents of `tests/geozero.rs` to verify test coverage for multipolygon handling. # Display the contents of `tests/geozero.rs`. cat tests/geozero.rsLength of output: 5182
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- tests/geozero.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/geozero.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- tests/geozero.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/geozero.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- tests/geozero.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/geozero.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- tests/geozero.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/geozero.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Outside diff range and nitpick comments (2)
tests/geozero.rs (2)
Line range hint
10-51
: Enhancemultipolygon
test with more assertions.The
multipolygon
test function is comprehensive. However, consider adding more assertions for interior rings to ensure complete coverage.+ assert_eq!(geo_mpoly.0[1].interiors().len(), 1); + assert_eq!(geo_mpoly.0[2].interiors().len(), 0);
56-85
: Enhancemultipolygon3d
test with more assertions.The
multipolygon3d
test function is comprehensive. However, consider adding more assertions for interior rings to ensure complete coverage.+ assert_eq!(mpoly[1].interiors().len(), 1); + assert_eq!(mpoly[2].interiors().len(), 0);
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/geozero/writer.rs (1 hunks)
- tests/geozero.rs (2 hunks)
Additional context used
Learnings (1)
src/geozero/writer.rs (1)
Learnt from: ciscorn PR: MIERUNE/flatgeom-rs#4 File: src/geozero/writer.rs:16-19 Timestamp: 2024-07-05T11:29:53.447Z Learning: In the `flatgeom-rs` library, `D` is a compile-time constant, and a value less than 2 indicates a programming error rather than a runtime condition.
GitHub Check: codecov/patch
src/geozero/writer.rs
[warning] 18-18: src/geozero/writer.rs#L18
Added line #L18 was not covered by tests
[warning] 30-30: src/geozero/writer.rs#L30
Added line #L30 was not covered by tests
[warning] 32-32: src/geozero/writer.rs#L32
Added line #L32 was not covered by tests
[warning] 38-40: src/geozero/writer.rs#L38-L40
Added lines #L38 - L40 were not covered by tests
[warning] 70-70: src/geozero/writer.rs#L70
Added line #L70 was not covered by tests
[warning] 72-72: src/geozero/writer.rs#L72
Added line #L72 was not covered by tests
[warning] 115-115: src/geozero/writer.rs#L115
Added line #L115 was not covered by tests
[warning] 127-127: src/geozero/writer.rs#L127
Added line #L127 was not covered by tests
Additional comments not posted (24)
src/geozero/writer.rs (13)
16-19
: Panic innew
method is acceptable for compile-time constantD
.Since
D
is a compile-time constant, the panic here is intended to catch programming errors early.Tools
GitHub Check: codecov/patch
[warning] 18-18: src/geozero/writer.rs#L18
Added line #L18 was not covered by tests
120-123
: Add tests forgeometrycollection_begin
method.The
geometrycollection_begin
method is not covered by tests. Adding tests will ensure its functionality.
125-132
: Add tests forgeometrycollection_end
method.The
geometrycollection_end
method is not covered by tests. Adding tests will ensure its functionality.Tools
GitHub Check: codecov/patch
[warning] 127-127: src/geozero/writer.rs#L127
Added line #L127 was not covered by tests
134-137
: Add tests formultipoint_begin
method.The
multipoint_begin
method is not covered by tests. Adding tests will ensure its functionality.
139-144
: Add tests forlinestring_begin
method.The
linestring_begin
method is not covered by tests. Adding tests will ensure its functionality.
146-149
: Add tests formultilinestring_begin
method.The
multilinestring_begin
method is not covered by tests. Adding tests will ensure its functionality.
151-156
: Add tests forpolygon_begin
method.The
polygon_begin
method is not covered by tests. Adding tests will ensure its functionality.
158-161
: Add tests formultipolygon_begin
method.The
multipolygon_begin
method is not covered by tests. Adding tests will ensure its functionality.
163-167
: Add tests formultipoint_end
method.The
multipoint_end
method is not covered by tests. Adding tests will ensure its functionality.
169-175
: Add tests forlinestring_end
method.The
linestring_end
method is not covered by tests. Adding tests will ensure its functionality.
177-180
: Add tests formultilinestring_end
method.The
multilinestring_end
method is not covered by tests. Adding tests will ensure its functionality.
182-187
: Add tests forpolygon_end
method.The
polygon_end
method is not covered by tests. Adding tests will ensure its functionality.
189-192
: Add tests formultipolygon_end
method.The
multipolygon_end
method is not covered by tests. Adding tests will ensure its functionality.tests/geozero.rs (11)
87-116
: LGTM!The
polygon
test function is comprehensive and covers both conversion and inversion.
118-133
: LGTM!The
polygon3d
test function is comprehensive and covers both conversion and inversion.
137-164
: LGTM!The
multilinestring
test function is comprehensive and covers both conversion and inversion.
168-182
: LGTM!The
multilinestring3d
test function is comprehensive and covers both conversion and inversion.
186-208
: LGTM!The
linestring
test function is comprehensive and covers both conversion and inversion.
211-223
: LGTM!The
linestring3d
test function is comprehensive and covers both conversion and inversion.
227-251
: LGTM!The
multipoint
test function is comprehensive and covers both conversion and inversion.
255-267
: LGTM!The
multipoint3d
test function is comprehensive and covers both conversion and inversion.
271-297
: LGTM!The
geometry
test function is comprehensive and covers both conversion and inversion.
300-315
: LGTM!The
geometry3d
test function is comprehensive and covers both conversion and inversion.
318-343
: LGTM!The
geometry_collection
test function is comprehensive and covers both conversion and inversion.
pub fn take_geometry(mut self) -> Option<Geometry<'static, [f64; D]>> { | ||
match self.geoms.len() { | ||
0 => None, | ||
1 => Some(self.geoms.pop().unwrap()), | ||
_ => Some(Geometry::GeometryCollection(self.geoms)), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for take_geometry
method.
The take_geometry
method is not covered by tests. Adding tests will ensure its functionality.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Tools
GitHub Check: codecov/patch
[warning] 30-30: src/geozero/writer.rs#L30
Added line #L30 was not covered by tests
[warning] 32-32: src/geozero/writer.rs#L32
Added line #L32 was not covered by tests
impl<const D: usize> Default for FlatgeomWriter<D> { | ||
fn default() -> Self { | ||
Self::new() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for Default
implementation.
The Default
implementation is not covered by tests. Adding tests will ensure its functionality.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Tools
GitHub Check: codecov/patch
[warning] 38-40: src/geozero/writer.rs#L38-L40
Added lines #L38 - L40 were not covered by tests
fn start_geometry(&mut self, geom: Geometry<'static, [f64; D]>) { | ||
match geom { | ||
Geometry::GeometryCollection(geoms) => { | ||
self.collections.push(geoms); | ||
} | ||
geom => { | ||
self.current = Some(geom); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for start_geometry
method.
The start_geometry
method is not covered by tests. Adding tests will ensure its functionality.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
fn finish_coords(&mut self, idx: usize) { | ||
if let Some(geom) = self.current.as_mut() { | ||
let iter = self.coords.iter().copied(); | ||
match geom { | ||
Geometry::MultiPoint(mp) => mp.extend(iter), | ||
Geometry::LineString(ls) => ls.extend(iter), | ||
Geometry::MultiLineString(mls) => mls.add_linestring(iter), | ||
Geometry::Polygon(poly) => poly.add_ring(iter), | ||
Geometry::MultiPolygon(mpoly) => { | ||
if idx == 0 { | ||
mpoly.add_exterior(iter); | ||
} else { | ||
mpoly.add_interior(iter); | ||
} | ||
} | ||
_ => {} | ||
} | ||
} | ||
self.coords.clear(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for finish_coords
method.
The finish_coords
method is not covered by tests. Adding tests will ensure its functionality.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Tools
GitHub Check: codecov/patch
[warning] 70-70: src/geozero/writer.rs#L70
Added line #L70 was not covered by tests
[warning] 72-72: src/geozero/writer.rs#L72
Added line #L72 was not covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/lib.rs (1 hunks)
- tests/geozero.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/geozero.rs
Additional comments not posted (3)
src/lib.rs (3)
6-6
: Good practice: Added separation for readability.The addition of a blank line improves the readability of the code.
7-7
: Good practice: Conditional compilation for optional features.Using the
#[cfg(feature = "geozero")]
attribute is a good way to manage optional features and reduce the binary size.
8-8
: Enhancing interoperability: Conditional publicgeozero
module.Making the
geozero
module public conditionally aligns with the goal of enhancing interoperability with the GeoZero library.
Close #2
This PR implements the GeomProcessor trait for our geometries, enabling the conversion of other GeoZero geometries into our geometries.
Summary by CodeRabbit
New Features
extend
methods toLineString
andMultiPoint
for appending coordinates.GeometryCollection
to handle collections of geometries.ToFlatgeom
trait for converting geometries to a flat representation.Enhancements
reader
andwriter
modules undergeozero
.FlatgeomWriter
to support multi-dimensional geometries and collections.Tests
flatgeom
conversions and additional geometric types.