Fix major bug in layout iteration

This commit is contained in:
Ian Gulliver
2019-07-16 06:13:53 +00:00
parent a40c8ea1fc
commit 87f8d6edd8
3 changed files with 10 additions and 11 deletions

View File

@@ -125,11 +125,15 @@ class Layout {
if (obj.offsetCollides(offset)) {
continue;
}
obj.savePos();
for (let obj of objects) {
obj.savePos();
}
obj.moveBy(offset);
this.setTension(objects);
let testTension = this.getTotalTension(objects);
obj.restorePos();
for (let obj of objects) {
obj.restorePos();
}
if (testTension < baseTension) {
obj.moveBy(offset);
return true;

View File

@@ -35,18 +35,11 @@ class LayoutGroup {
}
savePos() {
for (let node of this.nodes) {
node.savePos();
}
this.savedVec_ = Array.from(this.vec);
}
restorePos() {
for (let node of this.nodes) {
node.restorePos();
}
for (let node of this.nodes) {
this.nodesByPos_.set(node.pos, node);
}
this.vec = this.savedVec_;
}
moveBy(offset) {

View File

@@ -132,10 +132,12 @@ class LayoutNode {
savePos() {
this.savedPos_ = this.pos;
this.savedVec_ = Array.from(this.vec);
}
restorePos() {
this.moveTo(this.savedPos_);
this.vec = this.savedVec_;
}
getStep() {