private computeLocalTransform()

in packages/core/src/rendering/render-path.ts [145:187]


  private computeLocalTransform(offset: Point) {
    const {
      pathBounds = Rect.zero,
      _angle,
      _size,
      _transformOrigin
    } = this

    // 需要旋转 / 缩放
    const shouldRotate = _angle !== 0
    const shouldResize = !Size.isZero(_size) && (_size.width !== pathBounds.right || _size.height !== pathBounds.bottom)
    if (shouldRotate || shouldResize) {

      const resizeCenter = Point.fromXY(
        offset.x,
        offset.y,
      )

      const rotateCenter = Point.fromXY(
        offset.x + pathBounds.right * _transformOrigin.x,
        offset.y + pathBounds.bottom * _transformOrigin.y,
      )

      const rotateMatrix = _angle !== 0
        ? Matrix.fromRotation(_angle, rotateCenter.x, rotateCenter.y)
        : null

      const scale = Point.fromXY(
        _size.width / pathBounds.right,
        _size.height / pathBounds.bottom,
      )
      const resizeMatrix = (scale.x !== 1 || scale.y !== 1)
        ? Matrix.fromScaleTranslate(scale.x, scale.y, resizeCenter.x, resizeCenter.y)
        : null

      const paintMatrix = rotateMatrix && resizeMatrix
        ? Matrix.mul(resizeMatrix, rotateMatrix)
        : (rotateMatrix ?? resizeMatrix)

      return paintMatrix
    }
    return null
  }