intersect method
Return the A1Range or null where this and other intersect
updates the tag as this.tag, other.tag
Implementation
A1Range? intersect(A1Range other) {
if (!overlaps(other)) {
return null;
}
List? tagStack = [];
_flattenAndAdd(tagStack, tag);
_flattenAndAdd(tagStack, other.tag);
final intersectTag = tagStack.isEmpty
? null
: tagStack.length == 1
? tagStack.single
: tagStack;
if (this == all && other == all) {
return all.copyWith(tag: intersectTag);
} else if (this == all) {
return other.copyWith(tag: intersectTag);
} else if (other == all) {
return copyWith(tag: intersectTag);
}
final (int left, int top, int right, int bottom) =
_rectify(from, to, min: -1);
final (int otherLeft, int otherTop, int otherRight, int otherBottom) =
_rectify(other.from, other.to, min: -1);
return A1Range.fromPartials(
A1Partial.fromVector(
_maxPartial(left, otherLeft), _maxPartial(top, otherTop)),
A1Partial.fromVector(
_minPartial(right, otherRight), _minPartial(bottom, otherBottom)),
tag: intersectTag,
);
}