ShapeFactory

图形工厂类

new SDK.ShapeFactory()

提供创建和管理图形的静态方法

Methods

static SDK.ShapeFactory.calculateTotalArea(shapes)number

计算多个图形的总面积
Name Type Description
shapes Array.<Shape> 图形数组
Returns:
所有图形的总面积

static SDK.ShapeFactory.createShape(type, options)Shape

根据类型创建图形
Name Type Description
type ShapeType 图形类型
options Object 图形配置选项
Name Type Description
name string 图形名称
x number X坐标
y number Y坐标
radius number optional 半径(圆形)
width number optional 宽度(矩形)
height number optional 高度(矩形)
Returns:
创建的图形对象
Throws:
  • Error : 当图形类型不支持或参数不正确时抛出错误
Example:
// 创建一个圆形
const circle = ShapeFactory.createShape(ShapeType.CIRCLE, {
  name: 'myCircle',
  x: 0,
  y: 0,
  radius: 5
});

// 创建一个矩形
const rect = ShapeFactory.createShape(ShapeType.RECTANGLE, {
  name: 'myRect',
  x: 0,
  y: 0,
  width: 4,
  height: 5
});

static SDK.ShapeFactory.createShapes(configs)Array.<Shape>

批量创建图形
Name Type Description
configs Array.<Object> 图形配置数组
Returns:
创建的图形数组
Example:
const shapes = ShapeFactory.createShapes([
  {
    type: ShapeType.CIRCLE,
    options: { name: 'c1', x: 0, y: 0, radius: 5 }
  },
  {
    type: ShapeType.RECTANGLE,
    options: { name: 'r1', x: 10, y: 10, width: 4, height: 5 }
  }
]);

static SDK.ShapeFactory.findShapeByName(shapes, name)Shape|undefined

根据名称查找图形
Name Type Description
shapes Array.<Shape> 图形数组
name string 要查找的图形名称
Returns:
找到的图形,如果未找到返回undefined
Need help? Use AI.