From 87f8d6edd8bf3a78541ea3ee5925fa80a0e245dd Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 16 Jul 2019 06:13:53 +0000 Subject: [PATCH] Fix major bug in layout iteration --- Layout.js | 8 ++++++-- LayoutGroup.js | 11 ++--------- LayoutNode.js | 2 ++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Layout.js b/Layout.js index e939491..cc5674d 100644 --- a/Layout.js +++ b/Layout.js @@ -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; diff --git a/LayoutGroup.js b/LayoutGroup.js index e930049..0ff7c9f 100644 --- a/LayoutGroup.js +++ b/LayoutGroup.js @@ -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) { diff --git a/LayoutNode.js b/LayoutNode.js index 258f9fc..8f5f0dd 100644 --- a/LayoutNode.js +++ b/LayoutNode.js @@ -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() {