parentToLocal method Null safety

Point<num> parentToLocal(
  1. Point<num> parentPoint,
  2. [Point<num>? returnPoint]
)

Converts the point object from this display object's parent coordinates to this display object's local coordinates.

This method allows you to convert any given x- and y-coordinates from values that are relative to the origin (0,0) of this display object's parent coordinates to values that are relative to the origin of this display object's local coordinates.

Implementation

Point<num> parentToLocal(Point<num> parentPoint, [Point<num>? returnPoint]) {
  final p = returnPoint is Point ? returnPoint : Point<num>(0.0, 0.0);
  final x = parentPoint.x.toDouble();
  final y = parentPoint.y.toDouble();
  final m = transformationMatrix;

  p.x = (m.d * (x - m.tx) - m.c * (y - m.ty)) / m.det;
  p.y = (m.a * (y - m.ty) - m.b * (x - m.tx)) / m.det;

  return p;
}