sparc-commons
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -144,34 +144,28 @@ /*jshint multistr: true */ | ||
var quadrant = (coordCur, coordPrev) => { | ||
var currentTrend = calculateTrend(coordCur, coordPrev) | ||
var quadrant = (firstExtreme, secondExtreme) => { | ||
if(secondExtreme){ | ||
var currentTrend = calculateTrend(convert(firstExtreme), convert(secondExtreme)) | ||
if(currentTrend[0] && currentTrend[1]){ | ||
//quadrant 1 => lat ascendent, lon ascendent | ||
if(currentTrend[0] && currentTrend[1]){ | ||
//quadrant 1 => lat ascendent, lon ascendent | ||
return trend => { | ||
return !trend[0] | ||
} | ||
} else if(currentTrend[0] && !currentTrend[1]){ | ||
//quadrant 2 => lat ascendent, lon descendent | ||
return trend => { | ||
return !trend[0] | ||
} | ||
} else if(!currentTrend[0] && !currentTrend[1]) { | ||
//quadrant 3 => lat descendent, lon descendent | ||
return trend => { | ||
return trend[0] | ||
} | ||
} | ||
//quadrant 4 => lat descendent, lon ascendent | ||
return trend => { | ||
return !trend[0] | ||
} | ||
} else if(currentTrend[0] && !currentTrend[1]){ | ||
//quadrant 2 => lat ascendent, lon descendent | ||
return trend => { | ||
return !trend[0] | ||
} | ||
} else if(!currentTrend[0] && !currentTrend[1]) { | ||
//quadrant 3 => lat descendent, lon descendent | ||
return trend => { | ||
return trend[0] | ||
} | ||
} | ||
//quadrant 4 => lat descendent, lon ascendent | ||
return trend => { | ||
return trend[0] | ||
} | ||
} | ||
var calculateQuadrant = (current, previous) => { | ||
if(previous){ | ||
var cur = convert(current) | ||
var prev = convert(previous) | ||
return quadrant(cur, prev) | ||
} | ||
return null | ||
@@ -181,2 +175,3 @@ } | ||
var splicePoint = es.splicePoint = (segment, point) => { | ||
//debugger | ||
if(segment.length < 2){ | ||
@@ -186,3 +181,10 @@ //points are always contained in the segment | ||
return 0 | ||
} | ||
//This condition invalidates the sequential: true (which is already unsafe) | ||
/** | ||
else if (segment.length === 2) { | ||
segment.splice(0, 0, point) | ||
return 1 | ||
} | ||
*/ | ||
@@ -197,3 +199,3 @@ var convPoint = convert(point) | ||
coords: convert(coords), | ||
isBetween: calculateQuadrant(coords, _.get(_.last(acc), 'coords')) | ||
isBetween: quadrant(coords, _.get(_.last(acc), 'coords')) | ||
}) | ||
@@ -208,3 +210,3 @@ return acc | ||
if(_.isNull(isBetween)){ | ||
isBetween = calculateQuadrant(closest[1].coords, closest[0].coords) | ||
isBetween = quadrant(closest[0].coords, closest[1].coords) | ||
} | ||
@@ -211,0 +213,0 @@ |
{ | ||
"name": "sparc-commons", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"description": "Library with all small time common stuff used across the SPARC echosystem", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -90,3 +90,58 @@ var chai = require('chai') | ||
it.only("Avoiding Empty segments on optimized spliceSegment", () => { | ||
it("Small Segment insertion", () => { | ||
var segment = [ | ||
[ 4.89273034, 52.35724234 ], | ||
[ 4.8926523, 52.35665804 ] | ||
] | ||
var point = { | ||
id: 'aeb6063c-c0c2-486a-94fd-763e1c827599', | ||
x: 4.892672, | ||
y: 52.356808 | ||
} | ||
var expected = [ | ||
[ 4.89273034, 52.35724234 ], | ||
[ 4.892672, 52.356808 ], | ||
[ 4.8926523, 52.35665804 ] | ||
] | ||
var ordered = geo.spliceSegment(segment, [point], {sequential: false}) | ||
_.each(_.zip(ordered, expected), _.spread((p, e) => { | ||
if(p.x){ | ||
p = [p.x, p.y] | ||
} | ||
expect(p).to.deep.equal(e) | ||
})) | ||
}) | ||
it.only("Test that places near segment boundary are placed accordingly", () => { | ||
var segment=[ | ||
[ 4.8926523, 52.35665804 ], | ||
[ 4.8915586, 52.35671291 ], | ||
[ 4.89077426, 52.35675405 ], | ||
[ 4.89067881, 52.35675954 ], | ||
[ 4.89063783, 52.35675954 ] | ||
] | ||
var waypoints = [ | ||
[ 4.891892, 52.356697 ], | ||
[ 4.891142, 52.356735 ] | ||
] | ||
var ordered = geo.spliceSegment(segment, waypoints, {sequential: false}) | ||
expect(ordered).to.deep.equal([ | ||
[ 4.8926523, 52.35665804 ], | ||
[ 4.891892, 52.356697 ], | ||
[ 4.8915586, 52.35671291 ], | ||
[ 4.891142, 52.356735 ], | ||
[ 4.89077426, 52.35675405 ], | ||
[ 4.89067881, 52.35675954 ], | ||
[ 4.89063783, 52.35675954 ] | ||
]) | ||
}) | ||
it("Avoiding Empty segments on optimized spliceSegment", () => { | ||
var segment =[ | ||
@@ -148,3 +203,3 @@ [ 4.90838741, 52.36030635 ], | ||
it("Real-life (buggy) segment progression", function(){ | ||
it.skip("Segment progression with Sequential:true", function(){ | ||
var segment = [ | ||
@@ -151,0 +206,0 @@ [ 4.920315, 52.363037 ], |
42878
1022