Skip to content

Commit

Permalink
Merge pull request #43 from tschaub/updates
Browse files Browse the repository at this point in the history
Updated linter
  • Loading branch information
tschaub authored Nov 18, 2024
2 parents 313bed7 + 6465031 commit 4a27dd1
Show file tree
Hide file tree
Showing 28 changed files with 5,335 additions and 6,763 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
versioning-strategy: increase-if-necessary
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 22
- name: Install dependencies
run: npm ci
- name: Test
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import shared from 'eslint-config-tschaub';

export default [...shared];
47 changes: 31 additions & 16 deletions lib/bitbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
const orRanges = require('./ranges').or;
const andRanges = require('./ranges').and;
const orRanges = require('./ranges.js').or;
const andRanges = require('./ranges.js').and;

/**
* @typedef {Object} Config
* @property {number} minI The minI.
* @property {number} maxI The maxI.
* @property {number} minJ The minJ.
* @property {number} maxJ The maxJ.
* @property {number} resolution The resolution.
* @property {Array<number>} origin The origin.
* @property {Array} ranges The ranges.
*/

/**
* @param {Config} config The config.
*/
function BitBox(config) {
this.minI = config.minI;
this.maxI = config.maxI;
Expand All @@ -12,7 +26,7 @@ function BitBox(config) {
this._area = NaN;
}

BitBox.prototype.getArea = function() {
BitBox.prototype.getArea = function () {
if (isNaN(this._area)) {
let area = 0;
const cell = this.resolution * this.resolution;
Expand All @@ -27,7 +41,7 @@ BitBox.prototype.getArea = function() {
return this._area;
};

BitBox.prototype.get = function(i, j) {
BitBox.prototype.get = function (i, j) {
let set = false;
if (j in this._ranges && i >= this.minI && i <= this.maxI) {
const range = this._ranges[j];
Expand All @@ -45,7 +59,7 @@ BitBox.prototype.get = function(i, j) {
return set;
};

BitBox.prototype.or = function(bits) {
BitBox.prototype.or = function (bits) {
if (this.resolution !== bits.resolution) {
throw new Error('BitBoxes must have the same resolution');
}
Expand All @@ -70,11 +84,11 @@ BitBox.prototype.or = function(bits) {
maxJ: Math.max(this.maxJ, bits.maxJ),
resolution: this.resolution,
origin: this.origin,
ranges: ranges
ranges: ranges,
});
};

BitBox.prototype.and = function(bits) {
BitBox.prototype.and = function (bits) {
if (this.resolution !== bits.resolution) {
throw new Error('BitBoxes must have the same resolution');
}
Expand All @@ -95,7 +109,7 @@ BitBox.prototype.and = function(bits) {
minI = Math.min(minI, intersectingRanges[0]);
maxI = Math.max(
maxI,
intersectingRanges[intersectingRanges.length - 1]
intersectingRanges[intersectingRanges.length - 1],
);
ranges[j] = intersectingRanges;
}
Expand All @@ -108,11 +122,11 @@ BitBox.prototype.and = function(bits) {
maxJ: maxJ,
resolution: this.resolution,
origin: this.origin,
ranges: ranges
ranges: ranges,
});
};

BitBox.prototype.forEachRange = function(callback) {
BitBox.prototype.forEachRange = function (callback) {
for (let j in this._ranges) {
j = Number(j);
const ranges = this._ranges[j];
Expand All @@ -125,8 +139,8 @@ BitBox.prototype.forEachRange = function(callback) {
}
};

BitBox.prototype.forEach = function(callback) {
this.forEachRange(function(minI, maxI, j) {
BitBox.prototype.forEach = function (callback) {
this.forEachRange(function (minI, maxI, j) {
for (let i = minI; i <= maxI; ++i) {
const more = callback(i, j);
if (more === false) {
Expand All @@ -139,10 +153,10 @@ BitBox.prototype.forEach = function(callback) {
const portions = {
NONE: 0,
SOME: 1,
ALL: 2
ALL: 2,
};

BitBox.prototype.contains = function(minI, minJ, maxI, maxJ) {
BitBox.prototype.contains = function (minI, minJ, maxI, maxJ) {
const testRanges = [minI, maxI];
let portion = portions.NONE;
for (let j = minJ; j <= maxJ; ++j) {
Expand Down Expand Up @@ -177,7 +191,8 @@ BitBox.prototype.contains = function(minI, minJ, maxI, maxJ) {
return portion;
};

exports = module.exports = BitBox;
module.exports = BitBox;
exports = module.exports;
exports.ALL = portions.ALL;
exports.NONE = portions.NONE;
exports.SOME = portions.SOME;
exports.ALL = portions.ALL;
50 changes: 28 additions & 22 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const linestring = require('./linestring');
const point = require('./point');
const polygon = require('./polygon');
const BitBox = require('./bitbox');
const BitBox = require('./bitbox.js');
const linestring = require('./linestring.js');
const point = require('./point.js');
const polygon = require('./polygon.js');

const lookup = {
MultiLineString: linestring,
MultiPoint: point,
MultiPolygon: polygon
MultiPolygon: polygon,
};

/**
* @param {Object} data The data.
* @param {Object} options The options.
* @return {Object} The bits.
*/
function getBits(data, options) {
let bits, newBits, i, ii;
switch (data.type) {
Expand Down Expand Up @@ -72,22 +77,14 @@ function getBits(data, options) {
return bits;
}

exports = module.exports = getBits;
module.exports = getBits;
exports = module.exports;

exports.or = function(datas, options) {
let union = null;
for (let i = 0, ii = datas.length; i < ii; ++i) {
const bits = getBits(datas[i], options);
if (!union) {
union = bits;
} else {
union = union.or(bits);
}
}
return union;
};
exports.ALL = BitBox.ALL;
exports.NONE = BitBox.NONE;
exports.SOME = BitBox.SOME;

exports.and = function(datas, options) {
exports.and = function (datas, options) {
let intersection = null;
for (let i = 0, ii = datas.length; i < ii; ++i) {
const bits = getBits(datas[i], options);
Expand All @@ -100,6 +97,15 @@ exports.and = function(datas, options) {
return intersection;
};

exports.NONE = BitBox.NONE;
exports.SOME = BitBox.SOME;
exports.ALL = BitBox.ALL;
exports.or = function (datas, options) {
let union = null;
for (let i = 0, ii = datas.length; i < ii; ++i) {
const bits = getBits(datas[i], options);
if (!union) {
union = bits;
} else {
union = union.or(bits);
}
}
return union;
};
10 changes: 5 additions & 5 deletions lib/linestring.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const BitBox = require('./bitbox');
const sortAndMerge = require('./ranges').sortAndMerge;
const prepare = require('./segments').prepareLineString;
const BitBox = require('./bitbox.js');
const sortAndMerge = require('./ranges.js').sortAndMerge;
const prepare = require('./segments.js').prepareLineString;

exports.getBits = function(coordinates, options) {
exports.getBits = function (coordinates, options) {
options = options || {};
const resolution = options.resolution || 1;
const origin = options.origin || [0, 0];
Expand Down Expand Up @@ -77,6 +77,6 @@ exports.getBits = function(coordinates, options) {
minJ: quantized.minJ,
maxJ: quantized.maxJ,
origin: origin,
resolution: resolution
resolution: resolution,
});
};
6 changes: 3 additions & 3 deletions lib/point.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const BitBox = require('./bitbox');
const BitBox = require('./bitbox.js');

exports.getBits = function(coordinates, options) {
exports.getBits = function (coordinates, options) {
options = options || {};
const resolution = options.resolution || 1;
const origin = options.origin || [0, 0];
Expand All @@ -16,6 +16,6 @@ exports.getBits = function(coordinates, options) {
minJ: j,
maxJ: j,
origin: origin,
resolution: resolution
resolution: resolution,
});
};
17 changes: 11 additions & 6 deletions lib/polygon.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const BitBox = require('./bitbox');
const sortAndMerge = require('./ranges').sortAndMerge;
const prepare = require('./segments').preparePolygon;
const instructions = require('./segments').instructions;
const BitBox = require('./bitbox.js');
const sortAndMerge = require('./ranges.js').sortAndMerge;
const prepare = require('./segments.js').preparePolygon;
const instructions = require('./segments.js').instructions;

/**
* @param {number} instruction The instruction.
* @param {number} test The test.
* @return {boolean} The instruction includes the test.
*/
function includes(instruction, test) {
return (instruction & test) === test;
}

exports.getBits = function(coordinates, options) {
exports.getBits = function (coordinates, options) {
options = options || {};
const resolution = options.resolution || 1;
const origin = options.origin || [0, 0];
Expand Down Expand Up @@ -114,6 +119,6 @@ exports.getBits = function(coordinates, options) {
minJ: minJ,
maxJ: maxJ,
resolution: resolution,
origin: origin
origin: origin,
});
};
Loading

0 comments on commit 4a27dd1

Please sign in to comment.