forked from thi-ng/umbrella
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hvline.ts
51 lines (47 loc) · 1005 Bytes
/
hvline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { asInt } from "@thi.ng/api/typedarray";
export function* hline(x: number, y: number, len: number) {
[x, y, len] = asInt(x, y, len);
for (const xmax = x + len; x < xmax; x++) {
yield [x, y];
}
}
export function* vline(x: number, y: number, len: number) {
[x, y, len] = asInt(x, y, len);
for (const ymax = y + len; y < ymax; y++) {
yield [x, y];
}
}
export function* hlineClipped(
x: number,
y: number,
len: number,
left: number,
top: number,
right: number,
bottom: number
) {
[x, y, len] = asInt(x, y, len);
if (x >= right || y < top || y >= bottom) return;
if (x < left) {
len += x - left;
x = left;
}
yield* hline(x, y, Math.min(len, right - x));
}
export function* vlineClipped(
x: number,
y: number,
len: number,
left: number,
top: number,
right: number,
bottom: number
) {
[x, y, len] = asInt(x, y, len);
if (x < left || x >= right || y >= bottom) return;
if (y < top) {
len += y - top;
y = top;
}
yield* vline(x, y, Math.min(len, bottom - y));
}