wip: cull opaque tiles

This commit is contained in:
Patrick Walton 2018-12-03 14:08:08 -08:00
parent 2a07733144
commit 0929a98e2a
3 changed files with 23 additions and 6 deletions

View File

@ -20,8 +20,8 @@ export class Point2D {
Object.freeze(this);
}
approxEq(other: Point2D): boolean {
return approxEq(this.x, other.x) && approxEq(this.y, other.y);
approxEq(other: Point2D, epsilon: number | undefined): boolean {
return approxEq(this.x, other.x, epsilon) && approxEq(this.y, other.y, epsilon);
}
lerp(other: Point2D, t: number): Point2D {
@ -107,8 +107,8 @@ export class Matrix2D {
}
}
export function approxEq(a: number, b: number): boolean {
return Math.abs(a - b) <= EPSILON;
export function approxEq(a: number, b: number, epsilon: number | undefined): boolean {
return Math.abs(a - b) <= (epsilon == null ? EPSILON : epsilon);
}
export function lerp(a: number, b: number, t: number): number {

View File

@ -324,6 +324,10 @@ class App {
const pathTileStrips = scene.pathTileStrips[pathIndex];
for (const tileStrip of pathTileStrips) {
for (const tile of tileStrip.tiles) {
// TODO(pcwalton)
if (tile.isFilled())
continue;
for (const edge of tile.edges) {
let ctrl;
if (edge.ctrl == null)

View File

@ -264,7 +264,7 @@ export class Tiler {
}
private clipEdgeX(edge: Edge, x: number): ClippedEdgesX {
const EPSILON: number = 0.001;
const EPSILON: number = 0.00001;
if (edge.from.x < x && edge.to.x < x)
return {left: edge, right: null};
@ -291,7 +291,7 @@ export class Tiler {
}
private clipEdgeY(edge: Edge, y: number): ClippedEdgesY {
const EPSILON: number = 0.001;
const EPSILON: number = 0.00001;
if (edge.from.y < y && edge.to.y < y)
return {upper: edge, lower: null};
@ -473,6 +473,19 @@ export class Tile {
isEmpty(): boolean {
return this.edges.length === 0;
}
isFilled(): boolean {
if (this.edges.length !== 1)
return false;
const edge = this.edges[0];
if (edge.ctrl != null)
return false;
//console.log("single edge:", JSON.stringify(edge));
const left = edge.from.x < edge.to.x ? edge.from : edge.to;
const right = edge.from.x < edge.to.x ? edge.to : edge.from;
return left.approxEq(new Point2D(0, 0), 0.1) &&
right.approxEq(new Point2D(TILE_SIZE.width, 0), 0.1);
}
}
interface ClippedEdgesX {