mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-10-30 20:41:18 +00:00
Add clusteredCellsDensity function to extramath.js
Introduces clusteredCellsDensity to evaluate density of selected cells within a grid. Updates module version to 1.0.0 and exports the new function for external use.
This commit is contained in:
parent
83fb136957
commit
717b141cb7
|
|
@ -70,13 +70,40 @@ function cartesianProduct(arr) {
|
|||
}, [[]])
|
||||
}
|
||||
|
||||
function clusteredCellsDensity(numbers, size, minDensity) {
|
||||
if (!numbers || !numbers.length) return false;
|
||||
if (typeof minDensity === 'undefined') minDensity = 0.6;
|
||||
if (typeof size !== 'number' || size <= 0) size = 4; // default grid size = 4
|
||||
|
||||
// 1. Convert cell number → (x,y) coordinates
|
||||
var coords = numbers.map(function (n) {
|
||||
return { x: n % size, y: Math.floor(n / size) };
|
||||
});
|
||||
|
||||
var xs = coords.map(function (c) { return c.x; });
|
||||
var ys = coords.map(function (c) { return c.y; });
|
||||
|
||||
// 2. Compute bounding box of selected cells
|
||||
var minX = Math.min.apply(Math, xs), maxX = Math.max.apply(Math, xs);
|
||||
var minY = Math.min.apply(Math, ys), maxY = Math.max.apply(Math, ys);
|
||||
|
||||
// 3. Compute area and density
|
||||
var w = maxX - minX + 1;
|
||||
var h = maxY - minY + 1;
|
||||
var boxArea = w * h;
|
||||
|
||||
var density = coords.length / boxArea;
|
||||
return density >= minDensity;
|
||||
}
|
||||
|
||||
exports.DTM = DTM;
|
||||
exports.arrayCos = arrayCos;
|
||||
exports.measureSimilarity = measureSimilarity;
|
||||
exports.export_measureSimilarity = export_measureSimilarity;
|
||||
exports.cartesianProduct = cartesianProduct;
|
||||
exports.clusteredCellsDensity = clusteredCellsDensity;
|
||||
|
||||
exports.VERSIONINFO = "ExtraMath module (extramath.js) version 0.0.5";
|
||||
exports.VERSIONINFO = "ExtraMath module (extramath.js) version 1.0.0";
|
||||
exports.AUTHOR = "gnh1201@catswords.re.kr";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user