Skip to content

Commit 590e3c1

Browse files
committed
(#341) Remove Region#scaled
1 parent 93c455c commit 590e3c1

File tree

2 files changed

+1
-71
lines changed

2 files changed

+1
-71
lines changed

lib/region.class.spec.ts

+1-53
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Region } from "./region.class";
22

33
describe("Region", () => {
4-
it("should calcutate the correct area of a region", () => {
4+
it("should calculate the correct area of a region", () => {
55
const region = new Region(0, 0, 100, 100);
66
const expected = 10000;
77

@@ -14,56 +14,4 @@ describe("Region", () => {
1414

1515
expect(region.toString()).toEqual(expected);
1616
});
17-
18-
it("should scale and translate in x", () => {
19-
const scaleFactor = 2.0;
20-
const region = new Region(100, 100, 100, 100);
21-
const result = Region.scaled(region, scaleFactor);
22-
23-
expect(result.left).toBeCloseTo(region.left * scaleFactor);
24-
expect(result.width).toBeCloseTo(region.width * scaleFactor);
25-
expect(result.top).toBeCloseTo(region.top);
26-
expect(result.height).toBeCloseTo(region.height);
27-
});
28-
29-
it("should scale and translate in y", () => {
30-
const scaleFactor = 2.0;
31-
const region = new Region(200, 250, 100, 100);
32-
const result = Region.scaled(region, undefined, scaleFactor);
33-
34-
expect(result.left).toBeCloseTo(region.left);
35-
expect(result.width).toBeCloseTo(region.width);
36-
expect(result.top).toBeCloseTo(region.top * scaleFactor);
37-
expect(result.height).toBeCloseTo(region.height * scaleFactor);
38-
});
39-
40-
it("should scale and translate in both x and y", () => {
41-
const scaleFactorX = 1.75;
42-
const scaleFactorY = 2.5;
43-
const region = new Region(300, 720, 100, 100);
44-
const result = Region.scaled(region, scaleFactorX, scaleFactorY);
45-
46-
expect(result.left).toBeCloseTo(region.left * scaleFactorX);
47-
expect(result.width).toBeCloseTo(region.width * scaleFactorX);
48-
expect(result.top).toBeCloseTo(region.top * scaleFactorY);
49-
expect(result.height).toBeCloseTo(region.height * scaleFactorY);
50-
});
51-
52-
it("should throw an error when scaling to 0 in x", () => {
53-
const scaleFactorX = 0.0;
54-
const scaleFactorY = 2.5;
55-
const region = new Region(300, 720, 100, 100);
56-
expect(() => Region.scaled(region, scaleFactorX, scaleFactorY)).toThrow(
57-
`Scaling to 0. Please check parameters: scaleX: ${scaleFactorX}, scaleY: ${scaleFactorY}`,
58-
);
59-
});
60-
61-
it("should throw an error when scaling to 0 in y", () => {
62-
const scaleFactorX = 2.5;
63-
const scaleFactorY = 0.0;
64-
const region = new Region(300, 720, 100, 100);
65-
expect(() => Region.scaled(region, scaleFactorX, scaleFactorY)).toThrow(
66-
`Scaling to 0. Please check parameters: scaleX: ${scaleFactorX}, scaleY: ${scaleFactorY}`,
67-
);
68-
});
6917
});

lib/region.class.ts

-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
11
export class Region {
2-
public static scaled(
3-
region: Region,
4-
scaleX: number = 1.0,
5-
scaleY: number = 1.0,
6-
): Region {
7-
if (scaleX === 0 || scaleY === 0) {
8-
throw new Error(
9-
`Scaling to 0. Please check parameters: scaleX: ${scaleX}, scaleY: ${scaleY}`,
10-
);
11-
}
12-
return new Region(
13-
region.left * scaleX,
14-
region.top * scaleY,
15-
region.width * scaleX,
16-
region.height * scaleY,
17-
);
18-
}
19-
202
constructor(
213
public left: number,
224
public top: number,

0 commit comments

Comments
 (0)