mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 04:42:02 +08:00
commit
ca9be838a8
12
src/Shape.ts
12
src/Shape.ts
@ -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);
|
||||
|
@ -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),
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { Factory } from '../Factory';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
import { _registerNode } from '../Global';
|
||||
import { Shape, ShapeConfig } from '../Shape';
|
||||
|
||||
import { GetSet, PathSegment } from '../types';
|
||||
import {
|
||||
getCubicArcLength,
|
||||
getQuadraticArcLength,
|
||||
t2length,
|
||||
} from '../BezierFunctions';
|
||||
import { GetSet, PathSegment } from '../types';
|
||||
|
||||
export interface PathConfig extends ShapeConfig {
|
||||
data?: string;
|
||||
@ -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,
|
||||
@ -854,15 +858,15 @@ export class Path extends Shape<PathConfig> {
|
||||
return 0;
|
||||
}
|
||||
static convertEndpointToCenterParameterization(
|
||||
x1,
|
||||
y1,
|
||||
x2,
|
||||
y2,
|
||||
fa,
|
||||
fs,
|
||||
rx,
|
||||
ry,
|
||||
psiDeg
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number,
|
||||
fa: number,
|
||||
fs: number,
|
||||
rx: number,
|
||||
ry: number,
|
||||
psiDeg: number
|
||||
) {
|
||||
// Derived from: http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
|
||||
const psi = psiDeg * (Math.PI / 180.0);
|
||||
|
Loading…
Reference in New Issue
Block a user