bound method

Range2D bound({
  1. required Range2D to,
})

Bound a Selection to a Range2D.

Unbounded corners will receive the corresponding side from the Range2D.

If the given selection is located completely outside the given range, it will return a Range in which Range2D.isNil will be true.

Implementation

Range2D bound({
  required Range2D to,
}) {
  final xRange = to.xRange;
  final yRange = to.yRange;

  final left = this.left?.clamp(xRange.start, xRange.end) ?? xRange.start;
  final top = this.top?.clamp(yRange.start, yRange.end) ?? yRange.start;

  final right = this.right?.clamp(xRange.start, xRange.end) ?? xRange.end;
  final bottom = this.bottom?.clamp(yRange.start, yRange.end) ?? yRange.end;

  return Range2D.fromPoints(IntVector2(left, top), IntVector2(right, bottom));
}