Closed akhenakh closed 1 month ago
Yeah I see what you mean, thank you for reporting your experience. I think there are a few different options to make this sort of bug less likely:
Add a geom.NewCoordinates
function that takes a geom.CoordinatesType
. We'd also have to make it accept the right number of float64 arguments. So maybe the function signature would be like geom.NewCoordinates(geom.CoordinatesType, xyzm ...float64)
. Examples of use:
geom.NewPoint(geom.NewCoordinates(geom.DimXY, 10, 11))
geom.NewPoint(geom.NewCoordinates(geom.DimXYZ, 10, 11, 400))
It might be best if it panics if the geom.CoordinatesType
argument doesn't match the number of args, which is the same as what geom.NewSequence
does.
Create new functions for each coordinates type:
geom.NewCoordinatesXY(x, y float64) geom.Coordinates
geom.NewCoordinatesXYZ(x, y, z float64) geom.Coordinates
geom.NewCoordinatesXYM(x, y, m float64) geom.Coordinates
geom.NewCoordinatesXYZM(x, y, z, m float64) geom.Coordinates
Usage examples:
geom.NewPoint(geom.NewCoordinatesXY(10, 11))
geom.NewPoint(geom.NewCoordinatesXYZ(10, 11, 400))
The geom.Coordinates
are mainly used for the creation of geom.Point
values. So maybe we could just create new point constructors like this:
geom.NewPointXY(x, y float64) geom.Point
geom.NewPointXYZ(x, y, z float64) geom.Point
geom.NewPointXYM(x, y, m float64) geom.Point
geom.NewPointXYZM(x, y, z, m float64) geom.Point
Usage would look like:
geom.NewPointXY(10, 11)
geom.NewPointXYZ(10, 11, 400)
There are already "special" constructors for points, e.g. geom.NewEmptyPoint
, so there is definitely precedence for this sort of thing.
I'm sort of leaning towards option 3 as the best, but would love to hear your thoughts @akhenakh.
Thanks for your answer!
I agree with you, option 3 looks nicer to use, but does not really align with the rest of functions where we need to pass a geom.DimXY
as argument.
So my preference is 3, but consistency tends more to 1.
Maybe both option 1 AND 3 is right? NewPoint
just being an helper.
Fixed using an approach most similar to "option 1" above (see https://github.com/peterstace/simplefeatures/releases/tag/v0.52.0).
I run into a stupid bug because specifying Z in a
NewPoint(geom.Coordinates{})
results in it defaulting toType: geom.DimXY
, it makes sense.In the rest of the API, though, helper functions helps to remind you to specify the dimension like
geom.NewSequence(seq, geom.DimXY)
.I did not find any
NewCoordinates()
?