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

make s2.Loop Regions & serializable + Fix loop.IntersectsCell #8

Closed
wants to merge 4 commits into from

Conversation

azr
Copy link

@azr azr commented Jun 20, 2016

Hello there,

I really need a way to serialize a big bunch of s2.Loops and also @buckhx made them Region compliant. ( which I needed too )

I'm pushing this here as some people might need that too. Just tell me if something is wrong I'll change it :).

Thoughts: it's much more convenient if everything is public in a struct that is returned by a package. Specially for serialization cases. If you are afraid someone will tweak too much variables and they should not, well they just better know what they are doing :).

o/

EDIT: sorry, made the pull request before asking anything.

@azr
Copy link
Author

azr commented Aug 9, 2016

I resolved some conflicts. :)

@azr
Copy link
Author

azr commented Aug 9, 2016

I just found a bug case where the Covering returns an empty CellUnion where it should not.

This happens because the generated cell by FastCovering is much bigger than the actual Region ( which is a Loop ) and Cells for whichregion.IntersectsCell(cell) == false are filtered out inside coverer.newCandidate.

As the region is fully contained by the cell it does not intersects it.
I think intersect should return true if the first point of the Loop is inside the cell.

I added a test case. I'll fix it.

@azr
Copy link
Author

azr commented Aug 9, 2016

Here is a fix, tests are passing.

@azr azr changed the title make s2.Loop Regions & serializable make s2.Loop Regions & serializable + Fix loop.IntersectsCell Aug 9, 2016
@azr
Copy link
Author

azr commented Nov 15, 2016

Hello there ! I just rebased this.

Do you even accept prs at all ?

@dsymonds
Copy link
Contributor

Sorry, this isn't a sufficient approach. Exporting all the fields is easy and makes some things simpler, but makes for a worse API.

@dsymonds dsymonds closed this Nov 15, 2016
@dsymonds
Copy link
Contributor

Also, please keep features separate from bug fixes. This is way too noisy to untangle if we were interested in taking just a bug fix.

@azr
Copy link
Author

azr commented Nov 16, 2016

Hello @dsymonds,

For the mixed code, it's actually fixing some code that made the loop a Region

On the field exporting, I disagree, this is golang, not C++.

The struct has :

func (l Loop) RectBound() Rect {
    return l.bound
}
func (l Loop) Vertices() []Point {
    return l.vertices
}
func (l Loop) ContainsOrigin() bool {
    return l.originInside
}

and may be misses a SubregionBound() []Rect func.

I mean, instead of documenting the funcs, the fields could be Public and documented ( and they already are ! :) )

Plus as I said before if you are scared people tweak those fields just because they are public, then they just better know what they do.

And this would make a better golang API to me.

@azr
Copy link
Author

azr commented Nov 16, 2016

If you have any better/cooler idea to be able to encode this struct easily, I'm in to do it.

One weird way :

type publicLoop struct {
        Vertices []Point
        OriginInside bool
        Bound Rect
        SubregionBound Rect
}

func (l Loop) Fields() interface{} {
    return publicLoop{
        Vertices: l.vertices,
        OriginInside: l.originInside,
        Bound: l.bound,
        SubregionBound: l.subregionBound,
    }
}

Another way would be to implement every serialization known out there.

@dsymonds
Copy link
Contributor

Loop is a long way from complete. Its internals are going to change a fair bit as it gets filled out, which is why things are unexported.

@azr
Copy link
Author

azr commented Nov 17, 2016

aah okay, you don't want to break the api all the time :)

but do you have any preferences if the lib ever had a way to dump its structs to disk to later reload ?

What do you think of this approach ?

func (l Loop) Fields() interface{} {}
func (l Loop) SetFields(interface{}) error {}

@dsymonds
Copy link
Contributor

There's a specific serialization format that C++ already defines, and we're going to match those. Someone is working on that already.

@azr
Copy link
Author

azr commented Nov 18, 2016

Oki doki ! I'll just wait on my branch then :) thanks for your time

Philiphil pushed a commit to Philiphil/geo that referenced this pull request Nov 18, 2022
Philiphil pushed a commit to Philiphil/geo that referenced this pull request Nov 18, 2022
Philiphil pushed a commit to Philiphil/geo that referenced this pull request Nov 18, 2022
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.

None yet

2 participants