|
|
|
@ -217,8 +217,20 @@ function quad_fully_onscreen(screen, bbox) {
@@ -217,8 +217,20 @@ function quad_fully_onscreen(screen, bbox) {
|
|
|
|
|
|
|
|
|
|
function segments_onscreen(state, context) { |
|
|
|
|
// TODO: handle stroke width
|
|
|
|
|
|
|
|
|
|
if (state.onscreen_segments === null) { |
|
|
|
|
let total_points = 0; |
|
|
|
|
|
|
|
|
|
state.onscreen_segments.length = 0; |
|
|
|
|
for (const event of state.events) { |
|
|
|
|
if (event.type === EVENT.STROKE && !event.deleted) { |
|
|
|
|
total_points += event.points.length - 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
state.onscreen_segments = new Uint32Array(total_points * 6); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let at = 0; |
|
|
|
|
|
|
|
|
|
const screen_topleft = screen_to_canvas(state, {'x': 0, 'y': 0}); |
|
|
|
|
const screen_bottomright = screen_to_canvas(state, {'x': context.canvas.width, 'y': context.canvas.height}); |
|
|
|
@ -240,12 +252,20 @@ function segments_onscreen(state, context) {
@@ -240,12 +252,20 @@ function segments_onscreen(state, context) {
|
|
|
|
|
if (fully_onscreen || segment_interesects_quad(a, b, screen_topleft, screen_bottomright, screen_topright, screen_bottomleft)) { |
|
|
|
|
let base = head + j * 4; |
|
|
|
|
// We draw quads as [1, 2, 3, 4, 3, 2]
|
|
|
|
|
state.onscreen_segments.push(base + 0, base + 1, base + 2); |
|
|
|
|
state.onscreen_segments.push(base + 3, base + 2, base + 1); |
|
|
|
|
state.onscreen_segments[at + 0] = base + 0; |
|
|
|
|
state.onscreen_segments[at + 1] = base + 1; |
|
|
|
|
state.onscreen_segments[at + 2] = base + 2; |
|
|
|
|
state.onscreen_segments[at + 3] = base + 3; |
|
|
|
|
state.onscreen_segments[at + 4] = base + 2; |
|
|
|
|
state.onscreen_segments[at + 5] = base + 1; |
|
|
|
|
|
|
|
|
|
at += 6; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
head += (event.points.length - 1) * 4; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return at; |
|
|
|
|
} |
|
|
|
|