Skip to content

Commit 52a48e6

Browse files
test: draw outside image tests (#132)
1 parent 306beea commit 52a48e6

File tree

5 files changed

+120
-19
lines changed

5 files changed

+120
-19
lines changed

src/draw/__tests__/drawPoints.test.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ describe('drawPoints', () => {
9494
expect(result).toBe(out);
9595
expect(result).not.toBe(image);
9696
});
97-
9897
it('mask', () => {
99-
const image = testUtils.createMask([
98+
const mask = testUtils.createMask([
10099
[0, 0, 0, 0],
101100
[0, 0, 0, 0],
102101
[0, 0, 0, 0],
@@ -107,17 +106,17 @@ describe('drawPoints', () => {
107106
{ row: 1, column: 0 },
108107
{ row: 0, column: 1 },
109108
];
110-
const result = image.drawPoints(points);
111-
expect(result).toMatchImageData([
109+
const result = mask.drawPoints(points);
110+
expect(result).toMatchMaskData([
112111
[1, 1, 0, 0],
113112
[1, 0, 0, 0],
114113
[0, 0, 0, 0],
115114
[0, 0, 0, 0],
116115
]);
117-
expect(result).not.toBe(image);
116+
expect(result).not.toBe(mask);
118117
});
119118
it('default options', () => {
120-
const image = testUtils.createMask([
119+
const mask = testUtils.createMask([
121120
[0, 0, 0, 0],
122121
[0, 0, 0, 0],
123122
[0, 0, 0, 0],
@@ -128,17 +127,17 @@ describe('drawPoints', () => {
128127
{ row: 2, column: 0 },
129128
{ row: 0, column: 2 },
130129
];
131-
const result = drawPoints(image, points);
132-
expect(result).toMatchImageData([
130+
const result = drawPoints(mask, points);
131+
expect(result).toMatchMaskData([
133132
[0, 0, 1, 0],
134133
[0, 0, 0, 0],
135134
[1, 0, 1, 0],
136135
[0, 0, 0, 0],
137136
]);
138-
expect(result).not.toBe(image);
137+
expect(result).not.toBe(mask);
139138
});
140139
it('different origin', () => {
141-
const image = testUtils.createMask([
140+
const mask = testUtils.createMask([
142141
[0, 0, 0, 0],
143142
[0, 0, 0, 0],
144143
[0, 0, 0, 0],
@@ -150,17 +149,17 @@ describe('drawPoints', () => {
150149
{ row: 0, column: 1 },
151150
{ row: 0, column: 0 },
152151
];
153-
const result = drawPoints(image, points, { origin: { column: 2, row: 2 } });
154-
expect(result).toMatchImageData([
152+
const result = drawPoints(mask, points, { origin: { column: 2, row: 2 } });
153+
expect(result).toMatchMaskData([
155154
[0, 0, 0, 0],
156155
[0, 1, 1, 0],
157156
[0, 0, 1, 1],
158157
[0, 0, 0, 0],
159158
]);
160-
expect(result).not.toBe(image);
159+
expect(result).not.toBe(mask);
161160
});
162-
it('points outside image', () => {
163-
const image = testUtils.createMask([
161+
it('points outside mask', () => {
162+
const mask = testUtils.createMask([
164163
[0, 0, 0, 0],
165164
[0, 0, 0, 0],
166165
[0, 0, 0, 0],
@@ -173,13 +172,13 @@ describe('drawPoints', () => {
173172
{ row: 0, column: 0 },
174173
{ row: 2, column: 6 },
175174
];
176-
const result = drawPoints(image, points);
177-
expect(result).toMatchImageData([
175+
const result = drawPoints(mask, points);
176+
expect(result).toMatchMaskData([
178177
[1, 1, 0, 0],
179178
[0, 0, 0, 0],
180179
[0, 0, 0, 0],
181180
[0, 0, 0, 0],
182181
]);
183-
expect(result).not.toBe(image);
182+
expect(result).not.toBe(mask);
184183
});
185184
});

src/draw/__tests__/drawPolygonOnIjs.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,28 @@ describe('drawPolygon on IJS', () => {
288288
[0, 1, 0, 0],
289289
]);
290290
});
291+
it('outside of image', () => {
292+
const image = testUtils.createGreyImage([
293+
[0, 0, 0, 0],
294+
[0, 0, 0, 0],
295+
[0, 0, 0, 0],
296+
[0, 0, 0, 0],
297+
]);
298+
const points = [
299+
{ row: 0, column: 0 },
300+
{ row: 4, column: 4 },
301+
{ row: 4, column: -2 },
302+
];
303+
const result = image.drawPolygon(points, {
304+
strokeColor: [1],
305+
fillColor: [2],
306+
});
307+
expect(result).toMatchImageData([
308+
[1, 0, 0, 0],
309+
[1, 1, 0, 0],
310+
[2, 2, 1, 0],
311+
[2, 2, 2, 1],
312+
]);
313+
expect(result).not.toBe(image);
314+
});
291315
});

src/draw/__tests__/drawPolygonOnMask.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,30 @@ describe('drawPolygon on Mask', () => {
263263
]);
264264
expect(result).not.toBe(mask);
265265
});
266+
it('outside of mask', () => {
267+
const mask = testUtils.createMask([
268+
[0, 0, 0, 0, 0],
269+
[0, 0, 0, 0, 0],
270+
[0, 0, 0, 0, 0],
271+
[0, 0, 0, 0, 0],
272+
[0, 0, 0, 0, 0],
273+
]);
274+
275+
const points = [
276+
{ column: 0, row: 4 },
277+
{ column: 5, row: -1 },
278+
{ column: 1, row: -1 },
279+
];
280+
const result = mask.drawPolygon(points, {
281+
filled: true,
282+
});
283+
expect(result).toMatchMaskData([
284+
[0, 1, 1, 1, 1],
285+
[0, 1, 1, 1, 0],
286+
[1, 1, 1, 0, 0],
287+
[1, 1, 0, 0, 0],
288+
[1, 0, 0, 0, 0],
289+
]);
290+
expect(result).not.toBe(mask);
291+
});
266292
});

src/draw/__tests__/drawPolylineOnMask.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,30 @@ describe('drawPolyline on Mask', () => {
135135
]);
136136
expect(result).not.toBe(mask);
137137
});
138+
it('different origin, outside of mask', () => {
139+
const mask = testUtils.createMask([
140+
[0, 0, 0, 0, 0],
141+
[0, 0, 0, 0, 0],
142+
[0, 0, 0, 0, 0],
143+
[0, 0, 0, 0, 0],
144+
[0, 0, 0, 0, 0],
145+
]);
146+
const points = [
147+
{ row: 0, column: 0 },
148+
{ row: 0, column: 1 },
149+
{ row: 3, column: 1 },
150+
{ row: 3, column: 4 },
151+
];
152+
const result = mask.drawPolyline(points, {
153+
origin: { column: 0, row: 2 },
154+
});
155+
expect(result).toMatchMaskData([
156+
[0, 0, 0, 0, 0],
157+
[0, 0, 0, 0, 0],
158+
[1, 1, 0, 0, 0],
159+
[0, 1, 0, 0, 0],
160+
[0, 1, 0, 0, 0],
161+
]);
162+
expect(result).not.toBe(mask);
163+
});
138164
});

src/draw/__tests__/drawRectangle.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ describe('drawRectangle', () => {
162162
]);
163163
expect(result).not.toBe(image);
164164
});
165+
it('outside of image', () => {
166+
const image = testUtils.createGreyImage([
167+
[1, 1, 1, 1, 1, 1],
168+
[1, 1, 1, 1, 1, 1],
169+
[1, 1, 1, 1, 1, 1],
170+
[1, 1, 1, 1, 1, 1],
171+
[1, 1, 1, 1, 1, 1],
172+
[1, 1, 1, 1, 1, 1],
173+
]);
174+
const result = image.drawRectangle({
175+
width: image.width,
176+
height: image.height,
177+
strokeColor: [2],
178+
fillColor: [3],
179+
origin: { column: 1, row: 1 },
180+
});
181+
expect(result).toMatchImageData([
182+
[1, 1, 1, 1, 1, 1],
183+
[1, 2, 2, 2, 2, 2],
184+
[1, 2, 3, 3, 3, 3],
185+
[1, 2, 3, 3, 3, 3],
186+
[1, 2, 3, 3, 3, 3],
187+
[1, 2, 3, 3, 3, 3],
188+
]);
189+
expect(result).not.toBe(image);
190+
});
165191
it('mask, not filled', () => {
166192
const mask = testUtils.createMask([
167193
[0, 0, 0, 0, 0, 0],
@@ -239,7 +265,7 @@ describe('drawRectangle', () => {
239265
[1, 1, 1, 1, 1, 1],
240266
]);
241267
});
242-
it('points out of image', () => {
268+
it('points out of mask', () => {
243269
const mask = testUtils.createMask([
244270
[0, 0, 0, 0, 0, 0],
245271
[0, 0, 0, 0, 0, 0],

0 commit comments

Comments
 (0)