Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Add clearer documentation on the format of boxes #6

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

Conversation

finnergizer
Copy link

@finnergizer finnergizer commented Aug 29, 2016

Love the blog post, documentation, and utility of this!

Was setting it up myself, and had trouble getting results that I thought would be in the boxes when I set up the first inner list to be the bottom left coordinate and the second inner list to be the top right coordinate for the bounding box.

Maybe I am misinterpreting but when I examined the in_box method it appears as if the comparison is done using the first inner list as the bottom right, and the second as the top left.

I could be a bit misguided, so let me know if I was simply utilizing the BOXES incorrectly.

@finnergizer finnergizer changed the title Add clearer documentation on the format of boxes, and normalize lat/long comparisons Add clearer documentation on the format of boxes Aug 29, 2016
@jonpolak
Copy link

is it really bottom right and top left in that order?
it seemed to work bottom left and top right?

@finnergizer
Copy link
Author

finnergizer commented Aug 31, 2016

Here is my initial understanding...

Suppose we have a box with the following two points:

bottom-right: 40, -115 —> box[0][0] = 40, box[0][1] = -115
top-left: 45, -120 —> box[1][0] = 45, box[1][1] = -120

a valid point in this box is 42, -118
coords[0]=42
coords[1]=-118

Let’s sub this into the conditional statement in in_box

if box[0][0] < coords[0] < box[1][0] and box[1][1] < coords[1] < box[0][1]:

>>> 40 < 42 < 45 and -120 < -118 < -115
True

This statement evaluates to true with those co-ordinates specifying the box… So in-box returns True as it should.

Conversely if we were to use bottom-left, top-right, the same box would look like:

bottom-left: 40, -120 —> box[0][0] = 40, box[0][1] = -120
top-right: 45, -115 —> box[1][0] = 45, box[1][1] = -115

Again, subbing this into the conditional:

if box[0][0] < coords[0] < box[1][0] and box[1][1] < coords[1] < box[0][1]:

We get:

>>> 40 < 42 < 45 and -115 <  -118 < -120
False

Which is false by the second part of the conditional…

So in-box returns False when it should return true if the box was defined by bottom-left, top-right.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants