Skip to content
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

Add DumpCoordinates methods #398

Merged
merged 13 commits into from
Aug 5, 2021
Merged

Add DumpCoordinates methods #398

merged 13 commits into from
Aug 5, 2021

Conversation

peterstace
Copy link
Owner

Description

Adds DumpCoordinates methods on geometry types. These methods give back a
Sequence that contains all points in the geometry.

Check List

Have you:

  • Added unit tests? Yes.

  • Add cmprefimpl tests? (if appropriate?) N/A

Related Issue

Benchmark Results

N/A

@peterstace peterstace self-assigned this Aug 4, 2021
@@ -18,3 +25,76 @@ type Coordinates struct {
// or not Z and M are populated.
Type CoordinatesType
}

// String gives a string representation of the coordinates.
func (c Coordinates) String() string {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add a test for this.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in a986bf8

}

// NewXYCoordinates constructs a new set of coordinates of type XY.
func NewXYCoordinates(x, y float64) Coordinates {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably aren't necessary anymore... I used then for tests before I switched from returning []Coordinates to returning Sequence. Can be removed.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 4f6f5b6

case TypePoint:
return g.AsPoint().DumpCoordinates()
case TypeLineString:
return g.AsLineString().Coordinates()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no DumpCoordinates method for LineString, because the existing Coordinates method does the exact same thing. Even though it's a bit inconsistent, I think that's less confusing than having two methods that do exactly the same thing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if each geometry implemented DumpCoordinates(), could we do something like g.AsDumpable().DumpCoordinates() (for want of a better function name) and not required the switch-case block?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That (or something similar) might be possible. The challenge would be implementing AsDumpable() on the Geometry type. The obvious way to implement it would be to use a switch, but that would defeat the point since we're trying to eliminate a switch statement. It may be possible to use some sort of reflect/unsafe magic though.

The "switch" pattern actually shows up extremely frequently in this file (and is a bit of a code smell). Possibly it could be implemented generically so that we only need a single switch statement for all interface types.

Thanks for bringing this up! 😄 I've raised a ticket here: #399

These aren't really necessary at this point. We may wish to add
something like these in the future though.
@peterstace peterstace merged commit 331da28 into master Aug 5, 2021
@peterstace peterstace deleted the dump_points branch August 5, 2021 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants