From 9ae02ad2c2676a5991c6c952952fc6fcfdb96304 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Fri, 27 Dec 2019 14:52:19 -0500 Subject: integrated .loc with space.fetch (and dependencies) --- space.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'space.js') diff --git a/space.js b/space.js index 2b535fd..4a227cf 100644 --- a/space.js +++ b/space.js @@ -82,11 +82,21 @@ function Space(){ return row; }); } - this.comb = function(other, func, offset){ + + this.comb = function(other, func){ // other must have a valid .loc. If this.loc null, treated as offset + if (! other.loc) throw "The secondary space must have a valid .loc" + if (this.loc.length == 0) { + offset = [0, 0]; + this.loc = other.loc; + } else { + offset = vec.sub(this.loc, other.loc); + if (this.data.length > 0) + this.loc = vec.elem(this.loc, other.loc, (a,b) => Math.min(a,b)); + } // offset is position of other relative to this, so these are mainly definitional. // Convert negative offsets of either sort into zero offsets with significant previous whitespace (translation) for (let i = 0; i < -offset[0]; i++) this.data.unshift([]); if (offset[0] < 0) offset[0] = 0; - for (let row = 0; row < offset[0]+other.data.length; row++){ // offset[1] < 0 fix + for (let row = 0; row < this.data.length; row++){ // offset[1] < 0 fix for (let i = 0; i < -offset[1]; i++) this.data[row].unshift(''); } if (offset[1] < 0) offset[1] = 0; -- cgit