add types

This commit is contained in:
tbo47 2025-04-08 14:46:18 +00:00
parent 88e3d2a088
commit a4980fccdc
3 changed files with 36 additions and 18 deletions

View File

@ -213,10 +213,16 @@ export class Shape<
shapes[key] = this;
}
/**
* @deprecated
*/
getContext() {
Util.warn('shape.getContext() method is deprecated. Please do not use it.');
return this.getLayer()!.getContext();
}
/**
* @deprecated
*/
getCanvas() {
Util.warn('shape.getCanvas() method is deprecated. Please do not use it.');
return this.getLayer()!.getCanvas();
@ -442,7 +448,7 @@ export class Shape<
* @param {Number} point.y
* @returns {Boolean}
*/
intersects(point) {
intersects(point: Vector2d) {
const stage = this.getStage();
if (!stage) {
return false;
@ -599,7 +605,7 @@ export class Shape<
cachedCanvas = this._getCanvasCache(),
drawFunc = this.getSceneFunc(),
hasShadow = this.hasShadow();
let stage, bufferContext;
let stage;
const skipBuffer = false;
const cachingSelf = top === this;
@ -627,7 +633,7 @@ export class Shape<
if (this._useBufferCanvas() && !skipBuffer) {
stage = this.getStage();
const bc = bufferCanvas || stage.bufferCanvas;
bufferContext = bc.getContext();
const bufferContext = bc.getContext();
bufferContext.clear();
bufferContext.save();
bufferContext._applyLineJoin(this);

View File

@ -6,7 +6,15 @@ import { getNumberArrayValidator, getNumberValidator } from '../Validators';
import { Context } from '../Context';
import { GetSet } from '../types';
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
function getControlPoints(
x0: number,
y0: number,
x1: number,
y1: number,
x2: number,
y2: number,
t: number
) {
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)),
d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)),
fa = (t * d01) / (d01 + d12),

View File

@ -217,7 +217,7 @@ export class Path extends Shape<PathConfig> {
* @example
* var point = path.getPointAtLength(10);
*/
getPointAtLength(length) {
getPointAtLength(length: number) {
return Path.getPointAtLengthOfDataArray(length, this.dataArray);
}
@ -370,26 +370,33 @@ export class Path extends Shape<PathConfig> {
return { x: ix + adjustedRun, y: iy + adjustedRise };
}
static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) {
function CB1(t) {
static getPointOnCubicBezier(
pct: number,
P1x: number,
P1y: number,
P2x: number,
P2y: number,
P3x: number,
P3y: number,
P4x: number,
P4y: number
) {
function CB1(t: number) {
return t * t * t;
}
function CB2(t) {
function CB2(t: number) {
return 3 * t * t * (1 - t);
}
function CB3(t) {
function CB3(t: number) {
return 3 * t * (1 - t) * (1 - t);
}
function CB4(t) {
function CB4(t: number) {
return (1 - t) * (1 - t) * (1 - t);
}
const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
return {
x: x,
y: y,
};
return { x, y };
}
static getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) {
function QB1(t) {
@ -404,10 +411,7 @@ export class Path extends Shape<PathConfig> {
const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
return {
x: x,
y: y,
};
return { x, y };
}
static getPointOnEllipticalArc(
cx: number,