sparc-commons
Advanced tools
Comparing version 0.2.13 to 0.2.14
@@ -79,3 +79,3 @@ /*jshint multistr: true */ | ||
default: | ||
throw Error(`Invalid representation ${representation}`) | ||
throw Error(`Invalid representation ${JSON.stringify(representation, null, 2)}`) | ||
} | ||
@@ -223,4 +223,4 @@ } | ||
segment.unshift(point) | ||
_.each(segment, p => { | ||
p = transform(p, transformation) | ||
_.each(segment, (p, index) => { | ||
segment[index] = transform(p, transformation) | ||
}) | ||
@@ -243,2 +243,3 @@ return 0 | ||
var proximity = distance([coordinates, convPoint]).dist | ||
segment[index] = coordinates | ||
acc.push({ | ||
@@ -270,20 +271,4 @@ index: index, | ||
es.spliceSegment = function spliceSegment(segment, points, opts){ | ||
var arePointsSequential = _.get(opts, 'sequential', false) | ||
var transformation = _.get(opts, 'transformation') | ||
if(arePointsSequential){ | ||
var reduced = _.reduce(points, (acc, point) => { | ||
var rest = acc.rest | ||
var index = splicePoint(rest, point, transformation) | ||
acc.before = acc.before.concat(rest.slice(0, index)) | ||
acc.rest = rest.slice(index) | ||
return acc | ||
}, { | ||
rest: segment, | ||
before: [] | ||
}) | ||
return reduced.before.concat(reduced.rest) | ||
} | ||
return _.reduce(points, (seg, point) => { | ||
@@ -290,0 +275,0 @@ splicePoint(seg, point, transformation) |
{ | ||
"name": "sparc-commons", | ||
"version": "0.2.13", | ||
"version": "0.2.14", | ||
"description": "Library with all small time common stuff used across the SPARC echosystem", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -114,2 +114,51 @@ var chai = require('chai') | ||
it("Geojson representation", () => { | ||
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 = [ | ||
{ | ||
type: 'Feature', | ||
properties: { | ||
}, | ||
geometry: { | ||
type: "Point", | ||
coordinates: [ 4.89273034, 52.35724234 ] | ||
} | ||
}, | ||
{ | ||
type: 'Feature', | ||
properties: { | ||
id: "aeb6063c-c0c2-486a-94fd-763e1c827599" | ||
}, | ||
geometry: { | ||
type: "Point", | ||
coordinates: [ 4.892672, 52.356808 ] | ||
} | ||
}, | ||
{ | ||
type: 'Feature', | ||
properties: { | ||
}, | ||
geometry: { | ||
type: "Point", | ||
coordinates: [ 4.8926523, 52.35665804 ] | ||
} | ||
} | ||
] | ||
var ordered = geo.spliceSegment(segment, [point], {sequential: false, transformation: "geojson"}) | ||
_.each(_.zip(ordered, expected), _.spread((p, e) => { | ||
expect(p).to.deep.equal(e) | ||
})) | ||
}) | ||
it("Test that places near segment boundary are placed accordingly", () => { | ||
@@ -318,3 +367,4 @@ var segment=[ | ||
var ordered = geo.spliceSegment(segment, sequenceToAdd, {sequential: true}) | ||
var ordered = geo.spliceSegment(segment, sequenceToAdd, {transformation: "geojson"}) | ||
console.dir(ordered, {depth: 4}) | ||
@@ -321,0 +371,0 @@ var expectation = [ |
45331
1094