reflect method

Point reflect([
  1. Point? origin
])

Reflects the point through the given origin.

If origin is not given, reflects through the origin (0, 0). If both the point and the origin are 3-dimensional (i.e., z is not null), the reflection is computed in 3D space. Otherwise, it's in 2D.

Example:

var point = Point(1, 2, 3);
var origin = Point(0, 0, 0);
print(point.reflect(origin)); // Output: Point(-1, -2, -3)

Returns a new Point representing the reflection.

Implementation

Point reflect([Point? origin]) {
  origin = origin ?? Point(0, 0);

  var rx = 2 * origin.x - x;
  var ry = 2 * origin.y - y;
  if (z != null && origin.z != null) {
    var rz = 2 * origin.z! - z!;
    return Point(rx, ry, rz);
  } else {
    return Point(rx, ry);
  }
}