Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/turf-clusters-dbscan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ function clustersDbscan(
(neighbor) => {
const neighborIndex = neighbor.index;
const neighborPoint = points.features[neighborIndex];
const distanceInKm = distance(point, neighborPoint, {
units: "kilometers",
const distanceToNeighbor = distance(point, neighborPoint, {
units: options.units,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out this still needed fixing after the revert based on the test case below.

});
return distanceInKm <= maxDistance;
return distanceToNeighbor <= maxDistance;
}
);
};
Expand Down
35 changes: 35 additions & 0 deletions packages/turf-clusters-dbscan/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,38 @@ test("clusters-dbscan -- allow input mutation", (t) => {
t.equal(oldPoints.features[1].properties.cluster, 1, "cluster is 1");
t.end();
});

test("clusters-dbscan -- respect units option", (t) => {
const testPoints = featureCollection([
point([0, 0]),
point([0.000001, 0]),
point([0.001, 0]),
point([0.8, 0]),
]);

const kmPoints = clustersDbscan(testPoints, 1, { minPoints: 1 });
const mPoints = clustersDbscan(testPoints, 1, {
minPoints: 1,
units: "meters",
});
const degreePoints = clustersDbscan(testPoints, 1, {
minPoints: 1,
units: "degrees",
});

const kmClusters = new Set(
kmPoints.features.map((f) => f.properties.cluster)
);

const mClusters = new Set(mPoints.features.map((f) => f.properties.cluster));

const degreeClusters = new Set(
degreePoints.features.map((f) => f.properties.cluster)
);

t.equal(kmClusters.size, 2);
t.equal(mClusters.size, 3);
t.equal(degreeClusters.size, 1);

t.end();
});
4 changes: 2 additions & 2 deletions packages/turf-helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ depending on latitude.
See [https://www.thoughtco.com/degree-of-latitude-and-longitude-distance-4070616][1]
for an illustration of this behaviour.

Type: (`"meters"` | `"metres"` | `"millimeters"` | `"millimetres"` | `"centimeters"` | `"centimetres"` | `"kilometers"` | `"kilometres"` | `"miles"` | `"nauticalmiles"` | `"inches"` | `"yards"` | `"feet"` | `"radians"` | `"degrees"`)
Type: (`"meters"` | `"metres"` | `"m"` | `"millimeters"` | `"millimetres"` | `"mm"` | `"centimeters"` | `"centimetres"` | `"cm"` | `"kilometers"` | `"kilometres"` | `"km"` | `"miles"` | `"mi"` | `"nauticalmiles"` | `"nmi"` | `"inches"` | `"in"` | `"yards"` | `"yd"` | `"feet"` | `"ft"` | `"radians"` | `"rad"` | `"degrees"` | `"deg"`)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just coming from the automatic readme generation after #3063 was merged. Sadly the CI is still not catching this when the readmes haven't been regenerated.


## AreaUnits

Area measurement units.

Type: (Exclude<[Units][2], (`"radians"` | `"degrees"`)> | `"acres"` | `"hectares"`)
Type: (Exclude<[Units][2], (`"radians"` | `"rad"` | `"degrees"` | `"deg"`)> | `"acres"` | `"ac"` | `"hectares"` | `"ha"`)

## Grid

Expand Down
Loading