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 a simple toArray() helper to complement the other helpers on the Point class. #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kevinruscoe
Copy link

Add toArray() helper

@kevinruscoe kevinruscoe changed the title Add a simple toArray() to complement the other helpers on the Point class. Add a simple toArray() helper to complement the other helpers on the Point class. Aug 21, 2019
Copy link
Owner

@grimzy grimzy left a 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)

@grimzy
Copy link
Owner

grimzy commented Mar 5, 2020

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 or lng (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 🤣

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