public void AddRectangle(double left, double top, double right, double bottom)
{
if (!top.IsClose(lastBottom)) {
CloseFigure();
}
if (figure == null) {
figure = new PathFigure();
figure.StartPoint = new Point(left, top + cornerRadius);
if (Math.Abs(left - right) > cornerRadius) {
figure.Segments.Add(MakeArc(left + cornerRadius, top, SweepDirection.Clockwise));
figure.Segments.Add(MakeLineSegment(right - cornerRadius, top));
figure.Segments.Add(MakeArc(right, top + cornerRadius, SweepDirection.Clockwise));
}
figure.Segments.Add(MakeLineSegment(right, bottom - cornerRadius));
insertionIndex = figure.Segments.Count;
//figure.Segments.Add(MakeArc(left, bottom - cornerRadius, SweepDirection.Clockwise));
} else {
if (!lastRight.IsClose(right)) {
double cr = right < lastRight ? -cornerRadius : cornerRadius;
SweepDirection dir1 = right < lastRight ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
SweepDirection dir2 = right < lastRight ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
figure.Segments.Insert(insertionIndex++, MakeArc(lastRight + cr, lastBottom, dir1));
figure.Segments.Insert(insertionIndex++, MakeLineSegment(right - cr, top));
figure.Segments.Insert(insertionIndex++, MakeArc(right, top + cornerRadius, dir2));
}
figure.Segments.Insert(insertionIndex++, MakeLineSegment(right, bottom - cornerRadius));
figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft, lastTop + cornerRadius));
if (!lastLeft.IsClose(left)) {
double cr = left < lastLeft ? cornerRadius : -cornerRadius;
SweepDirection dir1 = left < lastLeft ? SweepDirection.Counterclockwise : SweepDirection.Clockwise;
SweepDirection dir2 = left < lastLeft ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
figure.Segments.Insert(insertionIndex, MakeArc(lastLeft, lastBottom - cornerRadius, dir1));
figure.Segments.Insert(insertionIndex, MakeLineSegment(lastLeft - cr, lastBottom));
figure.Segments.Insert(insertionIndex, MakeArc(left + cr, lastBottom, dir2));
}
}
this.lastTop = top;
this.lastBottom = bottom;
this.lastLeft = left;
this.lastRight = right;
}