|
|
|
@ -60,20 +60,24 @@ function process_rdp_indices(state, zoom, stroke) {
@@ -60,20 +60,24 @@ function process_rdp_indices(state, zoom, stroke) {
|
|
|
|
|
return npoints; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function process_ewmv(points, round = false) { |
|
|
|
|
const result = []; |
|
|
|
|
function exponential_smoothing(points, last, up_to) { |
|
|
|
|
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 x = Math.round(alpha * p.x + (1 - alpha) * result[result.length - 1].x); |
|
|
|
|
const y = Math.round(alpha * p.y + (1 - alpha) * result[result.length - 1].y); |
|
|
|
|
result.push({'x': x, 'y': y}); |
|
|
|
|
pr = alpha * p.pressure + (1 - alpha) * pr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
pr = alpha * last.pressure + (1 - alpha) * pr; |
|
|
|
|
|
|
|
|
|
return pr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function process_stroke(state, zoom, stroke) { |
|
|
|
@ -92,7 +96,7 @@ function process_stroke(state, zoom, stroke) {
@@ -92,7 +96,7 @@ function process_stroke(state, zoom, stroke) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function rdp_find_max2(zoom, points, start, end) { |
|
|
|
|
const EPS = 1.0 / zoom; |
|
|
|
|
const EPS = 0.125 / zoom; |
|
|
|
|
|
|
|
|
|
let result = -1; |
|
|
|
|
let max_dist = 0; |
|
|
|
@ -107,7 +111,7 @@ function rdp_find_max2(zoom, points, start, end) {
@@ -107,7 +111,7 @@ function rdp_find_max2(zoom, points, start, end) {
|
|
|
|
|
const sin_theta = dy / 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 ox = p.x - a.x; |
|
|
|
@ -145,9 +149,48 @@ function process_rdp_r2(zoom, points, start, end) {
@@ -145,9 +149,48 @@ function process_rdp_r2(zoom, points, start, end) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function process_rdp2(zoom, points) { |
|
|
|
|
const result = process_rdp_r2(zoom, points, 0, points.length - 1); |
|
|
|
|
result.unshift(points[0]); |
|
|
|
|
const result = []; |
|
|
|
|
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]); |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|