OpenLayers OpenLayers

Ticket #1072 (closed feature: fixed)

Opened 1 year ago

Last modified 1 year ago

Support Geometry intersection method

Reported by: crschmidt Assigned to: tschaub
Priority: minor Milestone: 2.6 Release
Component: Geometry Version: SVN
Keywords: Cc:
State: Complete

Description

In order to do better hit detection, support an 'intersects' method on geometries, which determines whether they intersect a given geom. This allows for more accurate selection based on a bounding box, and other similar things.

Attachments

intersects.patch (161.7 kB) - added by tschaub on 12/16/07 21:39:39.
add geometry.intersects method

Change History

10/07/07 09:14:07 changed by crschmidt

Tests:

PASS

POLYGON((-33.046875 48.8671875, -48.515625 6.6796875, -20.390625 8.0859375, -16.875 34.1015625, -33.046875 48.8671875))
POLYGON((-59.0625 29.1796875, -66.796875 -23.5546875, -38.671875 -7.3828125, -39.375 20.0390625, -59.0625 29.1796875))

POLYGON((-59.0625 29.1796875, -66.796875 -23.5546875, -38.671875 -7.3828125, -39.375 20.0390625, -59.0625 29.1796875))
LINESTRING(-0.703125 -19.3359375, -85.78125 8.7890625)

POLYGON((98.4375 27.0703125, 116.015625 -11.6015625, 139.21875 25.6640625, 98.4375 27.0703125))
POINT(109.6875 18.6328125)

LINESTRING(-19.6875 -46.7578125, -26.71875 -22.1484375, 0 23.5546875)
LINESTRING(-0.703125 -19.3359375, -85.78125 8.7890625)

FAIL

LINESTRING(87.890625 -22.1484375, 47.8125 -23.5546875, 47.8125 -60.1171875, 97.734375 -62.9296875)
POINT(63.28125 -40.4296875)

LINESTRING(87.890625 -22.1484375, 47.8125 -23.5546875, 47.8125 -60.1171875, 97.734375 -62.9296875)
LINESTRING(76.640625 -33.3984375, 75.234375 -51.6796875)

POLYGON((85.78125 54.4921875, 56.953125 52.3828125, 71.015625 5.2734375, 94.921875 9.4921875, 90.703125 24.2578125, 71.015625 23.5546875, 68.203125 43.9453125, 83.671875 43.9453125, 85.78125 54.4921875))
POINT(78.046875 35.5078125)

POLYGON((85.78125 54.4921875, 56.953125 52.3828125, 71.015625 5.2734375, 94.921875 9.4921875, 90.703125 24.2578125, 71.015625 23.5546875, 68.203125 43.9453125, 83.671875 43.9453125, 85.78125 54.4921875))
LINESTRING(81.5625 28.4765625, 106.171875 39.7265625)

10/08/07 00:32:28 changed by tschaub

Not sure if you're starting something elsewhere - in case it wasn't seen, I added intersect support in my geom sandbox.

http://trac.openlayers.org/changeset/4872

More later.

10/08/07 00:33:54 changed by crschmidt

I was just adding tests so that you wouldn't have to go create them -- i made the ticket after you made your sandbox commit :) Just trying to save a bit of work where I can, without doing anything particularly strenuous ;)

10/08/07 23:03:25 changed by tschaub

Thanks for the motivation. I added tests and fixed a few issues. The multis still need exercising. The intersects.html example is useful in building the geometry-intersects.js for the tests.

10/09/07 00:28:55 changed by crschmidt

I ripped all the standard test cases out of geos, then wrote a small ogr script to put together data for use in javascript. Looks like we're passing 472/500 of the geos tests for intersects().

12/16/07 19:35:18 changed by tschaub

  • owner set to tschaub.
  • state changed.

Ok, failed tests were about different rules for intersection. We now consider all points on an edge to be in polygons. There are places where this is undesirable (if you want to consider a point to be in only one of two polygons sharing an edge) - but it is obviously not the way geos looks at things. Our polygon.containsPoint method now returns 1 if the point is on a ring edge, boolean otherwise. The geometry.intersects method considers both cases (1 and true) to be an intersection. I've also tucked in some code here that will let us actually return the intersection of two geometries - but we'll save that for later. For now, geometry.intersects returns boolean and passes all geos tests.

Patch to follow.

12/16/07 21:39:39 changed by tschaub

  • attachment intersects.patch added.

add geometry.intersects method

12/16/07 21:42:38 changed by tschaub

  • status changed from new to assigned.
  • state set to Review.

Ok, with this, we get geometry.intersects on all geometry types. Tests pass in FF/IE. Thanks Chris for the geos test cases. I've wrapped the test up a bit so not all successes are reported (only failures) - but all 490 pass. Will gladly commit with approval.

12/16/07 21:58:23 changed by crschmidt

  • state changed from Review to Commit.

I don't know enough to understand the code, but I trust the tests in this case. (If we do the same thing as GEOS, certainly we at least have a strong argument that we're doing something that is considered right to fall back on.)

Technical niggle: Your patch adds the geos test data twice for a reason I don't really understand -- end result being that the file is twice as big as it should be. IF you make sure that isn't the case on commit, you can go ahead with this one whenever you're ready.

12/17/07 01:05:35 changed by tschaub

  • status changed from assigned to closed.
  • state changed from Commit to Complete.
  • resolution set to fixed.

(In [5458]) add geometry.intersects method for all geometry types (closes #1072)