summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-10-15 11:29:51 +0200
committerjmoenig <jens@moenig.org>2013-10-15 11:29:51 +0200
commita8d08c147d3c05290654e700a84fcdaa00ad4a3e (patch)
tree22d10098e62c0f0bad7b3b91544126b8b3df22eb
parentcc9a44ed1057e395da24c251fb0faf5f1b886c66 (diff)
downloadsnap-a8d08c147d3c05290654e700a84fcdaa00ad4a3e.tar.gz
snap-a8d08c147d3c05290654e700a84fcdaa00ad4a3e.zip
Condense damage list even more
by merging nearby rectangles, thanks, Craxic, for the idea for this in #192
-rwxr-xr-xhistory.txt4
-rw-r--r--morphic.js14
2 files changed, 15 insertions, 3 deletions
diff --git a/history.txt b/history.txt
index 01f72f1..16da6bd 100755
--- a/history.txt
+++ b/history.txt
@@ -1960,3 +1960,7 @@ ______
* Morphic: Condense damage list by merging overlapping dirty rectangles, thanks, Craxic!
* Objects: Increase maximum clone count from 128 to 300
* Portuguese translation update, thanks, Manuel!!
+
+131015
+------
+* Morphic: further condense damage list by merging nearby rectangles, thanks, Craxic!
diff --git a/morphic.js b/morphic.js
index ca84210..aac180d 100644
--- a/morphic.js
+++ b/morphic.js
@@ -1035,7 +1035,7 @@
/*global window, HTMLCanvasElement, getMinimumFontHeight, FileReader, Audio,
FileList, getBlurredShadowSupport*/
-var morphicVersion = '2013-October-14';
+var morphicVersion = '2013-October-15';
var modules = {}; // keep track of additional loaded modules
var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug
@@ -1970,6 +1970,14 @@ Rectangle.prototype.intersects = function (aRect) {
(ro.y <= this.corner.y);
};
+Rectangle.prototype.isNearTo = function (aRect, threshold) {
+ var ro = aRect.origin, rc = aRect.corner, border = threshold || 0;
+ return (rc.x + border >= this.origin.x) &&
+ (rc.y + border >= this.origin.y) &&
+ (ro.x - border <= this.corner.x) &&
+ (ro.y - border <= this.corner.y);
+};
+
// Rectangle transforming:
Rectangle.prototype.scaleBy = function (scale) {
@@ -9966,7 +9974,7 @@ WorldMorph.prototype.updateBroken = function () {
};
WorldMorph.prototype.condenseDamages = function () {
- // collapse overlapping damaged rectangles into their unions,
+ // collapse clustered damaged rectangles into their unions,
// thereby reducing the array of brokens to a manageable size
function condense(src) {
@@ -9974,7 +9982,7 @@ WorldMorph.prototype.condenseDamages = function () {
src.forEach(function (rect) {
hit = detect(
trgt,
- function (each) {return each.intersects(rect); }
+ function (each) {return each.isNearTo(rect, 20); }
);
if (hit) {
hit.mergeWith(rect);