changed determining "neighbors" from rectangular to circular perimeter

pull/95/head
jmoenig 2020-11-20 14:58:32 +01:00
rodzic db04d8f829
commit 8ee7e262be
4 zmienionych plików z 59 dodań i 11 usunięć

Wyświetl plik

@ -2,6 +2,8 @@
## in development:
* **Notable Changes:**
* changed determining "neighbors" from rectangular to circular perimeter
* **Notable Fixes:**
* fixed stretching SVG costumes with fixed aspect ratios in Firefox
* only report neighbors that are visible
@ -13,6 +15,7 @@
* threads: only report neighbors that are visible, thanks Frederic, for reporting this bug!
* Italian translation update, thanks, Stefano!
* Spanish translation update, thanks, Joan!
* threads, objects: changed determining "neighbors" from rectangular to circular perimeter
### 2020-11-19
* new dev version

Wyświetl plik

@ -10,7 +10,7 @@
<script src="src/widgets.js?version=2020-10-06"></script>
<script src="src/blocks.js?version=2020-11-17"></script>
<script src="src/threads.js?version=2020-11-20"></script>
<script src="src/objects.js?version=2020-11-19"></script>
<script src="src/objects.js?version=2020-11-20"></script>
<script src="src/gui.js?version=2020-11-19"></script>
<script src="src/paint.js?version=2020-05-17"></script>
<script src="src/lists.js?version=2020-07-01"></script>

Wyświetl plik

@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, BooleanSlotMorph,
localize, TableMorph, TableFrameMorph, normalizeCanvas, VectorPaintEditorMorph,
AlignmentMorph, Process, WorldMap, copyCanvas, useBlurredShadows*/
modules.objects = '2020-November-19';
modules.objects = '2020-November-20';
var SpriteMorph;
var StageMorph;
@ -4387,6 +4387,47 @@ SpriteMorph.prototype.overlappingPixels = function (otherSprite) {
];
};
// SpriteMorph neighbor detection
SpriteMorph.prototype.neighbors = function (aStage) {
var stage = aStage || this.parentThatIsA(StageMorph),
myPerimeter = this.perimeter(stage);
return new List(
stage.children.filter(each => {
var eachPerimeter,
distance;
if (each instanceof SpriteMorph &&
each.isVisible &&
(each !== this)
) {
eachPerimeter = each.perimeter(stage);
distance = myPerimeter.center.distanceTo(eachPerimeter.center);
return (distance - myPerimeter.radius - eachPerimeter.radius)
< 0;
}
return false;
})
);
};
SpriteMorph.prototype.perimeter = function (aStage) {
var stage = aStage || this.parentThatIsA(StageMorph),
stageScale = this instanceof StageMorph ? 1 : stage.scale,
radius;
if (this.costume) {
radius = Math.max(
this.costume.width(),
this.costume.height()
) * this.scale * stageScale;
} else {
radius = Math.max(this.width(), this.height());
}
return {
center: this.center(), // geometric center rather than position
radius: radius * 1.5
};
};
// SpriteMorph pen ops
SpriteMorph.prototype.doStamp = function () {
@ -9044,16 +9085,16 @@ StageMorph.prototype.showingWatcher = SpriteMorph.prototype.showingWatcher;
StageMorph.prototype.addVariable = SpriteMorph.prototype.addVariable;
StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable;
// StageMorph neighbor detection
StageMorph.prototype.neighbors = SpriteMorph.prototype.neighbors;
StageMorph.prototype.perimeter = SpriteMorph.prototype.perimeter;
// StageMorph block rendering
StageMorph.prototype.doScreenshot
= SpriteMorph.prototype.doScreenshot;
StageMorph.prototype.newCostumeName
= SpriteMorph.prototype.newCostumeName;
StageMorph.prototype.blockForSelector
= SpriteMorph.prototype.blockForSelector;
StageMorph.prototype.doScreenshot = SpriteMorph.prototype.doScreenshot;
StageMorph.prototype.newCostumeName = SpriteMorph.prototype.newCostumeName;
StageMorph.prototype.blockForSelector = SpriteMorph.prototype.blockForSelector;
// StageMorph variable watchers (for palette checkbox toggling)

Wyświetl plik

@ -4856,7 +4856,6 @@ Process.prototype.reportGet = function (query) {
// answer a reference to a first-class member
// or a list of first-class members
var thisObj = this.blockReceiver(),
neighborhood,
stage,
objName;
@ -4896,6 +4895,9 @@ Process.prototype.reportGet = function (query) {
return thisObj.isTemporary ?
this.reportGet(['clones']) : new List();
case 'neighbors':
// old rectangular, bounding-box-based algorithm
// deprecated in favor of a circular perimeter based newer one
/*
stage = thisObj.parentThatIsA(StageMorph);
neighborhood = thisObj.bounds.expandBy(new Point(
thisObj.width(),
@ -4909,6 +4911,8 @@ Process.prototype.reportGet = function (query) {
each.bounds.intersects(neighborhood)
)
);
*/
return thisObj.neighbors();
case 'dangling?':
return !thisObj.rotatesWithAnchor;
case 'draggable?':