mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[lazy-brush] Add definitions (#41526)
* Add lazy-brush definitions * Add instance properties
This commit is contained in:
committed by
Eli Barzilay
parent
82eb617a22
commit
5b98cd7e9b
Vendored
+145
@@ -0,0 +1,145 @@
|
||||
// Type definitions for lazy-brush 1.0
|
||||
// Project: https://github.com/dulnan/lazy-brush#readme
|
||||
// Definitions by: Kamil Socha <https://github.com/ksocha>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface Coordinates {
|
||||
x: number;
|
||||
|
||||
y: number;
|
||||
}
|
||||
|
||||
export class Point implements Coordinates {
|
||||
x: number;
|
||||
|
||||
y: number;
|
||||
|
||||
constructor(x: number, y: number);
|
||||
}
|
||||
|
||||
export class LazyPoint extends Point {
|
||||
/**
|
||||
* Update the x and y values
|
||||
*/
|
||||
update(coordinates: Coordinates): void;
|
||||
|
||||
/**
|
||||
* Move the point to another position using an angle and distance
|
||||
*/
|
||||
moveByAngle(angle: number, distance: number): void;
|
||||
|
||||
/**
|
||||
* Get the difference for x and y axis to another point
|
||||
*/
|
||||
getDifferenceTo(point: Coordinates): Point;
|
||||
|
||||
/**
|
||||
* Calculate distance to another point
|
||||
*/
|
||||
getDistanceTo(point: Coordinates): number;
|
||||
|
||||
/**
|
||||
* Calculate the angle to another point
|
||||
*/
|
||||
getAngleTo(point: Coordinates): number;
|
||||
|
||||
/**
|
||||
* Check if this point is the same as another point
|
||||
*/
|
||||
equalsTo(point: Coordinates): boolean;
|
||||
|
||||
/**
|
||||
* Return a simple object with x and y properties
|
||||
*/
|
||||
toObject(): Coordinates;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
radius?: number;
|
||||
enabled?: boolean;
|
||||
initialPoint?: Coordinates;
|
||||
}
|
||||
|
||||
export interface UpdateOptions {
|
||||
both: boolean;
|
||||
}
|
||||
|
||||
export class LazyBrush {
|
||||
radius: number;
|
||||
|
||||
_isEnabled: boolean;
|
||||
|
||||
pointer: LazyPoint;
|
||||
|
||||
brush: LazyPoint;
|
||||
|
||||
angle: number;
|
||||
|
||||
distance: number;
|
||||
|
||||
_hasMoved: boolean;
|
||||
|
||||
constructor(options?: Options);
|
||||
|
||||
/**
|
||||
* Enable lazy brush calculations
|
||||
*/
|
||||
enable(): void;
|
||||
|
||||
/**
|
||||
* Disable lazy brush calculations
|
||||
*/
|
||||
disable(): void;
|
||||
|
||||
isEnabled(): boolean;
|
||||
|
||||
/**
|
||||
* Update the radius
|
||||
*/
|
||||
setRadius(radius: number): void;
|
||||
|
||||
/**
|
||||
* Return the current radius
|
||||
*/
|
||||
getRadius(): number;
|
||||
|
||||
/**
|
||||
* Updates the pointer coordinates and calculates the new brush point
|
||||
*/
|
||||
update(coordinates: Coordinates, options?: UpdateOptions): boolean;
|
||||
|
||||
/**
|
||||
* Return the brush as a LazyPoint
|
||||
*/
|
||||
getBrush(): LazyPoint;
|
||||
|
||||
/**
|
||||
* Return the brush coordinates as a simple object
|
||||
*/
|
||||
getBrushCoordinates(): Coordinates;
|
||||
|
||||
/**
|
||||
* Return the pointer as a LazyPoint
|
||||
*/
|
||||
getPointer(): LazyPoint;
|
||||
|
||||
/**
|
||||
* Return the pointer coordinates as a simple object
|
||||
*/
|
||||
getPointerCoordinates(): Coordinates;
|
||||
|
||||
/**
|
||||
* Return the angle between pointer and brush
|
||||
*/
|
||||
getAngle(): number;
|
||||
|
||||
/**
|
||||
* Return the distance between pointer and brush
|
||||
*/
|
||||
getDistance(): number;
|
||||
|
||||
/**
|
||||
* Return if the previous update has moved the brush
|
||||
*/
|
||||
brushHasMoved(): boolean;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { LazyBrush, Point, LazyPoint, Coordinates } from 'lazy-brush';
|
||||
|
||||
const point = new Point(1, 2);
|
||||
const pointX: number = point.x;
|
||||
const pointY: number = point.y;
|
||||
|
||||
const lazyPoint = new LazyPoint(1, 2);
|
||||
const lazyPointX: number = lazyPoint.x;
|
||||
const lazyPointY: number = lazyPoint.y;
|
||||
const equalsToResult: boolean = lazyPoint.equalsTo({ x: 1, y: 4 });
|
||||
const getAngleToResult: number = lazyPoint.getAngleTo(point);
|
||||
const getDifferenceToResult: Point = lazyPoint.getDifferenceTo(point);
|
||||
const getDistanceToResult: number = lazyPoint.getDistanceTo(point);
|
||||
lazyPoint.moveByAngle(45, 20);
|
||||
const toObjectResult: Coordinates = lazyPoint.toObject();
|
||||
lazyPoint.update({ x: 1, y: 7 });
|
||||
|
||||
new LazyBrush();
|
||||
new LazyBrush({ radius: 20 });
|
||||
const lazy = new LazyBrush({
|
||||
radius: 30,
|
||||
enabled: true,
|
||||
initialPoint: { x: 0, y: 0 },
|
||||
});
|
||||
|
||||
const radiusValue: number = lazy.radius;
|
||||
const _isEnabledValue: boolean = lazy._isEnabled;
|
||||
const pointerValue: LazyPoint = lazy.pointer;
|
||||
const brushValue: LazyPoint = lazy.brush;
|
||||
const angleValue: number = lazy.angle;
|
||||
const distanceValue: number = lazy.distance;
|
||||
const _hasMovedValue: boolean = lazy._hasMoved;
|
||||
|
||||
const updateResult: boolean = lazy.update({ x: 50, y: 0 });
|
||||
const updateResult2: boolean = lazy.update({ x: 50, y: 0 }, { both: true });
|
||||
const brushHasMovedResult: boolean = lazy.brushHasMoved();
|
||||
lazy.disable();
|
||||
lazy.enable();
|
||||
const isEnabledResult: boolean = lazy.isEnabled();
|
||||
const getAngleResult: number = lazy.getAngle();
|
||||
const getBrushResult: LazyPoint = lazy.getBrush();
|
||||
const getBrushCoordinatesResult: Coordinates = lazy.getBrushCoordinates();
|
||||
const getDistanceResult: number = lazy.getDistance();
|
||||
const getPointerResult: LazyPoint = lazy.getPointer();
|
||||
const getPointerCoordinatesResult: Coordinates = lazy.getPointerCoordinates();
|
||||
const getRadiusResult: number = lazy.getRadius();
|
||||
lazy.setRadius(12);
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"lazy-brush-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user