Skip to content

Class: Shape

多边形抽象,核心是维护一个点坐标列表,点坐标为单位化后的

单位化的含义: 所有x和y始终按比例压缩在一个区间范围内 x:[-0.5, 0.5] y: [-0.5, 0.5]

点坐标之间永远是相对位置,不受尺寸影响

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Shape(unitPoints)

Parameters

NameTypeDescription
unitPointsPointLike[]单位点列表 每个点坐标范围:(x:[-0.5, 0.5] y: [-0.5, 0.5])

Properties

className

className: any


dirty

dirty: boolean


isClosed

isClosed: boolean = true

是否封闭图形(最后一个点是否连接到第一个点形成封闭图形),默认true


points

points: PointLike[]

单位点列表 x:[-0.5, 0.5] y: [-0.5, 0.5]


Arc

Static Arc: any

一个全局的Arc实例对象


Arrow

Static Arrow: any

一个全局的箭头形状实例对象


ArrowShape

Static ArrowShape: any

已过时,不推荐使用,未来将移除

请使用 Shape.Arrow 来替代: Shape.ArrowShape

Deprecated


BezierCurve

Static BezierCurve: any

一个全局的贝塞尔实例对象


Circle

Static Circle: any

一个全局的圆形实例对象


Curve

Static Curve: any

一个全局的曲线实例对象


Damond

Static Damond: Shape

菱形


Ellipse

Static Ellipse: any

一个全局的椭圆实例对象


Line

Static Line: any

一个全局的线条实例对象


Polygon

Static Polygon: any

生成多边形对象

已过时,不推荐使用,未来将移除

请使用 Shape.polygon (p小写) 来替代:Shape.Polygon

Deprecated


Rect

Static Rect: any

一个全局的矩形实例对象


RectShape

Static RectShape: any

已过时,不推荐使用,未来将移除

请使用 Shape.Rect 来替代: Shape.RectShape

Deprecated


Triangle

Static Triangle: Shape

一个全局的三角型, 右朝向


tip

Static tip: Shape

Methods

clone

clone(): Shape

Returns

Shape


draw

draw(ctx, points, object): void

Parameters

NameType
ctxCanvasRenderingContext2D
pointsPointLike[]
objectDisplayObject

Returns

void


rotate

rotate(angle): Shape

旋转,会修改points属性

Parameters

NameType
anglenumber

Returns

Shape


scale

scale(sx, sy): Shape

缩放,会修改points属性

Parameters

NameType
sxnumber
synumber

Returns

Shape


skew

skew(sx, sy): Shape

Parameters

NameType
sxnumber
synumber

Returns

Shape


toJSON

toJSON(): any

Returns

any


updatePoints

updatePoints(unitPoints): void

更新数据点

Parameters

NameTypeDescription
unitPointsPointLike[]单位点列表 x:[-0.5, 0.5] y: [-0.5, 0.5]

Returns

void


Scale

Static Scale(sx, sy): (p: PointLike) => PointLike

Deprecated

Parameters

NameType
sxnumber
synumber

Returns

fn

(p): PointLike

Parameters
NameType
pPointLike
Returns

PointLike


circlePoints

Static circlePoints(opt): any[]

生成圆上一列的点

Parameters

NameType
optObject
opt.beginnumber
opt.endnumber
opt.pointCount?number
opt.stepnumber

Returns

any[]


fn

Static fn(f): Shape

自定义函数来构

Parameters

NameType
fFunction

Returns

Shape


fromJSON

Static fromJSON(json): any

Parameters

NameType
jsonany

Returns

any


fromPoints

Static fromPoints(points, keepAspectRatio?): Shape

Parameters

NameTypeDefault value
pointsPointLike[]undefined
keepAspectRatiobooleantrue

Returns

Shape


innerGrid

Static innerGrid(rows, cols): Shape

生成内网格坐标

Parameters

NameTypeDescription
rowsnumber
colsnumber

Returns

Shape


normalPoints

Static normalPoints(points, keepAspectRatio?): { x: number ; y: number }[]

将指定点坐标单位化

Parameters

NameTypeDefault value
pointsPointLike[]undefined
keepAspectRatiobooleantrue

Returns

{ x: number ; y: number }[]


outerGrid

Static outerGrid(rows, cols): Shape

生成网格坐标(外边框)

Parameters

NameTypeDescription
rowsnumber
colsnumber

Returns

Shape

一维数组(单位坐标)


parallelogram

Static parallelogram(beginX?): Shape

生成一个平行四边形实例(上面一条边向右倾斜)

Parameters

NameTypeDefault valueDescription
beginXnumber0.2X偏移百分比

Returns

Shape


pointToSize

Static pointToSize(points, width, height, keepAspectRatio?): { x: number ; y: number }[]

Parameters

NameTypeDefault value
pointsPointLike[]undefined
widthnumberundefined
heightnumberundefined
keepAspectRatiobooleanfalse

Returns

{ x: number ; y: number }[]


polygon

Static polygon(edgeCount?, initAngle?): Shape

生成多边形Shape对象

Parameters

NameTypeDefault valueDescription
edgeCountnumber3边的条数
initAnglenumber0初始角度

Returns

Shape