diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f201958 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# vim stuff +.swp + +# Ignore Build results +*.properties diff --git a/README.md b/README.md index a4715cf..7b522a5 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # RangeSearch +A computational geometry project. diff --git a/kdtest/.Camera.pde.swp b/kdtest/.Camera.pde.swp new file mode 100644 index 0000000..fabd80f Binary files /dev/null and b/kdtest/.Camera.pde.swp differ diff --git a/kdtest/Camera.pde b/kdtest/Camera.pde new file mode 100644 index 0000000..7a0157e --- /dev/null +++ b/kdtest/Camera.pde @@ -0,0 +1,74 @@ +class Camera { + float _x; + float _y; + float _scale; + float _angle; + float _oldX; + float _oldY; + float _oldAngle; + float _oldScale; + + int _initMX; + int _initMY; + + Camera() { + _x = 0.0; + _y = 0.0; + _scale = 1.0; + _angle = 4 * PI; + } + + void update() { + translate(_x + width/2,_y + height/2); + rotate(_angle); + scale(_scale); + } + + void mousePressed() { + _initMX = mouseX; + _initMY = mouseY; + _oldScale = _scale; + _oldX = _x; + _oldY = _y; + _oldAngle = _angle; + } + + void mouseDragged() { + float difX = (float)(mouseX - _initMX); + float difY = (float)(mouseY - _initMY); + + switch(G_mode) { + case 1: + difX /= (float)(width); + difY /= (float)(height); + _scale = epsilon + (1 - 4*(difX + difY)) * _oldScale; + break; + case 2: + difX *= _scale; + difY *= _scale; + _x = cos(_angle)*difX + sin(_angle)*difY + _oldX; + _y = -sin(_angle)*difX + cos(_angle)*difY + _oldY; + break; + case 3: + float initAngle = atan((_initMY - height/2)/(epsilon + _initMX - width/2)); + float newAngle = atan((mouseY - height/2)/(epsilon + mouseX - width/2)); + float delta = newAngle - initAngle; + _angle = _oldAngle + delta; + _x = cos(delta) * _oldX - sin(delta)*_oldY; + _y = sin(delta) * _oldX + sin(delta)*_oldY; + break; + } + } + + void mouseReleased() { + + } + + Point transform(Point p) { + float px = (1/_scale)*(p._x - width/2); + float py = (1/_scale)*(p._y - height/2); + float x = cos(_angle)*px - sin(_angle)*py - _y; + float y = sin(_angle)*px + cos(_angle)*py - _x; + return new Point(x,y); + } +} diff --git a/kdtest/Console.pde b/kdtest/Console.pde new file mode 100644 index 0000000..3965d13 --- /dev/null +++ b/kdtest/Console.pde @@ -0,0 +1,35 @@ +class Console { + int _textSize = 10; + int _bufferSize = 40; + int _xOffset = 20; + int _yOffset = 20; + ArrayList _stringList; + + Console() { + _stringList = new ArrayList (); + } + + void print(String s) { + _stringList.add(s); + } + + void draw() { + pushStyle(); + noStroke(); + fill(0,0,0,150); + rect(0,0,400,_yOffset + (_bufferSize + 1) * _textSize); + fill(30,250,30); + textSize(_textSize); + int index = 0; + int c = 0; + if (_stringList.size() - _bufferSize > 0) { + index = (_stringList.size() - _bufferSize) - 1; + } + while(index < _stringList.size()) { + text(_stringList.get(index), _xOffset, _yOffset + c * _textSize); + index++; + c++; + } + popStyle(); + } +} diff --git a/kdtest/Mode.pde b/kdtest/Mode.pde new file mode 100644 index 0000000..519d757 --- /dev/null +++ b/kdtest/Mode.pde @@ -0,0 +1,34 @@ +class Mode { + int _h = 30; + int _w = 60; + color c = color(256,256,256); + + Mode () { + + } + + void draw() { + pushStyle(); + fill(c); + rect(0,height,_w,height-_h); + fill(0); + textSize(30); + String s = new String(); + switch(G_mode) { + case 1: + s = "SCALE"; + break; + case 2: + s = "PAN"; + break; + case 3: + s = "ROTATE"; + break; + case 4: + s = "PLACE"; + break; + } + text(s,10, height-_h); + popStyle(); + } +} diff --git a/kdtest/Point.pde b/kdtest/Point.pde new file mode 100644 index 0000000..7d4127d --- /dev/null +++ b/kdtest/Point.pde @@ -0,0 +1,9 @@ +class Point { + float _x; + float _y; + + Point(float x0, float y0) { + _x = x0; + _y = y0; + } +} diff --git a/kdtest/kdtest.pde b/kdtest/kdtest.pde new file mode 100644 index 0000000..9d73a9b --- /dev/null +++ b/kdtest/kdtest.pde @@ -0,0 +1,86 @@ +Console con; +Camera cam; +Mode statusLine; + +ArrayList pointList; + +boolean drawCon; +float epsilon = 0.000001; +int G_mode; +// 1 = SCALE +// 2 = PAN +// 3 = ROTATE +// 4 = PLACE + +void setup() { + size(800,800); + background(120); + stroke(256,256,256); + ellipseMode(CENTER); + + con = new Console(); + cam = new Camera(); + statusLine = new Mode(); + + pointList = new ArrayList(); + + drawCon = false; + G_mode = 1; +} + +void draw() { + background(120); + + pushMatrix(); + cam.update(); + drawGnoman(200); + for(Point p: pointList) { + ellipse(p._x, p._y, 40,40); + } + popMatrix(); + + if(drawCon) con.draw(); + statusLine.draw(); +} + +void keyPressed() { + switch(key) { + case 't': + con.print("t"); + drawCon = !drawCon; + break; + case 'f': + G_mode = 1; + break; + case 'd': + G_mode = 2; + break; + case 's': + G_mode = 3; + break; + case 'a': + G_mode = 4; + break; + } +} + +void drawGnoman(int r) { + line(-r,0,r,0); + line(0,-r,0,r); +} + +void mousePressed() { + if(G_mode == 4) { + pointList.add(cam.transform(new Point(mouseX, mouseY))); + } + cam.mousePressed(); + con.print("Pressed"); +} + +void mouseDragged() { + cam.mouseDragged(); +} + +void mouseReleased() { + cam.mouseReleased(); +} diff --git a/kdtest/web-export/index.html b/kdtest/web-export/index.html new file mode 100644 index 0000000..1c280dc --- /dev/null +++ b/kdtest/web-export/index.html @@ -0,0 +1,77 @@ + + + + kdtest : Built with Processing and Processing.js + + + + + + + + + + +
+
+ +

Your browser does not support the canvas tag.

+ +
+ +
+

kdtest

+

+

Source code: kdtest

+

+ Built with Processing + and Processing.js +

+
+ + diff --git a/kdtest/web-export/kdtest.pde b/kdtest/web-export/kdtest.pde new file mode 100644 index 0000000..5d394c3 --- /dev/null +++ b/kdtest/web-export/kdtest.pde @@ -0,0 +1,93 @@ +float angle = 0; +Console con; + +void setup() { + size(800,800); + background(120); + + stroke(256,256,256); + con = new Console(); +} + +void draw() { + //translate(width-mouseX, height-mouseY); + angle += 0.1; + background(120); + + pushMatrix(); + translate(400,400); + rotate(angle); + drawGnoman(200); + popMatrix(); + con.print("haaaaaaasa"); + textSize(20); + text("asdasd",20,100); + con.draw(); +} + +void drawGnoman(int r) { + line(-r,0,r,0); + line(0,-r,0,r); +} + +void mousePressed() { + print("mouse pressed"); +} + +void mouseDragged() { + print("mouse Dragged"); +} +class Camera { + float _x; + float _y; + float _scale; + float _angle; + + Camera() { + _x = width/2; + _y = height/2; + _scale = 1.0; + _angle = 0.0; + } + + void update() { + + } + + void cam_mousePressed() { + + } + + void cam_mouseDragged() { + + } +} +class Console { + int _textSize = 20; + int _bufferSize = 20; + int _xOffest = 20; + int _yOffset = 20; + ArrayList _stringList; + + Console() { + _stringList = new ArrayList (); + } + + void print(String s) { + _stringList.add(s); + } + + void draw() { + rect(40,40, 100,100); + textSize(_textSize); + int index = 0; + //if (_stringList.size - _bufferSize > 0) { + //index = (_stringList.size - _bufferSize) - 1; + //} + while(index < _stringList.size) { + text("Asdasfa", _xOffset, _yOffset + i * _textSize); + index++; + } + } +} + diff --git a/kdtest/web-export/processing.js b/kdtest/web-export/processing.js new file mode 100644 index 0000000..3b8d11e --- /dev/null +++ b/kdtest/web-export/processing.js @@ -0,0 +1,21738 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o'); + e.print.apply(e, args); + if (e.BufferArray.length > e.BufferMax) { + e.BufferArray.splice(0, 1); + } else { + e.javaconsole.scrollTop = e.javaconsole.scrollHeight; + } + }; + + e.showconsole = function () { e.wrapper.classList.remove("hidden"); }; + e.hideconsole = function () { e.wrapper.classList.add("hidden"); }; + + e.closer.onclick = function () { e.hideconsole(); }; + + e.hideconsole(); + + return e; +}; + +},{}],6:[function(require,module,exports){ +/** + * Processing.js default scope + */ +module.exports = function(options) { + + // Building defaultScope. Changing of the prototype protects + // internal Processing code from the changes in defaultScope + function DefaultScope() {} + DefaultScope.prototype = options.PConstants; + + var defaultScope = new DefaultScope(); + + // copy over all known Object types and helper objects + Object.keys(options).forEach(function(prop) { + defaultScope[prop] = options[prop]; + }); + + //////////////////////////////////////////////////////////////////////////// + // Class inheritance helper methods + //////////////////////////////////////////////////////////////////////////// + + defaultScope.defineProperty = function(obj, name, desc) { + if("defineProperty" in Object) { + Object.defineProperty(obj, name, desc); + } else { + if (desc.hasOwnProperty("get")) { + obj.__defineGetter__(name, desc.get); + } + if (desc.hasOwnProperty("set")) { + obj.__defineSetter__(name, desc.set); + } + } + }; + + /** + * class overloading, part 1 + */ + function overloadBaseClassFunction(object, name, basefn) { + if (!object.hasOwnProperty(name) || typeof object[name] !== 'function') { + // object method is not a function or just inherited from Object.prototype + object[name] = basefn; + return; + } + var fn = object[name]; + if ("$overloads" in fn) { + // the object method already overloaded (see defaultScope.addMethod) + // let's just change a fallback method + fn.$defaultOverload = basefn; + return; + } + if (!("$overloads" in basefn) && fn.length === basefn.length) { + // special case when we just overriding the method + return; + } + var overloads, defaultOverload; + if ("$overloads" in basefn) { + // let's inherit base class overloads to speed up things + overloads = basefn.$overloads.slice(0); + overloads[fn.length] = fn; + defaultOverload = basefn.$defaultOverload; + } else { + overloads = []; + overloads[basefn.length] = basefn; + overloads[fn.length] = fn; + defaultOverload = fn; + } + var hubfn = function() { + var fn = hubfn.$overloads[arguments.length] || + ("$methodArgsIndex" in hubfn && arguments.length > hubfn.$methodArgsIndex ? + hubfn.$overloads[hubfn.$methodArgsIndex] : null) || + hubfn.$defaultOverload; + return fn.apply(this, arguments); + }; + hubfn.$overloads = overloads; + if ("$methodArgsIndex" in basefn) { + hubfn.$methodArgsIndex = basefn.$methodArgsIndex; + } + hubfn.$defaultOverload = defaultOverload; + hubfn.name = name; + object[name] = hubfn; + } + + /** + * class overloading, part 2 + */ + + function extendClass(subClass, baseClass) { + function extendGetterSetter(propertyName) { + defaultScope.defineProperty(subClass, propertyName, { + get: function() { + return baseClass[propertyName]; + }, + set: function(v) { + baseClass[propertyName]=v; + }, + enumerable: true + }); + } + + var properties = []; + for (var propertyName in baseClass) { + if (typeof baseClass[propertyName] === 'function') { + overloadBaseClassFunction(subClass, propertyName, baseClass[propertyName]); + } else if(propertyName.charAt(0) !== "$" && !(propertyName in subClass)) { + // Delaying the properties extension due to the IE9 bug (see #918). + properties.push(propertyName); + } + } + while (properties.length > 0) { + extendGetterSetter(properties.shift()); + } + + subClass.$super = baseClass; + } + + /** + * class overloading, part 3 + */ + defaultScope.extendClassChain = function(base) { + var path = [base]; + for (var self = base.$upcast; self; self = self.$upcast) { + extendClass(self, base); + path.push(self); + base = self; + } + while (path.length > 0) { + path.pop().$self=base; + } + }; + + // static + defaultScope.extendStaticMembers = function(derived, base) { + extendClass(derived, base); + }; + + // interface + defaultScope.extendInterfaceMembers = function(derived, base) { + extendClass(derived, base); + }; + + /** + * Java methods and JavaScript functions differ enough that + * we need a special function to make sure it all links up + * as classical hierarchical class chains. + */ + defaultScope.addMethod = function(object, name, fn, hasMethodArgs) { + var existingfn = object[name]; + if (existingfn || hasMethodArgs) { + var args = fn.length; + // builds the overload methods table + if ("$overloads" in existingfn) { + existingfn.$overloads[args] = fn; + } else { + var hubfn = function() { + var fn = hubfn.$overloads[arguments.length] || + ("$methodArgsIndex" in hubfn && arguments.length > hubfn.$methodArgsIndex ? + hubfn.$overloads[hubfn.$methodArgsIndex] : null) || + hubfn.$defaultOverload; + return fn.apply(this, arguments); + }; + var overloads = []; + if (existingfn) { + overloads[existingfn.length] = existingfn; + } + overloads[args] = fn; + hubfn.$overloads = overloads; + hubfn.$defaultOverload = existingfn || fn; + if (hasMethodArgs) { + hubfn.$methodArgsIndex = args; + } + hubfn.name = name; + object[name] = hubfn; + } + } else { + object[name] = fn; + } + }; + + // internal helper function + function isNumericalJavaType(type) { + if (typeof type !== "string") { + return false; + } + return ["byte", "int", "char", "color", "float", "long", "double"].indexOf(type) !== -1; + } + + /** + * Java's arrays are pre-filled when declared with + * an initial size, but no content. JS arrays are not. + */ + defaultScope.createJavaArray = function(type, bounds) { + var result = null, + defaultValue = null; + if (typeof type === "string") { + if (type === "boolean") { + defaultValue = false; + } else if (isNumericalJavaType(type)) { + defaultValue = 0; + } + } + if (typeof bounds[0] === 'number') { + var itemsCount = 0 | bounds[0]; + if (bounds.length <= 1) { + result = []; + result.length = itemsCount; + for (var i = 0; i < itemsCount; ++i) { + result[i] = defaultValue; + } + } else { + result = []; + var newBounds = bounds.slice(1); + for (var j = 0; j < itemsCount; ++j) { + result.push(defaultScope.createJavaArray(type, newBounds)); + } + } + } + return result; + }; + + // screenWidth and screenHeight are shared by all instances. + // and return the width/height of the browser's viewport. + defaultScope.defineProperty(defaultScope, 'screenWidth', + { get: function() { return window.innerWidth; } }); + + defaultScope.defineProperty(defaultScope, 'screenHeight', + { get: function() { return window.innerHeight; } }); + + return defaultScope; +}; + +},{}],7:[function(require,module,exports){ +/** + * Finalise the Processing.js object. + */ +module.exports = function finalizeProcessing(Processing, options) { + + // unpack options + var window = options.window, + document = options.document, + XMLHttpRequest = window.XMLHttpRequest, + noop = options.noop, + isDOMPresent = options.isDOMPresent, + version = options.version, + undef; + + // versioning + Processing.version = (version ? version : "@DEV-VERSION@"); + + // Share lib space + Processing.lib = {}; + + /** + * External libraries can be added to the global Processing + * objects with the `registerLibrary` function. + */ + Processing.registerLibrary = function(name, library) { + Processing.lib[name] = library; + if(library.hasOwnProperty("init")) { + library.init(defaultScope); + } + }; + + /** + * This is the object that acts as our version of PApplet. + * This can be called as Processing.Sketch() or as + * Processing.Sketch(function) in which case the function + * must be an already-compiled-to-JS sketch function. + */ + Processing.Sketch = function(attachFunction) { + this.attachFunction = attachFunction; + this.options = { + pauseOnBlur: false, + globalKeyEvents: false + }; + + /* Optional Sketch event hooks: + * onLoad - parsing/preloading is done, before sketch starts + * onSetup - setup() has been called, before first draw() + * onPause - noLoop() has been called, pausing draw loop + * onLoop - loop() has been called, resuming draw loop + * onFrameStart - draw() loop about to begin + * onFrameEnd - draw() loop finished + * onExit - exit() done being called + */ + this.onLoad = noop; + this.onSetup = noop; + this.onPause = noop; + this.onLoop = noop; + this.onFrameStart = noop; + this.onFrameEnd = noop; + this.onExit = noop; + + this.params = {}; + this.imageCache = { + pending: 0, + images: {}, + // Opera requires special administration for preloading + operaCache: {}, + // Specify an optional img arg if the image is already loaded in the DOM, + // otherwise href will get loaded. + add: function(href, img) { + // Prevent muliple loads for an image, in case it gets + // preloaded more than once, or is added via JS and then preloaded. + if (this.images[href]) { + return; + } + + if (!isDOMPresent) { + this.images[href] = null; + } + + // No image in the DOM, kick-off a background load + if (!img) { + img = new Image(); + img.onload = (function(owner) { + return function() { + owner.pending--; + }; + }(this)); + this.pending++; + img.src = href; + } + + this.images[href] = img; + + // Opera will not load images until they are inserted into the DOM. + if (window.opera) { + var div = document.createElement("div"); + div.appendChild(img); + // we can't use "display: none", since that makes it invisible, and thus not load + div.style.position = "absolute"; + div.style.opacity = 0; + div.style.width = "1px"; + div.style.height= "1px"; + if (!this.operaCache[href]) { + document.body.appendChild(div); + this.operaCache[href] = div; + } + } + } + }; + + this.sourceCode = undefined; + this.attach = function(processing) { + // either attachFunction or sourceCode must be present on attach + if(typeof this.attachFunction === "function") { + this.attachFunction(processing); + } else if(this.sourceCode) { + var func = ((new Function("return (" + this.sourceCode + ");"))()); + func(processing); + this.attachFunction = func; + } else { + throw "Unable to attach sketch to the processing instance"; + } + }; + + this.toString = function() { + var i; + var code = "((function(Sketch) {\n"; + code += "var sketch = new Sketch(\n" + this.sourceCode + ");\n"; + for(i in this.options) { + if(this.options.hasOwnProperty(i)) { + var value = this.options[i]; + code += "sketch.options." + i + " = " + + (typeof value === 'string' ? '\"' + value + '\"' : "" + value) + ";\n"; + } + } + for(i in this.imageCache) { + if(this.options.hasOwnProperty(i)) { + code += "sketch.imageCache.add(\"" + i + "\");\n"; + } + } + // TODO serialize fonts + code += "return sketch;\n})(Processing.Sketch))"; + return code; + }; + }; + + /** + * aggregate all source code into a single file, then rewrite that + * source and bind to canvas via new Processing(canvas, sourcestring). + * @param {CANVAS} canvas The html canvas element to bind to + * @param {String[]} source The array of files that must be loaded + */ + var loadSketchFromSources = Processing.loadSketchFromSources = function(canvas, sources) { + var code = [], errors = [], sourcesCount = sources.length, loaded = 0; + + function ajaxAsync(url, callback) { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + var error; + if (xhr.status !== 200 && xhr.status !== 0) { + error = "Invalid XHR status " + xhr.status; + } else if (xhr.responseText === "") { + // Give a hint when loading fails due to same-origin issues on file:/// urls + if ( ("withCredentials" in new XMLHttpRequest()) && + (new XMLHttpRequest()).withCredentials === false && + window.location.protocol === "file:" ) { + error = "XMLHttpRequest failure, possibly due to a same-origin policy violation. You can try loading this page in another browser, or load it from http://localhost using a local webserver. See the Processing.js README for a more detailed explanation of this problem and solutions."; + } else { + error = "File is empty."; + } + } + + callback(xhr.responseText, error); + } + }; + xhr.open("GET", url, true); + if (xhr.overrideMimeType) { + xhr.overrideMimeType("application/json"); + } + xhr.setRequestHeader("If-Modified-Since", "Fri, 01 Jan 1960 00:00:00 GMT"); // no cache + xhr.send(null); + } + + function loadBlock(index, filename) { + function callback(block, error) { + code[index] = block; + ++loaded; + if (error) { + errors.push(filename + " ==> " + error); + } + if (loaded === sourcesCount) { + if (errors.length === 0) { + // This used to throw, but it was constantly getting in the way of debugging where things go wrong! + return new Processing(canvas, code.join("\n")); + } else { + throw "Processing.js: Unable to load pjs sketch files: " + errors.join("\n"); + } + } + } + if (filename.charAt(0) === '#') { + // trying to get script from the element + var scriptElement = document.getElementById(filename.substring(1)); + if (scriptElement) { + callback(scriptElement.text || scriptElement.textContent); + } else { + callback("", "Unable to load pjs sketch: element with id \'" + filename.substring(1) + "\' was not found"); + } + return; + } + + ajaxAsync(filename, callback); + } + + for (var i = 0; i < sourcesCount; ++i) { + loadBlock(i, sources[i]); + } + }; + + /** + * Automatic initialization function. + */ + var init = function() { + document.removeEventListener('DOMContentLoaded', init, false); + var i; + + // before running through init, clear the instances list, to prevent + // sketch duplication when page content is dynamically swapped without + // swapping out processing.js + while (Processing.instances.length > 0) { + for (i = Processing.instances.length - 1; i >= 0; i--) { + if (Processing.instances[i]) { + Processing.instances[i].exit(); + } + } + } + + var canvas = document.getElementsByTagName('canvas'), + filenames; + + for (i = 0, l = canvas.length; i < l; i++) { + // datasrc and data-src are deprecated. + var processingSources = canvas[i].getAttribute('data-processing-sources'); + if (processingSources === null) { + // Temporary fallback for datasrc and data-src + processingSources = canvas[i].getAttribute('data-src'); + if (processingSources === null) { + processingSources = canvas[i].getAttribute('datasrc'); + } + } + if (processingSources) { + filenames = processingSources.split(/\s+/g); + for (var j = 0; j < filenames.length;) { + if (filenames[j]) { + j++; + } else { + filenames.splice(j, 1); + } + } + loadSketchFromSources(canvas[i], filenames); + } + } + + // also process all