Skip to content

Commit 700c6ee

Browse files
authored
trim waffle slivers (#2205)
1 parent 27e8fff commit 700c6ee

File tree

8 files changed

+351
-111
lines changed

8 files changed

+351
-111
lines changed

src/marks/waffle.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,28 @@ function wafflePoints(i1, i2, columns) {
156156
if (i2 < i1) {
157157
return wafflePoints(i2, i1, columns);
158158
}
159-
return [
160-
[0, Math.ceil(i1 / columns)],
161-
[Math.floor(i1 % columns), Math.ceil(i1 / columns)],
162-
[Math.floor(i1 % columns), Math.floor(i1 / columns) + (i1 % 1)],
163-
[Math.ceil(i1 % columns), Math.floor(i1 / columns) + (i1 % 1)],
164-
...(i1 % columns > columns - 1
165-
? []
166-
: [
167-
[Math.ceil(i1 % columns), Math.floor(i1 / columns)],
168-
[columns, Math.floor(i1 / columns)]
169-
]),
170-
[columns, Math.floor(i2 / columns)],
171-
[Math.ceil(i2 % columns), Math.floor(i2 / columns)],
172-
[Math.ceil(i2 % columns), Math.floor(i2 / columns) + (i2 % 1)],
173-
[Math.floor(i2 % columns), Math.floor(i2 / columns) + (i2 % 1)],
174-
...(i2 % columns < 1
175-
? []
176-
: [
177-
[Math.floor(i2 % columns), Math.ceil(i2 / columns)],
178-
[0, Math.ceil(i2 / columns)]
179-
])
180-
];
159+
const x1f = Math.floor(i1 % columns);
160+
const x1c = Math.ceil(i1 % columns);
161+
const x2f = Math.floor(i2 % columns);
162+
const x2c = Math.ceil(i2 % columns);
163+
const y1f = Math.floor(i1 / columns);
164+
const y1c = Math.ceil(i1 / columns);
165+
const y2f = Math.floor(i2 / columns);
166+
const y2c = Math.ceil(i2 / columns);
167+
const points = [];
168+
if (y2c > y1c) points.push([0, y1c]);
169+
points.push([x1f, y1c], [x1f, y1f + (i1 % 1)], [x1c, y1f + (i1 % 1)]);
170+
if (!(i1 % columns > columns - 1)) {
171+
points.push([x1c, y1f]);
172+
if (y2f > y1f) points.push([columns, y1f]);
173+
}
174+
if (y2f > y1f) points.push([columns, y2f]);
175+
points.push([x2c, y2f], [x2c, y2f + (i2 % 1)], [x2f, y2f + (i2 % 1)]);
176+
if (!(i2 % columns < 1)) {
177+
points.push([x2f, y2c]);
178+
if (y2c > y1c) points.push([0, y2c]);
179+
}
180+
return points;
181181
}
182182

183183
function maybeRound(round) {

test/output/waffleHref.svg

Lines changed: 77 additions & 77 deletions
Loading

test/output/waffleMultiple.svg

Lines changed: 6 additions & 6 deletions
Loading

test/output/waffleRound.svg

Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)