@packtrack/layout 1.6.4 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { SectionPosition } from "./position";
2
2
  import { Router } from "./router";
3
+ import { Span } from "./span";
3
4
  export class Section {
4
5
  name;
5
6
  district;
@@ -60,53 +61,33 @@ export class Section {
60
61
  }
61
62
  }
62
63
  }
64
+ // TODO verifiy reverse
63
65
  getTilesInRange(startPosition, endPosition) {
64
- if (startPosition.section != this && endPosition.section != this) {
65
- return {
66
- offset: {
67
- start: 0,
68
- end: this.tiles[this.tiles.length - 1].pattern.length
69
- },
70
- tiles: [...this.tiles]
71
- };
72
- }
73
- let start = 0;
74
- let end = this.length;
75
- // only use the position limit if it is within our section
76
- if (startPosition.section == this) {
77
- end = startPosition.absolutePosition;
78
- }
79
- if (endPosition.section == this) {
80
- start = endPosition.absolutePosition;
81
- }
82
- // flip if the range was reversed
83
- if (end < start) {
84
- const small = end;
85
- end = start;
86
- start = small;
87
- }
88
- let passed = 0;
66
+ const span = Span.trail(startPosition, endPosition);
89
67
  const tiles = [];
90
- const tileUnitLength = this.length / this.tileLength;
91
- const offset = {
92
- start: 0,
93
- end: 0
94
- };
95
- for (let tile of this.tiles) {
96
- const length = tile.pattern.length * tileUnitLength;
97
- if (start - length <= passed && end + length >= passed) {
98
- tiles.push(tile);
99
- if (start <= passed) {
100
- offset.start = (start + length - passed) * tile.pattern.length / length;
101
- }
102
- if (end >= passed) {
103
- offset.end = 0.5; // (start + length - passed) * tile.pattern.length / length;
104
- }
68
+ let sectionLength = 0;
69
+ if (startPosition.section == endPosition.section) {
70
+ sectionLength = startPosition.section.length;
71
+ tiles.push(...startPosition.section.tiles);
72
+ }
73
+ else {
74
+ sectionLength += startPosition.section.length;
75
+ tiles.push(...startPosition.section.tiles);
76
+ for (let inside of span.inside) {
77
+ sectionLength += inside.length;
78
+ tiles.push(...inside.tiles);
105
79
  }
106
- passed += length;
80
+ sectionLength += endPosition.section.length;
81
+ tiles.push(...endPosition.section.tiles);
82
+ }
83
+ let tileLength = 0;
84
+ for (let tile of tiles) {
85
+ tileLength += tile.pattern.length;
107
86
  }
87
+ const start = tileLength / sectionLength * startPosition.absolutePosition;
88
+ const end = tileLength - tileLength / sectionLength * (endPosition.section.length - endPosition.absolutePosition);
108
89
  return {
109
- offset,
90
+ offset: { start, end },
110
91
  tiles
111
92
  };
112
93
  }
@@ -14,12 +14,12 @@ export class Span {
14
14
  }
15
15
  if (position.section == this.head.section && position.section == this.tail.section) {
16
16
  if (this.head.reversed) {
17
- if (this.head.absolutePosition > position.absolutePosition && this.tail.absolutePosition < position.absolutePosition) {
17
+ if (this.head.absolutePosition >= position.absolutePosition && this.tail.absolutePosition <= position.absolutePosition) {
18
18
  return true;
19
19
  }
20
20
  }
21
21
  else {
22
- if (this.head.offset < position.absolutePosition && this.tail.offset > position.absolutePosition) {
22
+ if (this.head.offset <= position.absolutePosition && this.tail.offset >= position.absolutePosition) {
23
23
  return true;
24
24
  }
25
25
  }
@@ -27,24 +27,24 @@ export class Span {
27
27
  }
28
28
  if (position.section == this.head.section) {
29
29
  if (this.head.reversed) {
30
- if (this.head.absolutePosition > position.absolutePosition) {
30
+ if (this.head.absolutePosition >= position.absolutePosition) {
31
31
  return true;
32
32
  }
33
33
  }
34
34
  else {
35
- if (this.head.offset < position.absolutePosition) {
35
+ if (this.head.offset <= position.absolutePosition) {
36
36
  return true;
37
37
  }
38
38
  }
39
39
  }
40
40
  if (position.section == this.tail.section) {
41
41
  if (this.tail.reversed) {
42
- if (this.tail.absolutePosition < position.absolutePosition) {
42
+ if (this.tail.absolutePosition <= position.absolutePosition) {
43
43
  return true;
44
44
  }
45
45
  }
46
46
  else {
47
- if (this.tail.offset > position.absolutePosition) {
47
+ if (this.tail.offset >= position.absolutePosition) {
48
48
  return true;
49
49
  }
50
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@packtrack/layout",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "type": "module",
5
5
  "main": ".built/index.js",
6
6
  "typings": ".built/index.d.ts",
package/source/section.ts CHANGED
@@ -2,6 +2,7 @@ import { District } from "./district";
2
2
  import { SectionPosition } from "./position";
3
3
  import { PowerDistrict } from "./power-district/index";
4
4
  import { Router } from "./router";
5
+ import { Span } from "./span";
5
6
  import { Tile } from "./tile";
6
7
  import { Track } from "./track";
7
8
 
@@ -80,68 +81,41 @@ export class Section {
80
81
  }
81
82
  }
82
83
 
84
+ // TODO verifiy reverse
83
85
  getTilesInRange(startPosition: SectionPosition, endPosition: SectionPosition) {
84
- if (startPosition.section != this && endPosition.section != this) {
85
- return {
86
- offset: {
87
- start: 0,
88
- end: this.tiles[this.tiles.length - 1].pattern.length
89
- },
90
-
91
- tiles: [...this.tiles]
92
- };
93
- }
94
-
95
- let start = 0;
96
- let end = this.length;
97
-
98
- // only use the position limit if it is within our section
99
- if (startPosition.section == this) {
100
- end = startPosition.absolutePosition;
101
- }
102
-
103
- if (endPosition.section == this) {
104
- start = endPosition.absolutePosition;
105
- }
106
-
107
- // flip if the range was reversed
108
- if (end < start) {
109
- const small = end;
110
-
111
- end = start;
112
- start = small;
113
- }
86
+ const span = Span.trail(startPosition, endPosition);
114
87
 
115
- let passed = 0;
116
88
  const tiles: Tile[] = [];
117
89
 
118
- const tileUnitLength = this.length / this.tileLength;
90
+ let sectionLength = 0;
119
91
 
120
- const offset = {
121
- start: 0,
122
- end: 0
123
- };
124
-
125
- for (let tile of this.tiles) {
126
- const length = tile.pattern.length * tileUnitLength;
92
+ if (startPosition.section == endPosition.section) {
93
+ sectionLength = startPosition.section.length;
94
+ tiles.push(...startPosition.section.tiles);
95
+ } else {
96
+ sectionLength += startPosition.section.length;
97
+ tiles.push(...startPosition.section.tiles);
127
98
 
128
- if (start - length <= passed && end + length >= passed) {
129
- tiles.push(tile);
99
+ for (let inside of span.inside) {
100
+ sectionLength += inside.length;
101
+ tiles.push(...inside.tiles);
102
+ }
130
103
 
131
- if (start <= passed) {
132
- offset.start = (start + length - passed) * tile.pattern.length / length;
133
- }
104
+ sectionLength += endPosition.section.length;
105
+ tiles.push(...endPosition.section.tiles);
106
+ }
134
107
 
135
- if (end >= passed) {
136
- offset.end = 0.5; // (start + length - passed) * tile.pattern.length / length;
137
- }
138
- }
108
+ let tileLength = 0;
139
109
 
140
- passed += length;
110
+ for (let tile of tiles) {
111
+ tileLength += tile.pattern.length;
141
112
  }
142
113
 
114
+ const start = tileLength / sectionLength * startPosition.absolutePosition;
115
+ const end = tileLength - tileLength / sectionLength * (endPosition.section.length - endPosition.absolutePosition);
116
+
143
117
  return {
144
- offset,
118
+ offset: { start, end },
145
119
  tiles
146
120
  };
147
121
  }
package/source/span.ts CHANGED
@@ -16,11 +16,11 @@ export class Span {
16
16
 
17
17
  if (position.section == this.head.section && position.section == this.tail.section) {
18
18
  if (this.head.reversed) {
19
- if (this.head.absolutePosition > position.absolutePosition && this.tail.absolutePosition < position.absolutePosition) {
19
+ if (this.head.absolutePosition >= position.absolutePosition && this.tail.absolutePosition <= position.absolutePosition) {
20
20
  return true;
21
21
  }
22
22
  } else {
23
- if (this.head.offset < position.absolutePosition && this.tail.offset > position.absolutePosition) {
23
+ if (this.head.offset <= position.absolutePosition && this.tail.offset >= position.absolutePosition) {
24
24
  return true;
25
25
  }
26
26
  }
@@ -30,11 +30,11 @@ export class Span {
30
30
 
31
31
  if (position.section == this.head.section) {
32
32
  if (this.head.reversed) {
33
- if (this.head.absolutePosition > position.absolutePosition) {
33
+ if (this.head.absolutePosition >= position.absolutePosition) {
34
34
  return true;
35
35
  }
36
36
  } else {
37
- if (this.head.offset < position.absolutePosition) {
37
+ if (this.head.offset <= position.absolutePosition) {
38
38
  return true;
39
39
  }
40
40
  }
@@ -42,11 +42,11 @@ export class Span {
42
42
 
43
43
  if (position.section == this.tail.section) {
44
44
  if (this.tail.reversed) {
45
- if (this.tail.absolutePosition < position.absolutePosition) {
45
+ if (this.tail.absolutePosition <= position.absolutePosition) {
46
46
  return true;
47
47
  }
48
48
  } else {
49
- if (this.tail.offset > position.absolutePosition) {
49
+ if (this.tail.offset >= position.absolutePosition) {
50
50
  return true;
51
51
  }
52
52
  }