grid-assign-js
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "grid-assign-js", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "dist", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -1,4 +0,4 @@ | ||
# Grid Assignment API and Linear Assignment API | ||
# Grid Assignment | ||
This repository is a simple and general API to use the Linear Assignment Problem Algorithm. | ||
This repository is a simple and general API to use the Linear Assignment Problem Algorithm. It also has a much higher level grid assignment API that automatically generates the grids for the screen and assigns the points to the grids. | ||
@@ -16,16 +16,50 @@ It uses the LAP-JV implemented from [here](https://github.com/Fil/lap-jv). These are almost the same, but | ||
Install via [npm](https://www.npmjs.com/package/linear-assignment-js) like this: | ||
Install via [npm](https://www.npmjs.com/package/grid-assign-js) like this: | ||
```bash | ||
npm install linear-assignment-js | ||
npm install grid-assign-js | ||
``` | ||
Then you can use it by importing the default function | ||
```javascript | ||
import * as gridAssign from "grid-assign-js"; | ||
``` | ||
### Grid Assignment | ||
```javascript | ||
import * as linearAssignment from "linear-assignment-js"; | ||
// const linearAssignment = require("linear-assignment-js"); | ||
const pointsToAssign = [ | ||
[5, 4], | ||
[1, 0], | ||
[1, 1], | ||
[-1, 1], | ||
]; | ||
// get grid API | ||
const { grid } = gridAssign; | ||
// get grid assignments for a 2 by 2 grid | ||
// in a 500 by 500 pixels space | ||
const { assignments } = grid.autoGridAssignment({ | ||
points: pointsToAssign, | ||
numColumns: 2, | ||
numRows: 2, | ||
screenWidth: 500, // 500 px | ||
screenHeight: 500, // 500 px | ||
}); | ||
/* | ||
assignments = { | ||
gridPoint: point; | ||
gridWidth: number; | ||
gridHeight: number; | ||
assignedPoint: point; | ||
assignedPointIndex: number; | ||
}[] | ||
yeah it's that easy | ||
*/ | ||
``` | ||
Then you can interface with the function like this | ||
### Linear Assignment Problem | ||
@@ -44,3 +78,3 @@ ```javascript | ||
const assignments = linearAssignment.assign({ | ||
const assignments = gridAssign.assign({ | ||
points: peopleCallingTaxiLocations, | ||
@@ -52,3 +86,3 @@ assignTo: taxiDriverLocations, | ||
output interpretation: | ||
assignment = [ 1, 2 ] | ||
assignments = [ 1, 2 ] | ||
taxi driver 0 was assigned to person 1 at location (1,0) | ||
@@ -58,1 +92,3 @@ taxi driver 1 was assigned to person 2 at location (1,1) | ||
``` | ||
For more detail take a look at the types and the test examples :) |
40753
91