Skip to content

Maintenance/341/remove old code #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions lib/assert.class.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) {
Expand All @@ -32,7 +32,7 @@ export class AssertClass {
try {
await this.screen.find(
needle,
{searchRegion, confidence} as LocationParameters,
{searchRegion, confidence} as OptionalSearchParameters,
);
} catch (err) {
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/expect/matchers/toShow.function.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions lib/locationparameters.class.ts

This file was deleted.

54 changes: 1 addition & 53 deletions lib/region.class.spec.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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}`,
);
});
});
18 changes: 0 additions & 18 deletions lib/region.class.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
18 changes: 9 additions & 9 deletions lib/screen.class.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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";
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', () => {
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/screen.class.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<void>;

Expand Down Expand Up @@ -97,7 +97,7 @@ export class ScreenClass {
*/
public async find(
template: Image | Promise<Image>,
params?: LocationParameters,
params?: OptionalSearchParameters,
): Promise<Region> {
const minMatch = (params && params.confidence) || this.config.confidence;
const screenSize = await this.providerRegistry.getScreen().screenSize();
Expand Down Expand Up @@ -149,7 +149,7 @@ export class ScreenClass {
*/
public async findAll(
template: FirstArgumentType<typeof ScreenClass.prototype.find>,
params?: LocationParameters,
params?: OptionalSearchParameters,
): Promise<Region[]> {
const minMatch = (params && params.confidence) || this.config.confidence;
const screenSize = await this.providerRegistry.getScreen().screenSize();
Expand Down Expand Up @@ -220,7 +220,7 @@ export class ScreenClass {
templateImage: FirstArgumentType<typeof ScreenClass.prototype.find>,
timeoutMs: number = 5000,
updateInterval: number = 500,
params?: LocationParameters,
params?: OptionalSearchParameters,
): Promise<Region> {
return timeout(updateInterval, timeoutMs, () => this.find(templateImage, params), {signal: params?.abort});
}
Expand Down