aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-07-16 12:40:56 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-07-16 12:41:55 -0400
commit5cc071b82b8916a9c6fc213599a3714612b5cfcb (patch)
tree15a6c723039d8055ad4a0c489a6e0c2531800e34
parentdb24fbe16e0f73f9278f4ec090be756c9704dee1 (diff)
improved space correctness
Subsections have valid locs, and built-in assumptions are asserted like a valid loc in a towrite() or the structure of a subsection() call
-rw-r--r--space.js3
1 files changed, 3 insertions, 0 deletions
diff --git a/space.js b/space.js
index 1828dda..65b5355 100644
--- a/space.js
+++ b/space.js
@@ -53,6 +53,7 @@ function Space(){
}
this.towrite = function(){ // Does no splitting or anything like that. Just returns a list of triplets for the write function
+ if (this.loc[0] === undefined) throw "Space.towrite() requires valid loc";
let writes = [];
for (let line = 0; line < this.data.length; line++) for (let chr = 0; chr < this.data[line].length; chr++){
if (this.data[line][chr] == '') continue; // Internal coding for "do not write"
@@ -138,6 +139,7 @@ function Space(){
}
this.subsection = function(range){ // range is a coordinate pair
+ if (range.length !== 2 || range[0].length !== 2) throw "not subsecting a coord pair";
// Similarly excludes this.loc
newspace = new Space();
for (let line=range[0][0]; line<range[1][0]; line++){
@@ -147,6 +149,7 @@ function Space(){
newspace.data[line-range[0][0]].push(thisline[chr] || '');
}
}
+ newspace.loc = [range[0][0], range[0][1]];
return newspace;
}