Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quadtree #312

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
97,433 changes: 48,879 additions & 48,554 deletions engine/dist/emptyproject.html

Large diffs are not rendered by default.

97,339 changes: 48,832 additions & 48,507 deletions engine/dist/wickengine.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions engine/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ gulp.task("default", function() {
'lib/localforage.min.js',
'lib/platform.js',
'lib/potrace.js',
'lib/quadtree.min.js',
'lib/reserved-words.js',
'lib/roundRect.js',
'lib/timestamp.js',
Expand All @@ -55,6 +56,7 @@ gulp.task("default", function() {
.src([
'src/Wick.js',
'src/Clipboard.js',
'src/Quadtree.js',
'src/Color.js',
'src/FileCache.js',
'src/History.js',
Expand Down
5 changes: 4 additions & 1 deletion engine/lib/croquis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @license croquis.js */
/* https://github.com/disjukr/croquis.js/tree/master */

var drawSpacings = [];
function Croquis(imageDataList, properties) {
var self = this;
if (properties != null)
Expand Down Expand Up @@ -816,6 +816,7 @@ function Croquis(imageDataList, properties) {
cacheLayer(self.getCurrentLayerIndex());
}
self.down = function (x, y, pressure) {
drawSpacings = [];
if (isDrawing || isStabilizing)
throw 'still drawing';
isDrawing = true;
Expand Down Expand Up @@ -1509,6 +1510,7 @@ Croquis.Brush = function () {
delta += d;
var midScale = (prevScale + scale) * 0.5;
var drawSpacing = size * spacing * midScale;
drawSpacings.push(drawSpacing);
var ldx = x - lastX;
var ldy = y - lastY;
var ld = sqrt(ldx * ldx + ldy * ldy);
Expand Down Expand Up @@ -1545,6 +1547,7 @@ Croquis.Brush = function () {
this.up = function (x, y, scale) {
dir = atan2(y - lastY, x - lastX);
drawReserved();
console.log(drawSpacings);
return dirtyRect;
};
};
2 changes: 2 additions & 0 deletions engine/lib/quadtree.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion engine/src/ObjectCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ WickObjectCache = class {

var object = this._objects[uuid];
if(!object) {
console.error("Warning: object with uuid " + uuid + " was not found in the cache.");
// This warning is removed because it shows up a lot when the hit test quadtree is used,
// which slows things down a lot.
//console.error("Warning: object with uuid " + uuid + " was not found in the cache.");
return null;
} else {
return object;
Expand Down
61 changes: 61 additions & 0 deletions engine/src/Quadtree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2020 WICKLETS LLC
*
* This file is part of Wick Engine.
*
* Wick Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wick Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wick Engine. If not, see <https://www.gnu.org/licenses/>.
*/

/* Quadtree wrapper */
// this.quadtree:
// - quadtree-lib data structure (https://github.com/elbywan/quadtree-lib#readme)
// - elements in form {x, y, width, height, uuid, inTree}
// this.dirty:
// - set of quadtree elements ({x, y, width, height, uuid, inTree})
// this.elements:
// - dictionary of elements {uuid1: element1, uuid2: element2}
// - these are the exact objects that go into this.quadtree by reference
Wick.Quadtree = class {
constructor (width, height) {
this._quadtree = new Quadtree({width: width, height: height});
this.dirty = new Set();
this.elements = {};
}

get quadtree() {
return this._quadtree;
}

clean() {
let to_remove = [];
this._quadtree.each(function(element) {
let clip = Wick.ObjectCache.getObjectByUUID(element.uuid);
if (!clip || !clip.onScreen) {
to_remove.push(element);
element.inTree = false;
}
});
for (let i = 0; i < to_remove.length; i++) {
this._quadtree.remove(to_remove[i]);
}
}

resize(width, height) {
this._quadtree.each(function(element) {
element.inTree = false;
this.dirty.add(element.uuid);
});
this._quadtree = new Quadtree({width: width, height: height});
}
}
Loading