toSegments method
Converts this shape to path segments.
Implementation
@override
List<Segment> toSegments() {
if (borderRadius == null) {
return [
MoveSegment(end: rect.topLeft),
LineSegment(end: rect.topRight, tag: SegmentTags.top),
LineSegment(end: rect.bottomRight, tag: SegmentTags.right),
LineSegment(end: rect.bottomLeft, tag: SegmentTags.bottom),
LineSegment(end: rect.topLeft, tag: SegmentTags.left),
CloseSegment(),
];
} else {
final tlr = borderRadius!.topLeft;
final trr = borderRadius!.topRight;
final brr = borderRadius!.bottomRight;
final blr = borderRadius!.bottomLeft;
final signX = rect.width > 0 ? 1 : -1;
final signY = rect.height > 0 ? 1 : -1;
final clockwise = signX + signY != 0;
return [
MoveSegment(end: rect.topLeft.translate(0, signY * tlr.y)),
ArcToPointSegment(
end: rect.topLeft.translate(signX * tlr.x, 0),
radius: tlr,
rotation: 0,
largeArc: false,
clockwise: clockwise,
tag: SegmentTags.topLeft),
LineSegment(
end: rect.topRight.translate(-signX * trr.x, 0),
tag: SegmentTags.top),
ArcToPointSegment(
end: rect.topRight.translate(0, signY * trr.y),
radius: trr,
rotation: 0,
largeArc: false,
clockwise: clockwise,
tag: SegmentTags.topRight),
LineSegment(
end: rect.bottomRight.translate(0, -signY * brr.y),
tag: SegmentTags.right),
ArcToPointSegment(
end: rect.bottomRight.translate(-signX * brr.x, 0),
radius: brr,
rotation: 0,
largeArc: false,
clockwise: clockwise,
tag: SegmentTags.bottomRight),
LineSegment(
end: rect.bottomLeft.translate(signX * blr.x, 0),
tag: SegmentTags.bottom),
ArcToPointSegment(
end: rect.bottomLeft.translate(0, -signY * blr.y),
radius: blr,
rotation: 0,
largeArc: false,
clockwise: clockwise,
tag: SegmentTags.bottomLeft),
LineSegment(
end: rect.topLeft.translate(0, signY * tlr.y),
tag: SegmentTags.left),
CloseSegment(),
];
}
}