getPathAABB method

AABB getPathAABB()

Implementation

AABB getPathAABB() {
  double minX = double.maxFinite;
  double minY = double.maxFinite;
  double maxX = -double.maxFinite;
  double maxY = -double.maxFinite;

  AABB obb = getPathOBB();

  List<Vec2D> pts = [
    Vec2D.fromValues(obb[0], obb[1]),
    Vec2D.fromValues(obb[2], obb[1]),
    Vec2D.fromValues(obb[2], obb[3]),
    Vec2D.fromValues(obb[0], obb[3])
  ];

  Mat2D localTransform;
  if (isPathInWorldSpace) {
    //  convert the path coordinates into local parent space.
    localTransform = Mat2D();
    Mat2D.invert(localTransform, parent!.worldTransform);
  } else if (!_isRootPath) {
    localTransform = Mat2D();
    // Path isn't root, so get transform in shape space.
    if (Mat2D.invert(localTransform, shape!.worldTransform)) {
      Mat2D.multiply(localTransform, localTransform, worldTransform);
    }
  } else {
    localTransform = transform;
  }

  for (final Vec2D p in pts) {
    Vec2D wp = Vec2D.transformMat2D(p, p, localTransform);
    if (wp[0] < minX) {
      minX = wp[0];
    }
    if (wp[1] < minY) {
      minY = wp[1];
    }

    if (wp[0] > maxX) {
      maxX = wp[0];
    }
    if (wp[1] > maxY) {
      maxY = wp[1];
    }
  }
  return AABB.fromValues(minX, minY, maxX, maxY);
}