-
Notifications
You must be signed in to change notification settings - Fork 334
Add a simple toArray() helper to complement the other helpers on the Point class. #96
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
Conversation
Add toArray() helper
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.
Good idea 💯
Would you mind adding the implements Arrayable
on Point
class? (Illuminate\Contracts\Support\Arrayable
)
Also -and I'm just thinking out loud here- it might be useful to implement ArrayAccess
on the Point
class (similarly to the GeometryCollection
). We should then be able to get and set the latitude and longitude on $point
just like an associative array:
$point = new Point(1, 2); echo $point['lat']; // 1 echo $point['lng'] // 2 $point['lat'] = 3; echo $point['lat']; // 3
Although if we implement ArrayAccess
, then we should throw an exception when:
- adding a 3rd value to the
$point
(ex:$point[] = <some float>
) - adding an array key different than
lat
orlng
(ex:$point['hello'] = <some float>
)
And to be complete, there's also IteratorAggregate
which will allow us to loop. Not super useful, is it? I'm not sure. But if we implement it, then we should invert the order of lat
and lng
in Point::toArray()
to match the order in the rest of the class (__toString()
, toPair()
).
What do you think?
I know I'm the one suggesting, but I'm also skeptical about these implementations 🤣
Add toArray() helper