diff --git a/index.ts b/index.ts index f7ae591f..db8b6d43 100644 --- a/index.ts +++ b/index.ts @@ -29,7 +29,6 @@ export {RGBA} from "./lib/rgba.class"; export {Key} from "./lib/key.enum"; export {Button} from "./lib/button.enum"; export {centerOf, randomPointIn} from "./lib/location.function"; -export {LocationParameters} from "./lib/locationparameters.class"; export {OptionalSearchParameters} from "./lib/optionalsearchparameters.class"; export {EasingFunction, linear} from "./lib/mouse-movement.function"; export {Point} from "./lib/point.class"; diff --git a/lib/assert.class.ts b/lib/assert.class.ts index d050b3c1..6409e791 100644 --- a/lib/assert.class.ts +++ b/lib/assert.class.ts @@ -1,7 +1,7 @@ -import {LocationParameters} from "./locationparameters.class"; import {Region} from "./region.class"; import {ScreenClass} from "./screen.class"; import {FirstArgumentType} from "./typings"; +import {OptionalSearchParameters} from "./optionalsearchparameters.class"; export class AssertClass { constructor(private screen: ScreenClass) { @@ -13,7 +13,7 @@ export class AssertClass { try { await this.screen.find( needle, - {searchRegion, confidence} as LocationParameters, + {searchRegion, confidence} as OptionalSearchParameters, ); } catch (err) { if (searchRegion !== undefined) { @@ -32,7 +32,7 @@ export class AssertClass { try { await this.screen.find( needle, - {searchRegion, confidence} as LocationParameters, + {searchRegion, confidence} as OptionalSearchParameters, ); } catch (err) { return; diff --git a/lib/expect/matchers/toShow.function.ts b/lib/expect/matchers/toShow.function.ts index cdd9d56b..3b3c3848 100644 --- a/lib/expect/matchers/toShow.function.ts +++ b/lib/expect/matchers/toShow.function.ts @@ -1,6 +1,6 @@ -import {LocationParameters} from "../../locationparameters.class"; import {ScreenClass} from "../../screen.class"; import {FirstArgumentType} from "../../typings"; +import {OptionalSearchParameters} from "../../optionalsearchparameters.class"; export const toShow = async ( received: ScreenClass, @@ -9,7 +9,7 @@ export const toShow = async ( ) => { let locationParams; if (confidence) { - locationParams = new LocationParameters(); + locationParams = new OptionalSearchParameters(); locationParams.confidence = confidence; } const identifier = (await needle).id; diff --git a/lib/locationparameters.class.ts b/lib/locationparameters.class.ts deleted file mode 100644 index 0febeb5f..00000000 --- a/lib/locationparameters.class.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {OptionalSearchParameters} from "./optionalsearchparameters.class"; - -/** - * {@deprecated This module serves as a polyfill to not break existing pre v1.5 code. Will be removed in v2.0.0} - * Use {@link OptionalSearchParameters} instead - */ -export { - OptionalSearchParameters as LocationParameters -} \ No newline at end of file diff --git a/lib/region.class.spec.ts b/lib/region.class.spec.ts index df1c0b64..077f46d1 100644 --- a/lib/region.class.spec.ts +++ b/lib/region.class.spec.ts @@ -1,7 +1,7 @@ import { Region } from "./region.class"; describe("Region", () => { - it("should calcutate the correct area of a region", () => { + it("should calculate the correct area of a region", () => { const region = new Region(0, 0, 100, 100); const expected = 10000; @@ -14,56 +14,4 @@ describe("Region", () => { expect(region.toString()).toEqual(expected); }); - - it("should scale and translate in x", () => { - const scaleFactor = 2.0; - const region = new Region(100, 100, 100, 100); - const result = Region.scaled(region, scaleFactor); - - expect(result.left).toBeCloseTo(region.left * scaleFactor); - expect(result.width).toBeCloseTo(region.width * scaleFactor); - expect(result.top).toBeCloseTo(region.top); - expect(result.height).toBeCloseTo(region.height); - }); - - it("should scale and translate in y", () => { - const scaleFactor = 2.0; - const region = new Region(200, 250, 100, 100); - const result = Region.scaled(region, undefined, scaleFactor); - - expect(result.left).toBeCloseTo(region.left); - expect(result.width).toBeCloseTo(region.width); - expect(result.top).toBeCloseTo(region.top * scaleFactor); - expect(result.height).toBeCloseTo(region.height * scaleFactor); - }); - - it("should scale and translate in both x and y", () => { - const scaleFactorX = 1.75; - const scaleFactorY = 2.5; - const region = new Region(300, 720, 100, 100); - const result = Region.scaled(region, scaleFactorX, scaleFactorY); - - expect(result.left).toBeCloseTo(region.left * scaleFactorX); - expect(result.width).toBeCloseTo(region.width * scaleFactorX); - expect(result.top).toBeCloseTo(region.top * scaleFactorY); - expect(result.height).toBeCloseTo(region.height * scaleFactorY); - }); - - it("should throw an error when scaling to 0 in x", () => { - const scaleFactorX = 0.0; - const scaleFactorY = 2.5; - const region = new Region(300, 720, 100, 100); - expect(() => Region.scaled(region, scaleFactorX, scaleFactorY)).toThrow( - `Scaling to 0. Please check parameters: scaleX: ${scaleFactorX}, scaleY: ${scaleFactorY}`, - ); - }); - - it("should throw an error when scaling to 0 in y", () => { - const scaleFactorX = 2.5; - const scaleFactorY = 0.0; - const region = new Region(300, 720, 100, 100); - expect(() => Region.scaled(region, scaleFactorX, scaleFactorY)).toThrow( - `Scaling to 0. Please check parameters: scaleX: ${scaleFactorX}, scaleY: ${scaleFactorY}`, - ); - }); }); diff --git a/lib/region.class.ts b/lib/region.class.ts index 1f428948..8dd15f4a 100644 --- a/lib/region.class.ts +++ b/lib/region.class.ts @@ -1,22 +1,4 @@ export class Region { - public static scaled( - region: Region, - scaleX: number = 1.0, - scaleY: number = 1.0, - ): Region { - if (scaleX === 0 || scaleY === 0) { - throw new Error( - `Scaling to 0. Please check parameters: scaleX: ${scaleX}, scaleY: ${scaleY}`, - ); - } - return new Region( - region.left * scaleX, - region.top * scaleY, - region.width * scaleX, - region.height * scaleY, - ); - } - constructor( public left: number, public top: number, diff --git a/lib/screen.class.spec.ts b/lib/screen.class.spec.ts index 6f8e4fd7..a302f352 100644 --- a/lib/screen.class.spec.ts +++ b/lib/screen.class.spec.ts @@ -1,7 +1,6 @@ import {join} from "path"; import {cwd} from "process"; import {Image} from "./image.class"; -import {LocationParameters} from "./locationparameters.class"; import {MatchRequest} from "./match-request.class"; import {MatchResult} from "./match-result.class"; import {Region} from "./region.class"; @@ -9,6 +8,7 @@ import {ScreenClass} from "./screen.class"; import {mockPartial} from "sneer"; import {ProviderRegistry} from "./provider/provider-registry.class"; import {ImageFinderInterface, ImageWriter, ScreenProviderInterface} from "./provider"; +import {OptionalSearchParameters} from "./optionalsearchparameters.class"; jest.mock('jimp', () => { }); @@ -165,7 +165,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(undefined, minMatch); + const parameters = new OptionalSearchParameters(undefined, minMatch); // WHEN const resultRegion = SUT.find(needle, parameters); @@ -193,7 +193,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(customSearchRegion); + const parameters = new OptionalSearchParameters(customSearchRegion); const expectedMatchRequest = new MatchRequest( expect.any(Image), needle, @@ -218,7 +218,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(searchRegion, undefined, false); + const parameters = new OptionalSearchParameters(searchRegion, undefined, false); const expectedMatchRequest = new MatchRequest( expect.any(Image), needle, @@ -244,7 +244,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(customSearchRegion, minMatch); + const parameters = new OptionalSearchParameters(customSearchRegion, minMatch); const expectedMatchRequest = new MatchRequest( expect.any(Image), needle, @@ -413,7 +413,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(undefined, minMatch); + const parameters = new OptionalSearchParameters(undefined, minMatch); // WHEN const [resultRegion] = await SUT.findAll(needle, parameters); @@ -441,7 +441,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(customSearchRegion); + const parameters = new OptionalSearchParameters(customSearchRegion); const expectedMatchRequest = new MatchRequest( expect.any(Image), needle, @@ -466,7 +466,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(searchRegion, undefined, false); + const parameters = new OptionalSearchParameters(searchRegion, undefined, false); const expectedMatchRequest = new MatchRequest( expect.any(Image), needle, @@ -492,7 +492,7 @@ describe("Screen.", () => { const SUT = new ScreenClass(providerRegistryMock); const needle = new Image(100, 100, Buffer.from([]), 3, "needle_image"); - const parameters = new LocationParameters(customSearchRegion, minMatch); + const parameters = new OptionalSearchParameters(customSearchRegion, minMatch); const expectedMatchRequest = new MatchRequest( expect.any(Image), needle, diff --git a/lib/screen.class.ts b/lib/screen.class.ts index 754d4681..d7c62b62 100644 --- a/lib/screen.class.ts +++ b/lib/screen.class.ts @@ -1,7 +1,6 @@ import {cwd} from "process"; import {FileType} from "./file-type.enum"; import {generateOutputPath} from "./generate-output-path.function"; -import {LocationParameters} from "./locationparameters.class"; import {MatchRequest} from "./match-request.class"; import {MatchResult} from "./match-result.class"; import {Region} from "./region.class"; @@ -10,6 +9,7 @@ import {Image} from "./image.class"; import {ProviderRegistry} from "./provider/provider-registry.class"; import {FirstArgumentType} from "./typings"; import {Point} from "./point.class"; +import {OptionalSearchParameters} from "./optionalsearchparameters.class"; export type FindHookCallback = (target: MatchResult) => Promise; @@ -97,7 +97,7 @@ export class ScreenClass { */ public async find( template: Image | Promise, - params?: LocationParameters, + params?: OptionalSearchParameters, ): Promise { const minMatch = (params && params.confidence) || this.config.confidence; const screenSize = await this.providerRegistry.getScreen().screenSize(); @@ -149,7 +149,7 @@ export class ScreenClass { */ public async findAll( template: FirstArgumentType, - params?: LocationParameters, + params?: OptionalSearchParameters, ): Promise { const minMatch = (params && params.confidence) || this.config.confidence; const screenSize = await this.providerRegistry.getScreen().screenSize(); @@ -220,7 +220,7 @@ export class ScreenClass { templateImage: FirstArgumentType, timeoutMs: number = 5000, updateInterval: number = 500, - params?: LocationParameters, + params?: OptionalSearchParameters, ): Promise { return timeout(updateInterval, timeoutMs, () => this.find(templateImage, params), {signal: params?.abort}); }