toMap method

Map<String, dynamic> toMap()

Implementation

Map<String, dynamic> toMap() {
  Map shape = Map();
  if (this.shape is RectangleShape) {
    RectangleShape s = this.shape as RectangleShape;
    shape['type'] = 'RectangleShape';
    shape['size'] = {'width': s.width, 'height': s.height};
  }

  if (this.shape is CircleShape) {
    CircleShape s = this.shape as CircleShape;
    shape['type'] = 'CircleShape';
    shape['radius'] = s.radius;
  }

  if (this.shape is PolygonShape) {
    PolygonShape s = this.shape as PolygonShape;
    shape['type'] = 'PolygonShape';
    shape['points'] = s.relativePoints.map((e) {
      return {'x': e.x, 'y': e.y};
    }).toList();
  }

  return {
    'shape': shape,
    'align': {'x': this.align?.x ?? 0.0, 'y': this.align?.y ?? 0.0},
  };
}