Skip to content

Commit

Permalink
Update iterative greedy dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
furstenheim committed May 2, 2017
1 parent f169561 commit 2f8da7e
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 17,204 deletions.
17,274 changes: 90 additions & 17,184 deletions dist/automatic-labelling.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path')
module.exports = function (config) {
config.set({
// ... normal karma configuration
Expand Down Expand Up @@ -31,4 +30,4 @@ module.exports = function (config) {
dir: 'coverage/'
}
})
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/automatic-labelling.js",
"scripts": {
"gulp": "gulp",
"browser-test": "karma start karma.conf.js"
"test-watch": "karma start karma.conf.js"
},
"reposistory": {
"type": "git",
Expand Down Expand Up @@ -49,7 +49,7 @@
"webworkify": "^1.4.0"
},
"dependencies": {
"iterative-greedy": "0.0.4"
"iterative-greedy": "1.0.0"
},
"peerDependencies": {
"lodash": "^4.16.2"
Expand Down
17 changes: 11 additions & 6 deletions src/extended-point-methods.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use strict'
module.exports = {updateAvailableSpace, promoteLabelToRectangle,
computeInitialAvailabeSpaces, resetAvailableSpace, updateMinima, translateLabel}
module.exports = {
updateAvailableSpace,
promoteLabelToRectangle,
computeInitialAvailabeSpaces,
resetAvailableSpace,
updateMinima,
translateLabel
}

const pointSegmentIntersection = require('./point-segment-intersection').pointSegmentIntersection
const labelRectangleIntersection = require('./label-rectangle-intersection').labelRectangleIntersection
const rayRectangleIntersection = require('./ray-rectangle-intersection').rayRectangleIntersection
const multiInterval = require('./multi-interval').multiInterval
Expand All @@ -28,8 +33,8 @@ function computeInitialAvailabeSpaces (extendedPoints, params) {
const radius = params.radius
const bbox = params.bbox
for (let pi of extendedPoints) {
for (let rij of pi.rays){
rij.initiallyAvailable = multiInterval([interval(0, Number.POSITIVE_INFINITY)])
for (let rij of pi.rays) {
rij.initiallyAvailable = multiInterval([interval(0, Number.POSITIVE_INFINITY)])
for (let pk of extendedPoints) {
const rectangle = {top: pk.position.y + radius, bottom: pk.position.y - radius, left: pk.position.x - radius, right: pk.position.x + radius, width: 2 * radius, height: 2 * radius}
rij.initiallyAvailable.remove(labelRectangleIntersection(rectangle, pi.label, rij.vector, pi.position))
Expand Down Expand Up @@ -76,4 +81,4 @@ function translateLabel (extendedPoint, vi) {
left: point.x + vi.x - label.width / 2,
right: point.x + vi.x + label.width / 2
}
}
}
2 changes: 0 additions & 2 deletions src/find-best-ray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ const labelSegmentIntersection = require('./label-segment-intersection').labelSe
const rayRectangleIntersection = require('./ray-rectangle-intersection').rayRectangleIntersection
const raySegmentIntersection = require('./ray-segment-intersection').raySegmentIntersection
const multiInterval = require('./multi-interval').multiInterval
const interval = require('./interval').interval
const utils = require('./utils')


async function findBestRay (pointsToLabel, pointsNotToLabel) {
// We follow the article page 4 Algorithm 1
var P = pointsToLabel
Expand Down
2 changes: 1 addition & 1 deletion src/label-rectangle-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function labelRectangleIntersection (lk, li, vi, pi) {
let max = Number.POSITIVE_INFINITY
if (vi.y !== 0) {
const firstIntersection = (lk.height / 2 + li.height / 2 + (lk.top + lk.bottom) / 2 - pi.y) / vi.y
const secondIntersection = (- lk.height / 2 - li.height / 2 + (lk.top + lk.bottom) / 2 - pi.y) / vi.y
const secondIntersection = (-lk.height / 2 - li.height / 2 + (lk.top + lk.bottom) / 2 - pi.y) / vi.y
// Multiplying by a negative sign reverses an inequality
if (vi.y > 0) {
max = Math.min(max, firstIntersection)
Expand Down
3 changes: 1 addition & 2 deletions src/main-algorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ module.exports = function (self) {
function mainAlgorithm (extendedPoints, params = {}) {
NUMBER_OF_RAYS = _.isNumber(params.NUMBER_OF_RAYS) ? params.NUMBER_OF_RAYS : 3
const MAX_NUMBER_OF_ITERATIONS = _.isNumber(params.MAX_NUMBER_OF_ITERATIONS) ? params.MAX_NUMBER_OF_ITERATIONS : 1
const isWebgl = params.isWebgl
computeRays(extendedPoints)
extendedPointMethods.computeInitialAvailabeSpaces(extendedPoints, {radius: params.radius || 2, bbox: params.bbox})
extendedPoints.forEach(function (p) {
extendedPointMethods.resetAvailableSpace(p)
extendedPointMethods.updateAvailableSpace(p)
})
const possiblePoints = extendedPoints.filter(p => p.availableMeasure > 0)
return iterativeGreedy.solve(_.partialRight(rayIntersection, isWebgl, {}), possiblePoints, resetFunction, {serializeFunction, MAX_NUMBER_OF_ITERATIONS})
return iterativeGreedy.solve(_.partialRight(rayIntersection), possiblePoints, resetFunction, {serializeFunction, MAX_NUMBER_OF_ITERATIONS})
}

function computeRays (extendedPoints) {
Expand Down
2 changes: 1 addition & 1 deletion src/ray-rectangle-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ function rayRectangleIntersection (lk, vi, pi) {
return intersection
}
return interval(intersection.start, Number.POSITIVE_INFINITY)
}
}
8 changes: 4 additions & 4 deletions src/segment-segment-intersection.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module.exports = {segmentSegmentIntersection}
// A point pi moves with vi, a segment is defined with pj, vj, we find the time t at which the point intersects and returns parameters s on the segment
// TODO change order so that pj, vj is the ray
function segmentSegmentIntersection (pi, vi, pj, vj /*Vector of the segment */) {
function segmentSegmentIntersection (pi, vi, pj, vj /* Vector of the segment */) {
// (vi -vj)(t, s)^T = (pj - pi)
var det = - (vi.x* vj.y - vj.x * vi.y)
var det = -(vi.x * vj.y - vj.x * vi.y)
if (det === 0) { // Parallel lines
// Test this
if ((pi.x - pj.x) * vj.y - (pi.j - pj.y) * vj.x !==0) return null // Line does not belong
if ((pi.x - pj.x) * vj.y - (pi.j - pj.y) * vj.x !== 0) return null // Line does not belong
// TODO concurrent lines
throw new Error('Parallel lines not allowed') // This must be handled out of the algorithm
}
const t = (-(pj.x - pi.x) * vj.y + (pj.y - pi.y) * vj.x) / det
const s = (-(pj.x - pi.x) * vi.y + (pj.y - pi.y) * vi.x) / det
return {t, s}
}
}

0 comments on commit 2f8da7e

Please sign in to comment.