pure-canvas
Advanced tools
Comparing version 0.5.13 to 0.5.14
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
let counter = 0; | ||
class NodeBase { | ||
constructor() { | ||
this._id = counter++; | ||
} | ||
get id() { | ||
return this._id; | ||
} | ||
toImage() { | ||
@@ -12,0 +5,0 @@ const { minX, minY, maxX, maxY } = this.getBounds(); |
@@ -7,31 +7,22 @@ "use strict"; | ||
this.tree = rbush(); | ||
this.nodeMap = {}; | ||
} | ||
clear() { | ||
this.nodeMap = {}; | ||
this.tree.clear(); | ||
} | ||
index(node, zIndex, transformers) { | ||
if (!this.nodeMap[node.id]) { | ||
const bounds = node.getBounds(); | ||
if (Number.isFinite(bounds.minX) && Number.isFinite(bounds.minY) && Number.isFinite(bounds.maxX) && Number.isFinite(bounds.maxY)) { | ||
let minX, minY, maxX, maxY; | ||
const { x: x1, y: y1 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.minX, y: bounds.minY }); | ||
const { x: x2, y: y2 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.maxX, y: bounds.maxY }); | ||
const { x: x3, y: y3 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.minX, y: bounds.maxY }); | ||
const { x: x4, y: y4 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.maxX, y: bounds.minY }); | ||
minX = Math.min(x1, x2, x3, x4); | ||
minY = Math.min(y1, y2, y3, y4); | ||
maxX = Math.max(x1, x2, x3, x4); | ||
maxY = Math.max(y1, y2, y3, y4); | ||
const indexedNode = { minX, minY, maxX, maxY, transformers, node, zIndex }; | ||
this.nodeMap[node.id] = indexedNode; | ||
this.tree.insert(indexedNode); | ||
} | ||
const bounds = node.getBounds(); | ||
if (Number.isFinite(bounds.minX) && Number.isFinite(bounds.minY) && Number.isFinite(bounds.maxX) && Number.isFinite(bounds.maxY)) { | ||
let minX, minY, maxX, maxY; | ||
const { x: x1, y: y1 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.minX, y: bounds.minY }); | ||
const { x: x2, y: y2 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.maxX, y: bounds.maxY }); | ||
const { x: x3, y: y3 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.minX, y: bounds.maxY }); | ||
const { x: x4, y: y4 } = transformers.reduce((point, transformer) => transformer.transform(point), { x: bounds.maxX, y: bounds.minY }); | ||
minX = Math.min(x1, x2, x3, x4); | ||
minY = Math.min(y1, y2, y3, y4); | ||
maxX = Math.max(x1, x2, x3, x4); | ||
maxY = Math.max(y1, y2, y3, y4); | ||
const indexedNode = { minX, minY, maxX, maxY, transformers, node, zIndex }; | ||
this.tree.insert(indexedNode); | ||
} | ||
} | ||
remove(node) { | ||
this.tree.remove(this.nodeMap[node.id]); | ||
delete this.nodeMap[node.id]; | ||
} | ||
intersection(point) { | ||
@@ -38,0 +29,0 @@ const results = this.tree |
{ | ||
"name": "pure-canvas", | ||
"version": "0.5.13", | ||
"version": "0.5.14", | ||
"description": "TODO", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -14,4 +14,2 @@ export interface Bounds { | ||
interface Node { | ||
id: number; | ||
getBounds(): Bounds; | ||
@@ -18,0 +16,0 @@ |
@@ -5,11 +5,3 @@ import Node, {Bounds, Point} from './Node'; | ||
let counter = 0; | ||
abstract class NodeBase implements NodeIndexable { | ||
private _id = counter++; | ||
get id() { | ||
return this._id; | ||
} | ||
abstract getBounds(): Bounds; | ||
@@ -16,0 +8,0 @@ |
@@ -9,6 +9,3 @@ import * as rbush from 'rbush'; | ||
private nodeMap: {[index: number]: IndexedNode} = {}; | ||
clear() { | ||
this.nodeMap = {}; | ||
this.tree.clear(); | ||
@@ -18,26 +15,18 @@ } | ||
index(node: Node, zIndex: number, transformers: Array<Transformer>) { | ||
if (!this.nodeMap[node.id]) { | ||
const bounds = node.getBounds(); | ||
if (Number.isFinite(bounds.minX) && Number.isFinite(bounds.minY) && Number.isFinite(bounds.maxX) && Number.isFinite(bounds.maxY)) { | ||
let minX: number, minY: number, maxX: number, maxY: number; | ||
const {x: x1, y: y1} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.minX, y: bounds.minY}); | ||
const {x: x2, y: y2} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.maxX, y: bounds.maxY}); | ||
const {x: x3, y: y3} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.minX, y: bounds.maxY}); | ||
const {x: x4, y: y4} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.maxX, y: bounds.minY}); | ||
minX = Math.min(x1, x2, x3, x4); | ||
minY = Math.min(y1, y2, y3, y4); | ||
maxX = Math.max(x1, x2, x3, x4); | ||
maxY = Math.max(y1, y2, y3, y4); | ||
const indexedNode = {minX, minY, maxX, maxY, transformers, node, zIndex}; | ||
this.nodeMap[node.id] = indexedNode; | ||
this.tree.insert(indexedNode); | ||
} | ||
const bounds = node.getBounds(); | ||
if (Number.isFinite(bounds.minX) && Number.isFinite(bounds.minY) && Number.isFinite(bounds.maxX) && Number.isFinite(bounds.maxY)) { | ||
let minX: number, minY: number, maxX: number, maxY: number; | ||
const {x: x1, y: y1} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.minX, y: bounds.minY}); | ||
const {x: x2, y: y2} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.maxX, y: bounds.maxY}); | ||
const {x: x3, y: y3} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.minX, y: bounds.maxY}); | ||
const {x: x4, y: y4} = transformers.reduce((point: Point, transformer: Transformer) => transformer.transform(point), {x: bounds.maxX, y: bounds.minY}); | ||
minX = Math.min(x1, x2, x3, x4); | ||
minY = Math.min(y1, y2, y3, y4); | ||
maxX = Math.max(x1, x2, x3, x4); | ||
maxY = Math.max(y1, y2, y3, y4); | ||
const indexedNode = {minX, minY, maxX, maxY, transformers, node, zIndex}; | ||
this.tree.insert(indexedNode); | ||
} | ||
} | ||
remove(node: Node) { | ||
this.tree.remove(this.nodeMap[node.id]); | ||
delete this.nodeMap[node.id]; | ||
} | ||
intersection(point: Point): Node { | ||
@@ -44,0 +33,0 @@ const results = this.tree |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
195995
2577