Add methods to check geometry type and convert simultaneously #423
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Renames the
AsXYZ
methods of theGeometry
type toMustAsXYZ
. Thisfollows the go convention that methods and functions prefixed with
Must
maypanic if preconditions are not met. Note that there's no change in behaviour
here, it's simply a rename (these methods previously panicked).
Adds new methods named
AsXYZ
to theGeometry
type. These methods have thesignature
AsXYZ() (XYZ, bool)
. The boolean return value indicates if theconversion was successful or not. These methods are useful because they allow
concrete geometries to be extracted from a
Geometry
value, with the checkfor the type and the extraction only specified once. Previously, users would
have to first call
IsXYZ
to check if the type is expected, and thenconditionally call
AsXYZ
. Users now just have to callAsXYZ
, and cancheck the flag. This helps to eliminate the class of bugs there the type
specified with
IsXYZ
differs from the type specified byAsXYZ
(e.g. ifthe user calls
IsPoint
but thenAsPolygon
, which would be erroneous).Check List
Have you:
Added unit tests? Yes.
Add cmprefimpl tests? (if appropriate?) N/A
Updated release notes? (if appropriate?) TODO
Related Issue
ToXYZ
geometry conversion methods #420Benchmark Results
N/A