@obliczeniowo/elementary
Version:
Library made in Angular version 19
108 lines (107 loc) • 4 kB
TypeScript
import { ColorType } from '../colors/color-interface';
export interface IPoint2D {
x: number;
y: number;
}
export interface IDrawText {
drawText: (text: string, handlePosition: Point2D, color: ColorType, angle: number, options?: any) => void;
setFontSize: (size: number) => void;
}
export declare class Point2D implements IPoint2D {
x: number;
y: number;
static isCorrectPoint(point: IPoint2D): boolean;
static fromInterface(iPoint: IPoint2D): Point2D;
/**
* Check if two lines described by pairs of points intersects with each other
* @param pt1 first line start point
* @param pt2 first line end point
* @param pt3 second line start point
* @param pt4 second line end point
* @returns true if intersection exist
*/
static linesIntersect(pt1: Point2D, pt2: Point2D, pt3: Point2D, pt4: Point2D): boolean;
constructor(x?: number, y?: number);
get isZeroLength(): boolean;
isPtInCircle(centralPoint: Point2D, ray: number): boolean;
isPtInRect(x: number, y: number, width: number, height: number): boolean;
isEqual(point2D: Point2D): boolean;
multiply(value: number): Point2D;
scalarMultiple(other: Point2D): number;
determinant(other: Point2D): number;
scale(xs: number, ys: number): Point2D;
add(point: Point2D): Point2D;
subtract(point: Point2D): Point2D;
length(): number;
/**
* Set vector length
* @param length new length to set
* @returns new instance of Point2D with new length if current length of vector is !== 0 in this case
* return degenerated { x: 0, y: 0 } vector
*/
setLength(length: number): Point2D;
/**
* Calculate x * x + y * y = scalarMultiple(this)
* @returns return sick length that can be useful to compare distance between points without calculate sqrt.
* for example if you have two points P1, P2 then P1.sickLength() < P2.sickLength() means P1 is closer to beginning of
* x = 0, y = 0 point then P2 (not require calculate sqrt)
*/
sickLength(): number;
angle(reverseX?: boolean): number;
/**
* rotate point by angle
* @param angle - in radians
* @returns new Instance of Point2D
*/
rotate(angle: number): Point2D;
/**
* Calculate Point2D containing coordinates of point thrown perpendicularly on line
* @param startLinePoint first point of line
* @param endLinePoint last point of line
* @returns if points are equal then null, if not then new instance of Point2D containing coordinates of point thrown
* perpendicularly on line
*/
getPointOnLine(startLinePoint: Point2D, endLinePoint: Point2D): Point2D | null;
/**
* Method to draw point position using IDrawingInterface (require only DrawText method)
* @param ctx can be any IDrawingInterface or your own class containing drawing method
* @param options options to control drawing:
* x, y - position coordinates to display (can be different then coordinates)
* precision - 2 for value 2.3333 display 2.33
* color - of text
* angle - of text
*/
drawPointPos(ctx: IDrawText, options: {
x?: number;
y?: number;
precision?: number;
color?: string;
angle?: number;
fontSize?: number;
}): void;
/**
* Make brand brand new copy of object
* @returns new instance
*/
copy(): Point2D;
/**
* Simplify to interface
*
* @returns IPoint2D interface
*/
toInterface(): IPoint2D;
/**
* Convert to string
* @param separator separator to use for coordinates
* @returns string in format: ' 10, 23.5'
*/
toString(separator?: string): string;
toCssTranslate(unit?: '' | 'px' | 'rem'): string;
}
export interface IPoint2DData<T = any> extends IPoint2D {
extData: T;
}
export declare class Point2DData<T = any> extends Point2D {
extData?: T;
constructor(x?: number, y?: number, extData?: T);
}