Anonymous user
Ramer-Douglas-Peucker line simplification: Difference between revisions
Ramer-Douglas-Peucker line simplification (view source)
Revision as of 14:58, 2 April 2019
, 5 years ago→{{header|JavaScript}}
Line 534:
*/
const RDP = (l, eps) => {
const last = l.length - 1;
const p1 = l[0];
Line 542 ⟶ 540:
const y21 = p2.y - p1.y;
const [dMax, x] = l.slice(1, last)
return [v, idx];
}, [-1, 0]);
if (dMax > eps) {
return [...RDP(l.slice(0, x + 1), eps), ...RDP(l.slice(x), eps).slice(1)];
}
return [l[0], l[last]]
Line 557 ⟶ 555:
const points = [
{x: 0, y: 0},
{x: 2, y: -0.1},
{x: 3, y: 5},
{x: 4, y: 6},
{x: 5, y: 7},
{x: 6, y: 8.1},
{x: 7, y: 9},
{x: 8, y: 9},
{x: 9, y: 9}];
console.log(RDP(points, 1));</lang>
{{out}}
<pre>[
{
{
{
{
=={{header|Julia}}==
|