Browse Source

Fix epsilon calculation for RDP

ssao
A.Olokhtonov 11 months ago
parent
commit
fdca3e6b07
  1. 2
      client/index.html
  2. 4
      client/index.js
  3. 3
      client/math.js
  4. 12
      client/webgl_draw.js

2
client/index.html

@ -56,7 +56,7 @@ @@ -56,7 +56,7 @@
<div class="sizer-wrapper">
<div class="sizer">
<input type="range" class="slider" id="stroke-width" min="1" max="64">
<input type="range" class="slider" id="stroke-width" min="0.01" step="0.01" max="64">
</div>
<div id="stroke-preview" class="dhide"></div>
</div>

4
client/index.js

@ -19,8 +19,8 @@ const config = { @@ -19,8 +19,8 @@ const config = {
second_finger_timeout: 500,
buffer_first_touchmoves: 5,
debug_print: false,
min_zoom: 0.0000005,
max_zoom: 10.0,
min_zoom: 1.0,
max_zoom: 1000,
initial_offline_timeout: 1000,
default_color: 0x00,
default_width: 8,

3
client/math.js

@ -7,7 +7,7 @@ function screen_to_canvas(state, p) { @@ -7,7 +7,7 @@ function screen_to_canvas(state, p) {
}
function rdp_find_max(state, points, start, end) {
const EPS = 0.5 / Math.pow(state.canvas.zoom, 0.25);
const EPS = 1.0 / state.canvas.zoom;
// const EPS = 10.0;
let result = -1;
@ -86,6 +86,7 @@ function process_ewmv(points, round = false) { @@ -86,6 +86,7 @@ function process_ewmv(points, round = false) {
function process_stroke(state, points) {
// const result0 = process_ewmv(points);
const result1 = process_rdp(state, points, true);
console.debug('simplified to', points.length, 'points to', result1.length);
return result1;
}

12
client/webgl_draw.js

@ -164,6 +164,18 @@ function draw(state, context) { @@ -164,6 +164,18 @@ function draw(state, context) {
const dynamic_points = context.dynamic_serializer.offset / config.bytes_per_point;
if (dynamic_points > 0) {
gl.drawBuffers([gl.BACK]);
locations = context.locations['sdf'].main;
gl.useProgram(context.programs['sdf'].main);
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height);
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom);
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y);
gl.uniform1i(locations['u_stroke_count'], state.stroke_count);
gl.uniform1i(locations['u_debug_mode'], state.debug.red);
gl.clear(gl.DEPTH_BUFFER_BIT);
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_packed_dynamic']);

Loading…
Cancel
Save