Skip to content

Commit

Permalink
🐛 fix segment rounding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Jan 7, 2025
1 parent 37daa69 commit 1756c1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
34 changes: 17 additions & 17 deletions src/net/sourceforge/plantuml/project/draw/RectangleTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public class RectangleTask {
public RectangleTask(double startPos, double endPos, double round, int completion, Collection<Segment> paused) {
this.round = round;
this.completion = completion;
if (startPos < endPos) {
if (startPos < endPos)
this.segments = new ArrayList<>(new Segment(startPos, endPos).cutSegmentIfNeed(paused));
} else {
else
this.segments = Collections.singletonList(new Segment(startPos, startPos + 1));
}

}

private void draw2hlines(UGraphic ug, double height, ULine hline) {
Expand Down Expand Up @@ -160,12 +160,12 @@ else if (current >= lim)

drawPartly(widthCompletion, ug, segment, height, documentBackground, i);

if (!oddStart && i == 0) {
if (!oddStart && i == 0)
ug.apply(UTranslate.dx(segment.getPos1())).draw(vline);
}
if (!oddEnd && i == segments.size() - 1) {

if (!oddEnd && i == segments.size() - 1)
ug.apply(UTranslate.dx(segment.getPos2())).draw(vline);
}

current = next;
}
drawIntermediateDotted(ug, height);
Expand All @@ -183,36 +183,36 @@ private void drawIntermediateDotted(UGraphic ug, double height) {
for (int i = 0; i < segments.size() - 1; i++) {
final double v1 = segments.get(i).getPos2() + 3;
final double v2 = segments.get(i + 1).getPos1() - 3;
if (v2 > v1) {
if (v2 > v1)
draw2hlines(ug.apply(UTranslate.dx(v1)), height, ULine.hline(v2 - v1));
}

}
}

private void drawPartly(double widthCompletion, UGraphic ug, final Segment segment, double height,
HColor documentBackground, int i) {
double width = segment.getLength();
if (i != segments.size() - 1) {
if (i != segments.size() - 1)
width++;
}
if (width > 0) {

if (width > 0)
drawRect(widthCompletion, ug.apply(HColors.none()).apply(UTranslate.dx(segment.getPos1())),
documentBackground, width, height);
}

double pos1 = segment.getPos1();
double len = segment.getLength();
if (i == 0) {
if (segments.size() > 1) {
if (segments.size() > 1)
len--;
}

} else {
pos1++;
len--;
}
if (len > 0) {

if (len > 0)
draw2hlines(ug.apply(UTranslate.dx(pos1)), height, ULine.hline(len));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public Collection<Segment> cutSegmentIfNeed(Collection<Segment> allDelays) {
final List<Segment> result2 = new ArrayList<>();
double pendingStart = pos1;
for (Segment pause : sortedDelay) {
if (pause.pos1 == pendingStart) {
if (Math.abs(pause.pos1 - pendingStart) < 0.001) {
pendingStart = pause.pos2;
continue;
}
if (pause.pos1 < pendingStart) {
if (pause.pos1 < pendingStart)
continue;
}

if (pause.pos1 > this.pos2) {
if (pendingStart < this.pos2)
result2.add(new Segment(pendingStart, this.pos2));
Expand All @@ -120,6 +120,7 @@ public Collection<Segment> cutSegmentIfNeed(Collection<Segment> allDelays) {
}
if (pendingStart < this.pos2)
result2.add(new Segment(pendingStart, this.pos2));

return Collections.unmodifiableCollection(result2);
}

Expand Down

0 comments on commit 1756c1f

Please sign in to comment.