|
|
@ -60,20 +60,24 @@ function process_rdp_indices(state, zoom, stroke) { |
|
|
|
return npoints; |
|
|
|
return npoints; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function process_ewmv(points, round = false) { |
|
|
|
function exponential_smoothing(points, last, up_to) { |
|
|
|
const result = []; |
|
|
|
|
|
|
|
const alpha = 0.5; |
|
|
|
const alpha = 0.5; |
|
|
|
|
|
|
|
|
|
|
|
result.push(points[0]); |
|
|
|
let pr = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 1; i < points.length; ++i) { |
|
|
|
let start = points.length - up_to; |
|
|
|
|
|
|
|
if (start < 0) { |
|
|
|
|
|
|
|
start = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = start; i < points.length; ++i) { |
|
|
|
const p = points[i]; |
|
|
|
const p = points[i]; |
|
|
|
const x = Math.round(alpha * p.x + (1 - alpha) * result[result.length - 1].x); |
|
|
|
pr = alpha * p.pressure + (1 - alpha) * pr; |
|
|
|
const y = Math.round(alpha * p.y + (1 - alpha) * result[result.length - 1].y); |
|
|
|
|
|
|
|
result.push({'x': x, 'y': y}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
pr = alpha * last.pressure + (1 - alpha) * pr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function process_stroke(state, zoom, stroke) { |
|
|
|
function process_stroke(state, zoom, stroke) { |
|
|
@ -92,7 +96,7 @@ function process_stroke(state, zoom, stroke) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function rdp_find_max2(zoom, points, start, end) { |
|
|
|
function rdp_find_max2(zoom, points, start, end) { |
|
|
|
const EPS = 1.0 / zoom; |
|
|
|
const EPS = 0.125 / zoom; |
|
|
|
|
|
|
|
|
|
|
|
let result = -1; |
|
|
|
let result = -1; |
|
|
|
let max_dist = 0; |
|
|
|
let max_dist = 0; |
|
|
@ -107,7 +111,7 @@ function rdp_find_max2(zoom, points, start, end) { |
|
|
|
const sin_theta = dy / dist_ab; |
|
|
|
const sin_theta = dy / dist_ab; |
|
|
|
const cos_theta = dx / dist_ab; |
|
|
|
const cos_theta = dx / dist_ab; |
|
|
|
|
|
|
|
|
|
|
|
for (let i = start; i < end; ++i) { |
|
|
|
for (let i = start + 1; i < end; ++i) { |
|
|
|
const p = points[i]; |
|
|
|
const p = points[i]; |
|
|
|
|
|
|
|
|
|
|
|
const ox = p.x - a.x; |
|
|
|
const ox = p.x - a.x; |
|
|
@ -132,7 +136,7 @@ function rdp_find_max2(zoom, points, start, end) { |
|
|
|
|
|
|
|
|
|
|
|
function process_rdp_r2(zoom, points, start, end) { |
|
|
|
function process_rdp_r2(zoom, points, start, end) { |
|
|
|
let result = []; |
|
|
|
let result = []; |
|
|
|
|
|
|
|
|
|
|
|
const max = rdp_find_max2(zoom, points, start, end); |
|
|
|
const max = rdp_find_max2(zoom, points, start, end); |
|
|
|
|
|
|
|
|
|
|
|
if (max !== -1) { |
|
|
|
if (max !== -1) { |
|
|
@ -145,9 +149,48 @@ function process_rdp_r2(zoom, points, start, end) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function process_rdp2(zoom, points) { |
|
|
|
function process_rdp2(zoom, points) { |
|
|
|
const result = process_rdp_r2(zoom, points, 0, points.length - 1); |
|
|
|
const result = []; |
|
|
|
result.unshift(points[0]); |
|
|
|
const stack = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack.push({ |
|
|
|
|
|
|
|
'type': 0, |
|
|
|
|
|
|
|
'start': 0, |
|
|
|
|
|
|
|
'end': points.length - 1, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.push(points[0]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (stack.length > 0) { |
|
|
|
|
|
|
|
const entry = stack.pop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entry.type === 0) { |
|
|
|
|
|
|
|
const max = rdp_find_max2(zoom, points, entry.start, entry.end); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (max !== -1) { |
|
|
|
|
|
|
|
stack.push({ |
|
|
|
|
|
|
|
'type': 0, |
|
|
|
|
|
|
|
'start': max, |
|
|
|
|
|
|
|
'end': entry.end |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack.push({ |
|
|
|
|
|
|
|
'type': 1, |
|
|
|
|
|
|
|
'index': max, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stack.push({ |
|
|
|
|
|
|
|
'type': 0, |
|
|
|
|
|
|
|
'start': entry.start, |
|
|
|
|
|
|
|
'end': max, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
result.push(points[entry.index]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result.push(points[points.length - 1]); |
|
|
|
result.push(points[points.length - 1]); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|