getBounds method

void getBounds(
  1. Vector2 offset,
  2. Vector2 size,
  3. List<double> temp
)

Implementation

void getBounds(Vector2 offset, Vector2 size, List<double> temp) {
  final List<Slot> drawOrder = this.drawOrder;
  double minX = double.infinity,
      minY = double.infinity,
      maxX = double.negativeInfinity,
      maxY = double.negativeInfinity;

  final int n = drawOrder.length;
  for (int i = 0; i < n; i++) {
    final Slot slot = drawOrder[i];
    int verticesLength = 0;
    Float32List? vertices;
    final Attachment? attachment = slot.getAttachment();
    if (attachment is RegionAttachment) {
      final RegionAttachment region = attachment;
      verticesLength = 8;
      vertices = Float32List.fromList(ArrayUtils.copyWithNewArraySize(
          temp, verticesLength, double.infinity));
      region.computeWorldVertices2(slot.bone, vertices, 0, 2);
    } else if (attachment is MeshAttachment) {
      final MeshAttachment mesh = attachment;
      verticesLength = mesh.worldVerticesLength;
      vertices = Float32List.fromList(ArrayUtils.copyWithNewArraySize(
          temp, verticesLength, double.infinity));
      mesh.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
    }
    if (vertices != null) {
      final int nn = vertices.length;
      for (int ii = 0; ii < nn; ii += 2) {
        final double x = vertices[ii], y = vertices[ii + 1];
        minX = math.min(minX, x);
        minY = math.min(minY, y);
        maxX = math.max(maxX, x);
        maxY = math.max(maxY, y);
      }
    }
  }
  offset.set(minX, minY);
  size.set(maxX - minX, maxY - minY);
}