New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gridfinder

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gridfinder - npm Package Compare versions

Comparing version 1.8.0 to 1.14.0

603

__snapshots__/lib/lib.test.js

@@ -1,477 +0,144 @@

exports['findGrid perfect clicks findGrid 1'] = {
"name": "findGrid",
"behavior": [
{
"given": [
[
{
"x": 0,
"y": 0
},
{
"x": 100,
"y": 100
},
{
"x": 200,
"y": 200
}
]
],
"expect": {
"cellSize": {
"width": 100,
"height": 100
},
"offset": {
"x": 0,
"y": 0
}
}
},
{
"given": [
[
{
"x": 0,
"y": 0
},
{
"x": 72,
"y": 144
},
{
"x": 288,
"y": 72
}
]
],
"expect": {
"cellSize": {
"width": 72,
"height": 72
},
"offset": {
"x": 0,
"y": 0
}
}
}
]
exports['findGrid 256 farmhouse 1 1'] = {
"cellSize": {
"width": 138.04796430563303,
"height": 138.04796430563303
},
"offset": {
"x": 8.953337051496268,
"y": 70.80786793400029
}
}
exports['findGrid very good clicks findGrid 1'] = {
"name": "findGrid",
"behavior": [
{
"given": [
[
{
"x": 0,
"y": 0
},
{
"x": 110,
"y": 98
},
{
"x": 312,
"y": 302
}
]
],
"expect": {
"cellSize": {
"width": 104,
"height": 104
},
"offset": {
"x": 2,
"y": -5.333333333333333
}
}
}
]
exports['findGrid 256 farmhouse bad +1 1'] = {
"cellSize": {
"width": 8.28860869891713,
"height": 8.28860869891713
},
"offset": {
"x": -4.139983052459229,
"y": -4.144304349458196
}
}
exports['findGrid 60x60 https://i.redd.it/9xy7jbjw4wv11.jpg findGrid 1'] = {
"name": "findGrid",
"behavior": [
{
"given": [
[
{
"x": 595.977798334875,
"y": 428.898055242918
},
{
"x": 595.977798334875,
"y": 306.6018226234514
},
{
"x": 721.7187789084181,
"y": 306.6018226234514
},
{
"x": 721.7187789084181,
"y": 431.48177846727293
}
]
],
"expect": {
"cellSize": {
"width": 125.74098057354308,
"height": 125.74098057354308
},
"offset": {
"x": -32.72710453284037,
"y": 54.04341830541574
}
}
},
{
"given": [
[
{
"x": 595.977798334875,
"y": 428.898055242918
},
{
"x": 595.977798334875,
"y": 306.6018226234514
},
{
"x": 721.7187789084181,
"y": 306.6018226234514
},
{
"x": 721.7187789084181,
"y": 431.48177846727293
},
{
"x": 657.1258094357077,
"y": 375.50110860624955
}
]
],
"expect": {
"cellSize": {
"width": 62.87049028677154,
"height": 62.87049028677154
},
"offset": {
"x": 29.798889916743384,
"y": -7.406024207960582
}
}
},
{
"given": [
[
{
"x": 595.977798334875,
"y": 428.898055242918
},
{
"x": 595.977798334875,
"y": 306.6018226234514
},
{
"x": 721.7187789084181,
"y": 306.6018226234514
},
{
"x": 721.7187789084181,
"y": 431.48177846727293
},
{
"x": 657.9870490286771,
"y": 429.75929631770305
}
]
],
"expect": {
"cellSize": {
"width": 62.87049028677154,
"height": 62.87049028677154
},
"offset": {
"x": 29.971137835337277,
"y": -9.12848472302419
}
}
},
{
"given": [
[
{
"x": 1511.4754856614245,
"y": 1746.5968996639313
},
{
"x": 1580.3746530989824,
"y": 1917.9838735461417
},
{
"x": 1575.2072155411654,
"y": 2163.43757985986
},
{
"x": 1575.2072155411654,
"y": 1979.9932309306596
},
{
"x": 1637.2164662349676,
"y": 1919.7063556957116
}
]
],
"expect": {
"cellSize": {
"width": 59.54866859941837,
"height": 59.54866859941837
},
"offset": {
"x": 27.630823630663443,
"y": 16.16672531810564
}
}
}
]
exports['findGrid 256 farmhouse bad +2 1'] = {
"cellSize": {
"width": 255.01325932778298,
"height": 255.01325932778298
},
"offset": {
"x": 20.997841504778442,
"y": 17.95427024556227
}
}
exports['findGrid 256x256 https://i.redd.it/m6l4go8l56v51.jpg findGrid 1'] = {
"name": "findGrid",
"behavior": [
{
"given": [
[
{
"x": 2597.300613496932,
"y": 1813.9973492199026
},
{
"x": 5119.018404907975,
"y": 2562.9583759811503
},
{
"x": 5119.018404907975,
"y": 2830.9352571159084
}
]
],
"expect": {
"cellSize": {
"width": 252.17177914110434,
"height": 252.17177914110434
},
"offset": {
"x": 75.58282208588844,
"y": 49.027055455346535
}
}
},
{
"given": [
[
{
"x": 5119.018404907975,
"y": 2830.935257115908
},
{
"x": 5112.147239263804,
"y": 2562.95837598115
},
{
"x": 3600.490797546012,
"y": 2549.215971820393
}
]
],
"expect": {
"cellSize": {
"width": 303.70552147239266,
"height": 303.70552147239266
},
"offset": {
"x": -46.265848670757045,
"y": 116.82385603587807
}
}
},
{
"given": [
[
{
"x": 1288.880666049953,
"y": 4604.322132248466
},
{
"x": 2573.617021276596,
"y": 1811.061000713393
},
{
"x": 3601.406105457909,
"y": 2557.035783615935
}
]
],
"expect": {
"cellSize": {
"width": 8.28860869891713,
"height": 8.28860869891713
},
"offset": {
"x": -4.140417879597938,
"y": -4.144304349458214
}
}
},
{
"given": [
[
{
"x": 1288.880666049953,
"y": 4604.322132248466
},
{
"x": 2573.617021276596,
"y": 1811.061000713393
},
{
"x": 3601.406105457909,
"y": 2557.035783615935
},
{
"x": 5114.079555966698,
"y": 1811.061000713393
}
]
],
"expect": {
"cellSize": {
"width": 25.672475771253318,
"height": 25.672475771253318
},
"offset": {
"x": 6.03567415207084,
"y": -12.576214544428069
}
}
},
{
"given": [
[
{
"x": 1288.880666049953,
"y": 4604.322132248466
},
{
"x": 2573.617021276596,
"y": 1811.061000713393
},
{
"x": 3601.406105457909,
"y": 2557.035783615935
},
{
"x": 5114.079555966698,
"y": 1811.061000713393
},
{
"x": 4102.867715078631,
"y": 3332.020696964687
}
]
],
"expect": {
"cellSize": {
"width": 255.01325932778298,
"height": 255.01325932778298
},
"offset": {
"x": 20.997841504778442,
"y": 17.95427024556227
}
}
},
{
"given": [
[
{
"x": 1288.880666049953,
"y": 4604.322132248466
},
{
"x": 2573.617021276596,
"y": 1811.061000713393
},
{
"x": 3601.406105457909,
"y": 2557.035783615935
},
{
"x": 5114.079555966698,
"y": 1811.061000713393
},
{
"x": 4102.867715078631,
"y": 3332.020696964687
},
{
"x": 3327.881591119334,
"y": 1790.3394789661
},
{
"x": 3601.406105457909,
"y": 3323.732088265769
},
{
"x": 2565.328399629972,
"y": 3323.732088265769
},
{
"x": 1284.736355226642,
"y": 3854.203044996466
},
{
"x": 2047.289546716003,
"y": 3858.347349345924
},
{
"x": 2043.145235892692,
"y": 4608.466436597925
},
{
"x": 2569.472710453284,
"y": 4608.466436597925
},
{
"x": 5114.079555966698,
"y": 2561.180087965393
},
{
"x": 5122.368177613321,
"y": 2822.271261981283
},
{
"x": 5114.079555966698,
"y": 3323.732088265769
}
]
],
"expect": {
"cellSize": {
"width": 255.84212149244524,
"height": 255.84212149244524
},
"offset": {
"x": 6.207256655360515,
"y": 6.110142328299374
}
}
}
]
exports['findGrid 256 farmhouse bad +a lot 1'] = {
"cellSize": {
"width": 255.84212149244524,
"height": 255.84212149244524
},
"offset": {
"x": 6.207256655360515,
"y": 6.110142328299374
}
}
exports['findGrid 256 farmhouse bad 1'] = {
"cellSize": {
"width": 8.28860869891713,
"height": 8.28860869891713
},
"offset": {
"x": -4.140417879597938,
"y": -4.144304349458214
}
}
exports['findGrid 256 farmhouse min 1'] = {
"cellSize": {
"width": 53.6535700300222,
"height": 53.6535700300222
},
"offset": {
"x": 21.929252055866073,
"y": -11.780323912012099
}
}
exports['findGrid 60 perspective_inn 1 1'] = {
"cellSize": {
"width": 59.54866859941837,
"height": 59.54866859941837
},
"offset": {
"x": 27.630823630663443,
"y": 16.16672531810564
}
}
exports['findGrid 60 perspective_inn refine_grid 1'] = {
"cellSize": {
"width": 125.74098057354308,
"height": 125.74098057354308
},
"offset": {
"x": -32.72710453284037,
"y": 54.04341830541574
}
}
exports['findGrid 60 perspective_inn refine_grid half 1 1'] = {
"cellSize": {
"width": 62.87049028677154,
"height": 62.87049028677154
},
"offset": {
"x": 29.798889916743384,
"y": -7.406024207960582
}
}
exports['findGrid 60 perspective_inn refine_grid half 2 1'] = {
"cellSize": {
"width": 62.87049028677154,
"height": 62.87049028677154
},
"offset": {
"x": 29.971137835337277,
"y": -9.12848472302419
}
}
exports['findGrid perfect clicks 1 1'] = {
"cellSize": {
"width": 100,
"height": 100
},
"offset": {
"x": 0,
"y": 0
}
}
exports['findGrid perfect clicks 2 1'] = {
"cellSize": {
"width": 72,
"height": 72
},
"offset": {
"x": 0,
"y": 0
}
}
exports['findGrid very good clicks 1'] = {
"cellSize": {
"width": 104,
"height": 104
},
"offset": {
"x": 2,
"y": -5.333333333333333
}
}
exports['findOffset works findOffset 1'] = {

@@ -478,0 +145,0 @@ "name": "findOffset",

@@ -50,31 +50,43 @@ import Point from "./Point.js";

let relPoints = points.slice(1).map(({x, y}) => new Point(x, y).sub(origin));
points = points.map(({x, y}) => new Point(x, y));
let candidates = [];
for (let cells = minDim/8 |0; cells > 0; cells--) {
let minPx = minDim / cells;
let maxCells = Math.round(maxDim/minPx);
let px = maxDim/maxCells;
let minErr = Infinity;
let bestCellSize;
let bestOffset;
for (let cells = 1; cells < minDim/8; cells++) {
let minCellSize = minDim / cells;
let maxCells = Math.round(maxDim/minCellSize);
let cellSize = maxDim/maxCells;
let off = findOffsetPoint(cellSize, points, origin);
let err = 0;
for (let point of relPoints) {
err += point.roundError(px).div(px).lengthSquared();
for (let point of points) {
err += point.sub(off).roundError(cellSize).div(cellSize).lengthSquared();
}
candidates.push({px, err});
if (err < minErr) {
minErr = err;
bestCellSize = cellSize;
bestOffset = off;
}
}
candidates.sort((a, b) => a.err - b.err || b.px - a.px);
let cellSize = candidates[0].px;
let cellSize = bestCellSize;
return {
cellSize: {width: cellSize, height: cellSize},
offset: calculateOffset?
findOffset({
cellSize,
points,
reference: origin,
}) : null,
offset: calculateOffset? bestOffset : null,
}
}
function findOffsetPoint(cellSize, points, reference) {
reference = reference || points.reduce((a, b) => ({x: Math.min(a.x, b.x), y: Math.min(a.y, b.y)}));
reference = new Point(reference.x, reference.y);
return points
.map(({x, y}) => new Point(x, y).sub(reference).roundError(cellSize))
.reduce((a, b) => a.add(b))
.div(points.length)
.add(reference.roundError(cellSize));
}
/** Find the offset of the grid.

@@ -94,12 +106,4 @@ *

}) {
reference = reference || points.reduce((a, b) => ({x: Math.min(a.x, b.x), y: Math.min(a.y, b.y)}));
reference = new Point(reference.x, reference.y);
let {x, y} = points
.map(({x, y}) => new Point(x, y).sub(reference).roundError(cellSize))
.reduce((a, b) => a.add(b))
.div(points.length)
.add(reference.roundError(cellSize));
let {x, y} = findOffsetPoint(cellSize, points, reference);
return {x, y};
}

@@ -6,102 +6,149 @@ import * as gridfinder from "./lib.js";

describe("findGrid", () => {
it("perfect clicks", () => {
snapshot(gridfinder.findGrid,
[[
Object.entries({
"perfect clicks": {
sub: {
"1": {
width: 100,
points: [
{x: 0, y: 0},
{x: 100, y: 100},
{x: 200, y: 200},
],
},
"2": {
width: 72,
points: [
{x: 0, y: 0},
{x: 72, y: 144},
{x: 288, y: 72},
],
},
},
},
"very good clicks": {
width: 100,
points: [
{x: 0, y: 0},
{x: 100, y: 100},
{x: 200, y: 200},
]],
[[
{x: 0, y: 0},
{x: 72, y: 144},
{x: 288, y: 72},
]]);
});
it("very good clicks", () => {
snapshot(gridfinder.findGrid,
[[
{x: 0, y: 0},
{x: 110, y: 98},
{x: 312, y: 302},
]]);
});
],
},
"60 perspective_inn": {
bg: "https://i.redd.it/9xy7jbjw4wv11.jpg",
width: 60,
sub: {
refine_grid: {
points: [
{x: 595.977798334875, y: 428.898055242918},
{x: 595.977798334875, y: 306.6018226234514},
{x: 721.7187789084181, y: 306.6018226234514},
{x: 721.7187789084181, y: 431.48177846727293},
],
sub: {
"half 1": {
points: [
{x: 657.1258094357077, y: 375.50110860624955},
],
},
"half 2": {
points: [
{x: 657.9870490286771, y: 429.75929631770305},
],
},
},
},
"1": {
points: [
{x: 1511.4754856614245, y: 1746.5968996639313},
{x: 1580.3746530989824, y: 1917.9838735461417},
{x: 1575.2072155411654, y: 2163.43757985986},
{x: 1575.2072155411654, y: 1979.9932309306596},
{x: 1637.2164662349676, y: 1919.7063556957116},
],
},
},
},
"256 farmhouse": {
bg: "https://i.redd.it/m6l4go8l56v51.jpg",
width: 256,
sub: {
min: {
points: [
{x: 2597.300613496932, y: 1813.9973492199026},
{x: 5119.018404907975, y: 2562.9583759811503},
{x: 5119.018404907975, y: 2830.9352571159084},
],
},
"1": {
points: [
// Too small.
{x: 5119.018404907975, y: 2830.935257115908},
{x: 5112.147239263804, y: 2562.958375981150},
{x: 3600.490797546012, y: 2549.215971820393},
],
},
bad: {
points: [
// Selects a too small grid!
{x: 1288.880666049953, y: 4604.322132248466},
{x: 2573.617021276596, y: 1811.061000713393},
{x: 3601.406105457909, y: 2557.035783615935},
],
sub: {
"+1": {
points: [
{x: 3601.406105457909, y: 2557.035783615935},
],
},
"+2": {
points: [
{x: 5114.079555966698, y: 1811.061000713393},
{x: 4102.867715078631, y: 3332.020696964687},
],
},
"+a lot": {
// Lots and lots of points, good result.
points: [
{x: 5114.079555966698, y: 1811.061000713393},
{x: 4102.867715078631, y: 3332.020696964687},
{x: 3327.881591119334, y: 1790.339478966100},
{x: 3601.406105457909, y: 3323.732088265769},
{x: 2565.328399629972, y: 3323.732088265769},
{x: 1284.736355226642, y: 3854.203044996466},
{x: 2047.289546716003, y: 3858.347349345924},
{x: 2043.145235892692, y: 4608.466436597925},
{x: 2569.472710453284, y: 4608.466436597925},
{x: 5114.079555966698, y: 2561.180087965393},
{x: 5122.368177613321, y: 2822.271261981283},
{x: 5114.079555966698, y: 3323.732088265769},
],
},
},
},
},
},
}).forEach(function run([name, cfg]) {
let {bg, points=[], sub={}, width} = cfg;
it("60x60 https://i.redd.it/9xy7jbjw4wv11.jpg", () => {
snapshot(gridfinder.findGrid,
[[
// Big grid!
{x: 595.977798334875, y: 428.898055242918},
{x: 595.977798334875, y: 306.6018226234514},
{x: 721.7187789084181, y: 306.6018226234514},
{x: 721.7187789084181, y: 431.48177846727293},
]], [[
// Actually I want half the size!
{x: 595.977798334875, y: 428.898055242918},
{x: 595.977798334875, y: 306.6018226234514},
{x: 721.7187789084181, y: 306.6018226234514},
{x: 721.7187789084181, y: 431.48177846727293},
{x: 657.1258094357077, y: 375.50110860624955},
]], [[
// Half the size another way.
{x: 595.977798334875, y: 428.898055242918},
{x: 595.977798334875, y: 306.6018226234514},
{x: 721.7187789084181, y: 306.6018226234514},
{x: 721.7187789084181, y: 431.48177846727293},
{x: 657.9870490286771, y: 429.75929631770305},
]], [[
{x: 1511.4754856614245, y: 1746.5968996639313},
{x: 1580.3746530989824, y: 1917.9838735461417},
{x: 1575.2072155411654, y: 2163.43757985986},
{x: 1575.2072155411654, y: 1979.9932309306596},
{x: 1637.2164662349676, y: 1919.7063556957116}
]]);
})
if (points.length) {
it(name, function() {
snapshot(gridfinder.findGrid(points));
});
}
it("256x256 https://i.redd.it/m6l4go8l56v51.jpg", () => {
snapshot(gridfinder.findGrid,
[[
{x: 2597.300613496932, y: 1813.9973492199026},
{x: 5119.018404907975, y: 2562.9583759811503},
{x: 5119.018404907975, y: 2830.9352571159084},
]], [[
{x: 5119.018404907975, y: 2830.935257115908},
{x: 5112.147239263804, y: 2562.958375981150},
{x: 3600.490797546012, y: 2549.215971820393},
]], [[
// Selects a too small grid!
{x: 1288.880666049953, y: 4604.322132248466},
{x: 2573.617021276596, y: 1811.061000713393},
{x: 3601.406105457909, y: 2557.035783615935},
]], [[
// Larger, but still too small.
{x: 1288.880666049953, y: 4604.322132248466},
{x: 2573.617021276596, y: 1811.061000713393},
{x: 3601.406105457909, y: 2557.035783615935},
{x: 5114.079555966698, y: 1811.061000713393},
]], [[
// Perfection.
{x: 1288.880666049953, y: 4604.322132248466},
{x: 2573.617021276596, y: 1811.061000713393},
{x: 3601.406105457909, y: 2557.035783615935},
{x: 5114.079555966698, y: 1811.061000713393},
{x: 4102.867715078631, y: 3332.020696964687},
]], [[
// Lots and lots of points, good result.
{x: 1288.880666049953, y: 4604.322132248466},
{x: 2573.617021276596, y: 1811.061000713393},
{x: 3601.406105457909, y: 2557.035783615935},
{x: 5114.079555966698, y: 1811.061000713393},
{x: 4102.867715078631, y: 3332.020696964687},
{x: 3327.881591119334, y: 1790.339478966100},
{x: 3601.406105457909, y: 3323.732088265769},
{x: 2565.328399629972, y: 3323.732088265769},
{x: 1284.736355226642, y: 3854.203044996466},
{x: 2047.289546716003, y: 3858.347349345924},
{x: 2043.145235892692, y: 4608.466436597925},
{x: 2569.472710453284, y: 4608.466436597925},
{x: 5114.079555966698, y: 2561.180087965393},
{x: 5122.368177613321, y: 2822.271261981283},
{x: 5114.079555966698, y: 3323.732088265769},
]]);
let subs = Object.entries(sub)
describe(name, function() {
for (let [sub_name, {points: p=[], ...rest}] of subs) {
run([sub_name, {
...cfg,
points: [...points, ...p],
sub: undefined,
...rest,
}]);
}
});
assert(points.length || subs.length);
})

@@ -200,3 +247,3 @@ })

});
})
})
});
});
{
"name": "gridfinder",
"version": "1.8.0",
"version": "1.14.0",
"license": "Apache 2.0",

@@ -27,2 +27,3 @@ "homepage": "https://gridfinder.kevincox.ca",

"snap-shot-it": {
"sortSnapshots": true,
"useRelativePath": true

@@ -29,0 +30,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc