RoundedRectangle.fromLTRBR constructor

RoundedRectangle.fromLTRBR(
  1. double _left,
  2. double _top,
  3. double _right,
  4. double _bottom,
  5. double _radius,
)

Constructs a RoundedRectangle with left, top, right and bottom edges, and the given radius.

If the edges are given in the wrong order (e.g. left is to the right from right), then they will be swapped.

The radius cannot be negative. At the same time, if the radius is too big, it will be reduced so that the rounded edge can fit inside the rectangle. In other words, the radius will be adjusted to not exceed the half-width or half-height of the rectangle.

Implementation

RoundedRectangle.fromLTRBR(
  this._left,
  this._top,
  this._right,
  this._bottom,
  this._radius,
) : assert(_radius >= 0, 'Radius cannot be negative: $_radius') {
  if (_left > _right) {
    final tmp = _left;
    _left = _right;
    _right = tmp;
  }
  if (_top > _bottom) {
    final tmp = _top;
    _top = _bottom;
    _bottom = tmp;
  }
  if (_radius > (_right - _left) / 2) {
    _radius = (_right - _left) / 2;
  }
  if (_radius > (_bottom - _top) / 2) {
    _radius = (_bottom - _top) / 2;
  }
}