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
99 changes: 12 additions & 87 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,91 +1,16 @@
{
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"consistent-return": 0,
"curly": 2,
"dot-notation": 2,
"eqeqeq": 2,
"func-names": ["error", "always"],
"guard-for-in": 2,
"indent": [2, 2, {"SwitchCase": 1}],
"linebreak-style": [2, "unix"],
"new-cap": 1,
"no-caller": 2,
"no-catch-shadow": 2,
"no-console": 2,
"no-else-return": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-eval": 2,
"no-implicit-coercion": 2,
"no-implied-eval": 2,
"no-invalid-this": 2,
"no-irregular-whitespace": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 1,
"no-loop-func": 2,
"no-multi-spaces": 1,
"no-multiple-empty-lines": 1,
"no-native-reassign": 2,
"no-nested-ternary": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-throw-literal": 2,
"no-undef": 2,
"no-undef-init": 1,
"no-unreachable": 2,
"no-unused-expressions": [2, {"allowShortCircuit": true}],
"no-useless-call": 2,
"no-with": 2,
"quotes": [2, "single"],
"require-atomic-updates": 0,
"semi": [2, "always"],
"space-before-blocks": 2,
"strict": [2, "global"],
"vars-on-top": 2,
"yoda": [2, "never"],
"sort-keys": ["error", "asc"],
"keyword-spacing": ["error", { "before": true, "after": true }],
"object-curly-spacing": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"comma-spacing": 2,
"brace-style": ["error", "stroustrup"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false, "overrides": { "!": true } }],
"key-spacing": ["error", { "afterColon": true }]
},
"overrides": [
{
"files": [
"test/**/*.js",
"features-legacy/**/*.js",
"features/**/*.js"
],
"rules": {
"sort-keys": "off"
}
}
"plugins": [
"kuzzle"
],
"extends": [
"plugin:kuzzle/default",
"plugin:kuzzle/node"
],
"env": {
"node": true,
"es6": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": false
},
"ecmaVersion": 2018
"ecmaVersion": 2020
},
"extends": "eslint:recommended"
}
"rules": {
"sort-keys": "warn",
"kuzzle/array-foreach": "warn"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [pull_request]
jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache node modules
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push_branches.workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
release:
name: Release process
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 1.4.0-beta.1 (2025-12-02)

* fix: missing deps to release ([6d92972](https://github.com/kuzzleio/boost-geospatial-index/commit/6d92972))
* fix: missing deps to release ([c90180b](https://github.com/kuzzleio/boost-geospatial-index/commit/c90180b))
* fix: missing deps to release ([91466d3](https://github.com/kuzzleio/boost-geospatial-index/commit/91466d3))
* Merge branch 'beta' into 1-dev ([594fad0](https://github.com/kuzzleio/boost-geospatial-index/commit/594fad0))
* Merge pull request #25 from kuzzleio/1-dev ([919555d](https://github.com/kuzzleio/boost-geospatial-index/commit/919555d)), closes [#25](https://github.com/kuzzleio/boost-geospatial-index/issues/25)
* chore(license): Update LICENSE.md ([65924e6](https://github.com/kuzzleio/boost-geospatial-index/commit/65924e6))
* chore(license): Update LICENSE.md ([f88003f](https://github.com/kuzzleio/boost-geospatial-index/commit/f88003f))
* chore(lint): linting the app ([1b2a539](https://github.com/kuzzleio/boost-geospatial-index/commit/1b2a539))
* chore(runner): update runner version ([2253a4a](https://github.com/kuzzleio/boost-geospatial-index/commit/2253a4a))
* feat: bump deps ([2da3a53](https://github.com/kuzzleio/boost-geospatial-index/commit/2da3a53))

# [1.3.0](https://github.com/kuzzleio/boost-geospatial-index/compare/v1.2.0...v1.3.0) (2025-01-07)


Expand Down
120 changes: 75 additions & 45 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var BSI = require('bindings')('BoostSpatialIndex');
"use strict";

var BSI = require("bindings")("BoostSpatialIndex");

/**
* @constructor
*/
function BoostSpatialIndex () {
function BoostSpatialIndex() {
this.spatialIndex = new BSI.SpatialIndex();
return this;
}
Expand All @@ -18,21 +20,31 @@ function BoostSpatialIndex () {
* @param {Number} max_lon
* @return {boolean}
*/
BoostSpatialIndex.prototype.addBoundingBox = function addBoundingBox (id, min_lat, min_lon, max_lat, max_lon) {
if (! id || typeof id !== 'string' || id.length === 0) {
BoostSpatialIndex.prototype.addBoundingBox = function addBoundingBox(
id,
min_lat,
min_lon,
max_lat,
max_lon,
) {
if (!id || typeof id !== "string" || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

if ([min_lat, min_lon, max_lat, max_lon].findIndex(v => typeof v !== 'number') !== -1) {
throw new Error('Invalid coordinates parameter');
if (
[min_lat, min_lon, max_lat, max_lon].findIndex(
(v) => typeof v !== "number",
) !== -1
) {
throw new Error("Invalid coordinates parameter");
}

if (min_lat >= max_lat) {
throw new Error('min_lat argument cannot be greater or equal max_lat');
throw new Error("min_lat argument cannot be greater or equal max_lat");
}

if (min_lon >= max_lon) {
throw new Error('min_lon argument cannot be greater or equal max_lon');
throw new Error("min_lon argument cannot be greater or equal max_lon");
}

return this.spatialIndex.addBBox(id, min_lat, min_lon, max_lat, max_lon);
Expand All @@ -47,13 +59,18 @@ BoostSpatialIndex.prototype.addBoundingBox = function addBoundingBox (id, min_la
* @param {Number} radius in meters
* @return {boolean}
*/
BoostSpatialIndex.prototype.addCircle = function addCircle (id, lat, lon, radius) {
if (! id || typeof id !== 'string' || id.length === 0) {
BoostSpatialIndex.prototype.addCircle = function addCircle(
id,
lat,
lon,
radius,
) {
if (!id || typeof id !== "string" || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

if ([lat, lon, radius].findIndex(v => typeof v !== 'number') !== -1) {
throw new Error('Invalid coordinates parameter');
if ([lat, lon, radius].findIndex((v) => typeof v !== "number") !== -1) {
throw new Error("Invalid coordinates parameter");
}

return this.spatialIndex.addCircle(id, lat, lon, radius);
Expand All @@ -69,17 +86,23 @@ BoostSpatialIndex.prototype.addCircle = function addCircle (id, lat, lon, radius
* @param {Number} innerRadius in meters
* @return {boolean}
*/
BoostSpatialIndex.prototype.addAnnulus = function addAnnulus (id, lat, lon, outer, inner) {
if (! id || typeof id !== 'string' || id.length === 0) {
BoostSpatialIndex.prototype.addAnnulus = function addAnnulus(
id,
lat,
lon,
outer,
inner,
) {
if (!id || typeof id !== "string" || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

if ([lat, lon, outer, inner].findIndex(v => typeof v !== 'number') !== -1) {
throw new Error('Invalid coordinates parameter');
if ([lat, lon, outer, inner].findIndex((v) => typeof v !== "number") !== -1) {
throw new Error("Invalid coordinates parameter");
}

if (outer <= inner) {
throw new Error('Outer radius must be strictly greater than the inner one');
throw new Error("Outer radius must be strictly greater than the inner one");
}

return this.spatialIndex.addAnnulus(id, lat, lon, outer, inner);
Expand All @@ -97,27 +120,31 @@ BoostSpatialIndex.prototype.addAnnulus = function addAnnulus (id, lat, lon, oute
* @param {Array<Array<Number>>} points
* @return {boolean}
*/
BoostSpatialIndex.prototype.addPolygon = function addPolygon (id, points) {
BoostSpatialIndex.prototype.addPolygon = function addPolygon(id, points) {
var idx;

if (! id || typeof id !== 'string' || id.length === 0) {
if (!id || typeof id !== "string" || id.length === 0) {
throw new Error('Invalid "id" parameter: must be a non-empty string');
}

if (! points || typeof points !== 'object' || ! Array.isArray(points)) {
throw new Error('Invalid points arguments');
if (!points || typeof points !== "object" || !Array.isArray(points)) {
throw new Error("Invalid points arguments");
}

idx = points.findIndex(v => {
return ! v ||
typeof v !== 'object' ||
! Array.isArray(v) ||
idx = points.findIndex((v) => {
return (
!v ||
typeof v !== "object" ||
!Array.isArray(v) ||
v.length !== 2 ||
v.find(coord => typeof coord !== 'number');
v.find((coord) => typeof coord !== "number")
);
});

if (idx !== -1) {
throw new Error('points arguments must only contain arrays, each one being a point coordinates');
throw new Error(
"points arguments must only contain arrays, each one being a point coordinates",
);
}

return this.spatialIndex.addPolygon(id, points);
Expand All @@ -130,13 +157,13 @@ BoostSpatialIndex.prototype.addPolygon = function addPolygon (id, points) {
* @param {Number} lon
* @return {Array<string>}
*/
BoostSpatialIndex.prototype.queryPoint = function queryPoint (lat, lon) {
if (typeof lat !== 'number') {
throw new Error('Invalid lat parameter');
BoostSpatialIndex.prototype.queryPoint = function queryPoint(lat, lon) {
if (typeof lat !== "number") {
throw new Error("Invalid lat parameter");
}

if (typeof lon !== 'number') {
throw new Error('Invalid lon parameter');
if (typeof lon !== "number") {
throw new Error("Invalid lon parameter");
}

return this.spatialIndex.queryPoint(lat, lon);
Expand All @@ -154,22 +181,25 @@ BoostSpatialIndex.prototype.queryPoint = function queryPoint (lat, lon) {
* @param {Array<Array<Number>>} points
* @return {Array<string>}
*/
BoostSpatialIndex.prototype.queryIntersect = function queryIntersect (points) {

if (! points || typeof points !== 'object' || ! Array.isArray(points)) {
throw new Error('Invalid points arguments');
BoostSpatialIndex.prototype.queryIntersect = function queryIntersect(points) {
if (!points || typeof points !== "object" || !Array.isArray(points)) {
throw new Error("Invalid points arguments");
}

let idx = points.findIndex(v => {
return ! v ||
typeof v !== 'object' ||
! Array.isArray(v) ||
let idx = points.findIndex((v) => {
return (
!v ||
typeof v !== "object" ||
!Array.isArray(v) ||
v.length !== 2 ||
v.find(coord => typeof coord !== 'number');
v.find((coord) => typeof coord !== "number")
);
});

if (idx !== -1) {
throw new Error('points arguments must only contain arrays, each one being point coordinates');
throw new Error(
"points arguments must only contain arrays, each one being point coordinates",
);
}

return this.spatialIndex.queryIntersect(points);
Expand All @@ -181,9 +211,9 @@ BoostSpatialIndex.prototype.queryIntersect = function queryIntersect (points) {
* @param {string} id - shape identifier to remove
* @return {boolean}
*/
BoostSpatialIndex.prototype.remove = function remove (id) {
if (! id || typeof id !== 'string' || id.length === 0) {
throw new Error('Invalid id parameter');
BoostSpatialIndex.prototype.remove = function remove(id) {
if (!id || typeof id !== "string" || id.length === 0) {
throw new Error("Invalid id parameter");
}

return this.spatialIndex.remove(id);
Expand Down
Loading
Loading