merge static method

BorderSide merge(
  1. BorderSide a,
  2. BorderSide b
)

Creates a BorderSide that represents the addition of the two given BorderSides.

It is only valid to call this if canMerge returns true for the two sides.

If one of the sides is zero-width with BorderStyle.none, then the other side is return as-is. If both of the sides are zero-width with BorderStyle.none, then BorderSide.none is returned.

Implementation

static BorderSide merge(BorderSide a, BorderSide b) {
  assert(canMerge(a, b));
  final bool aIsNone = a.style == BorderStyle.none && a.width == 0.0;
  final bool bIsNone = b.style == BorderStyle.none && b.width == 0.0;
  if (aIsNone && bIsNone) {
    return BorderSide.none;
  }
  if (aIsNone) {
    return b;
  }
  if (bIsNone) {
    return a;
  }
  assert(a.color == b.color);
  assert(a.style == b.style);
  return BorderSide(
    color: a.color, // == b.color
    width: a.width + b.width,
    strokeAlign: math.max(a.strokeAlign, b.strokeAlign),
    style: a.style, // == b.style
  );
}