Condense damage list even more

by merging nearby rectangles, thanks, Craxic, for the idea for this in
#192
pull/3/merge
jmoenig 2013-10-15 11:29:51 +02:00
rodzic cc9a44ed10
commit a8d08c147d
2 zmienionych plików z 15 dodań i 3 usunięć

Wyświetl plik

@ -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!

Wyświetl plik

@ -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);