Skip to content

Commit ca9be83

Browse files
authored
Merge pull request #1915 from tbo47/master
add types
2 parents 3587358 + 09f2838 commit ca9be83

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

src/Shape.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,16 @@ export class Shape<
213213
shapes[key] = this;
214214
}
215215

216+
/**
217+
* @deprecated
218+
*/
216219
getContext() {
217220
Util.warn('shape.getContext() method is deprecated. Please do not use it.');
218221
return this.getLayer()!.getContext();
219222
}
223+
/**
224+
* @deprecated
225+
*/
220226
getCanvas() {
221227
Util.warn('shape.getCanvas() method is deprecated. Please do not use it.');
222228
return this.getLayer()!.getCanvas();
@@ -442,7 +448,7 @@ export class Shape<
442448
* @param {Number} point.y
443449
* @returns {Boolean}
444450
*/
445-
intersects(point) {
451+
intersects(point: Vector2d) {
446452
const stage = this.getStage();
447453
if (!stage) {
448454
return false;
@@ -599,7 +605,7 @@ export class Shape<
599605
cachedCanvas = this._getCanvasCache(),
600606
drawFunc = this.getSceneFunc(),
601607
hasShadow = this.hasShadow();
602-
let stage, bufferContext;
608+
let stage;
603609

604610
const skipBuffer = false;
605611
const cachingSelf = top === this;
@@ -627,7 +633,7 @@ export class Shape<
627633
if (this._useBufferCanvas() && !skipBuffer) {
628634
stage = this.getStage();
629635
const bc = bufferCanvas || stage.bufferCanvas;
630-
bufferContext = bc.getContext();
636+
const bufferContext = bc.getContext();
631637
bufferContext.clear();
632638
bufferContext.save();
633639
bufferContext._applyLineJoin(this);

src/shapes/Line.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import { getNumberArrayValidator, getNumberValidator } from '../Validators';
66
import { Context } from '../Context';
77
import { GetSet } from '../types';
88

9-
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
9+
function getControlPoints(
10+
x0: number,
11+
y0: number,
12+
x1: number,
13+
y1: number,
14+
x2: number,
15+
y2: number,
16+
t: number
17+
) {
1018
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)),
1119
d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)),
1220
fa = (t * d01) / (d01 + d12),

src/shapes/Path.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Factory } from '../Factory';
2-
import { Shape, ShapeConfig } from '../Shape';
32
import { _registerNode } from '../Global';
3+
import { Shape, ShapeConfig } from '../Shape';
44

5-
import { GetSet, PathSegment } from '../types';
65
import {
76
getCubicArcLength,
87
getQuadraticArcLength,
98
t2length,
109
} from '../BezierFunctions';
10+
import { GetSet, PathSegment } from '../types';
1111

1212
export interface PathConfig extends ShapeConfig {
1313
data?: string;
@@ -217,7 +217,7 @@ export class Path extends Shape<PathConfig> {
217217
* @example
218218
* var point = path.getPointAtLength(10);
219219
*/
220-
getPointAtLength(length) {
220+
getPointAtLength(length: number) {
221221
return Path.getPointAtLengthOfDataArray(length, this.dataArray);
222222
}
223223

@@ -370,26 +370,33 @@ export class Path extends Shape<PathConfig> {
370370
return { x: ix + adjustedRun, y: iy + adjustedRise };
371371
}
372372

373-
static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) {
374-
function CB1(t) {
373+
static getPointOnCubicBezier(
374+
pct: number,
375+
P1x: number,
376+
P1y: number,
377+
P2x: number,
378+
P2y: number,
379+
P3x: number,
380+
P3y: number,
381+
P4x: number,
382+
P4y: number
383+
) {
384+
function CB1(t: number) {
375385
return t * t * t;
376386
}
377-
function CB2(t) {
387+
function CB2(t: number) {
378388
return 3 * t * t * (1 - t);
379389
}
380-
function CB3(t) {
390+
function CB3(t: number) {
381391
return 3 * t * (1 - t) * (1 - t);
382392
}
383-
function CB4(t) {
393+
function CB4(t: number) {
384394
return (1 - t) * (1 - t) * (1 - t);
385395
}
386396
const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
387397
const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
388398

389-
return {
390-
x: x,
391-
y: y,
392-
};
399+
return { x, y };
393400
}
394401
static getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) {
395402
function QB1(t) {
@@ -404,10 +411,7 @@ export class Path extends Shape<PathConfig> {
404411
const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
405412
const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
406413

407-
return {
408-
x: x,
409-
y: y,
410-
};
414+
return { x, y };
411415
}
412416
static getPointOnEllipticalArc(
413417
cx: number,
@@ -854,15 +858,15 @@ export class Path extends Shape<PathConfig> {
854858
return 0;
855859
}
856860
static convertEndpointToCenterParameterization(
857-
x1,
858-
y1,
859-
x2,
860-
y2,
861-
fa,
862-
fs,
863-
rx,
864-
ry,
865-
psiDeg
861+
x1: number,
862+
y1: number,
863+
x2: number,
864+
y2: number,
865+
fa: number,
866+
fs: number,
867+
rx: number,
868+
ry: number,
869+
psiDeg: number
866870
) {
867871
// Derived from: http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
868872
const psi = psiDeg * (Math.PI / 180.0);

0 commit comments

Comments
 (0)