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

Commit

Permalink
pull geometry from feature objects in within
Browse files Browse the repository at this point in the history
whoops
  • Loading branch information
jgravois committed Oct 13, 2016
1 parent 267aa97 commit 2d53c92
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/node/timezone/index.js
Expand Up @@ -79,7 +79,7 @@ var server = http.createServer(function (request, response) {
for (var i = 0; i < results.length; i++) {
// since we are using Terraformer, we can check containsPoint()
var rowId = results[i].rowId;
if (places[rowId].intersects({ type: "Point", coordinates: [ parsed.query.longitude, parsed.query.latitude ] })) {
if (places[rowId].within({ type: "Point", coordinates: [ parsed.query.longitude, parsed.query.latitude ] })) {
found = places[results[i].rowId].properties.TZID;
}
}
Expand Down
5 changes: 5 additions & 0 deletions spec/terraformerSpec.js
Expand Up @@ -910,6 +910,11 @@ describe("Intersection", function(){
expect(point.within(polygon)).toEqual(true);
});

it("should return true when inside a circle", function(){
var circle = new Terraformer.Circle([ 10, 10 ], 50, 64);
expect(point.within(circle)).toEqual(true);
});

});

describe("MultiPolygon Within", function(){
Expand Down
5 changes: 5 additions & 0 deletions terraformer.js
Expand Up @@ -755,6 +755,11 @@
Primitive.prototype.within = function(primitive) {
var coordinates, i, contains;

// if we are passed a feature, use the polygon inside instead
if (primitive.type === 'Feature') {
primitive = primitive.geometry;
}

// point.within(point) :: equality
if (primitive.type === "Point") {
if (this.type === "Point") {
Expand Down

0 comments on commit 2d53c92

Please sign in to comment.