Skip to content

Commit 52aee12

Browse files
committed
fix: joining uniform polygon border segments
1 parent 9ff3d40 commit 52aee12

3 files changed

Lines changed: 25 additions & 71 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.11.0
1+
2.12.0

src/Draw.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,25 @@ public function getPolygon(array $points, string $mode = 'S', array $styles = []
351351
return $out;
352352
}
353353

354+
// When the outline is uniformly styled (no per-segment style overrides),
355+
// stroke it as a single continuous path so that adjacent edges are joined
356+
// at the vertices (miter/round/bevel) instead of being drawn as
357+
// independent, butt-capped segments that would leave the corners open.
358+
$hasSegmentStyles = false;
359+
foreach ($styles as $skey => $sval) {
360+
if (!\is_int($skey) || $sval === []) {
361+
continue;
362+
}
363+
364+
$hasSegmentStyles = true;
365+
break;
366+
}
367+
368+
if (!$hasSegmentStyles) {
369+
$closed = $points[0] === ($points[$nco - 2] ?? null) && $points[1] === ($points[$nco - 1] ?? null);
370+
return $out . $this->getBasicPolygon($points, $closed ? 's' : 'S');
371+
}
372+
354373
$nco -= 3;
355374

356375
// paint the outline

test/DrawTest.php

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,8 @@ public function testGetPolygon(): void
493493
. "\n"
494494
. '5.250000 66.750000 l'
495495
. "\n"
496-
. 'S'
497-
. "\n"
498-
. '5.250000 66.750000 m'
499-
. "\n"
500496
. '9.750000 62.250000 l'
501497
. "\n"
502-
. 'S'
503-
. "\n"
504-
. '9.750000 62.250000 m'
505-
. "\n"
506498
. '14.250000 57.750000 l'
507499
. "\n"
508500
. 'S'
@@ -576,7 +568,10 @@ public function testGetPolygon(): void
576568
);
577569

578570
$res = $draw->getPolygon([0 => 3, 1 => 5, 2 => 7, 3 => 11, 4 => 13, 6 => 19, 7 => 23, 8 => 29]);
579-
$this->assertEquals('2.250000 71.250000 m' . "\n" . '5.250000 66.750000 l' . "\n" . 'S' . "\n", $res);
571+
$this->assertEquals(
572+
'2.250000 71.250000 m' . "\n" . '5.250000 66.750000 l' . "\n" . '14.250000 57.750000 l' . "\n" . 'S' . "\n",
573+
$res,
574+
);
580575
}
581576

582577
/**
@@ -595,22 +590,10 @@ public function testGetRegularPolygon(): void
595590
. "\n"
596591
. '7.460867 70.610186 l'
597592
. "\n"
598-
. 'S'
599-
. "\n"
600-
. '7.460867 70.610186 m'
601-
. "\n"
602593
. '4.468746 76.008116 l'
603594
. "\n"
604-
. 'S'
605-
. "\n"
606-
. '4.468746 76.008116 m'
607-
. "\n"
608595
. '-1.589607 74.830491 l'
609596
. "\n"
610-
. 'S'
611-
. "\n"
612-
. '-1.589607 74.830491 m'
613-
. "\n"
614597
. '-2.341753 68.704749 l'
615598
. "\n"
616599
. 'S'
@@ -744,58 +727,22 @@ public function testGetStarPolygon(): void
744727
. "\n"
745728
. '7.025568 69.069071 l'
746729
. "\n"
747-
. 'S'
748-
. "\n"
749-
. '7.025568 69.069071 m'
750-
. "\n"
751730
. '6.217685 74.688019 l'
752731
. "\n"
753-
. 'S'
754-
. "\n"
755-
. '6.217685 74.688019 m'
756-
. "\n"
757732
. '0.770904 76.287338 l'
758733
. "\n"
759-
. 'S'
760-
. "\n"
761-
. '0.770904 76.287338 m'
762-
. "\n"
763734
. '-2.946563 71.997153 l'
764735
. "\n"
765-
. 'S'
766-
. "\n"
767-
. '-2.946563 71.997153 m'
768-
. "\n"
769736
. '-0.588364 66.833419 l'
770737
. "\n"
771-
. 'S'
772-
. "\n"
773-
. '-0.588364 66.833419 m'
774-
. "\n"
775738
. '5.088364 66.833419 l'
776739
. "\n"
777-
. 'S'
778-
. "\n"
779-
. '5.088364 66.833419 m'
780-
. "\n"
781740
. '7.446563 71.997153 l'
782741
. "\n"
783-
. 'S'
784-
. "\n"
785-
. '7.446563 71.997153 m'
786-
. "\n"
787742
. '3.729096 76.287338 l'
788743
. "\n"
789-
. 'S'
790-
. "\n"
791-
. '3.729096 76.287338 m'
792-
. "\n"
793744
. '-1.717685 74.688019 l'
794745
. "\n"
795-
. 'S'
796-
. "\n"
797-
. '-1.717685 74.688019 m'
798-
. "\n"
799746
. '-2.525568 69.069071 l'
800747
. "\n"
801748
. 'S'
@@ -1012,25 +959,13 @@ public function testGetRect(): void
1012959
. "\n"
1013960
. '7.500000 71.250000 l'
1014961
. "\n"
1015-
. 'S'
1016-
. "\n"
1017-
. '7.500000 71.250000 m'
1018-
. "\n"
1019962
. '7.500000 63.000000 l'
1020963
. "\n"
1021-
. 'S'
1022-
. "\n"
1023-
. '7.500000 63.000000 m'
1024-
. "\n"
1025964
. '2.250000 63.000000 l'
1026965
. "\n"
1027-
. 'S'
1028-
. "\n"
1029-
. '2.250000 63.000000 m'
1030-
. "\n"
1031966
. '2.250000 71.250000 l'
1032967
. "\n"
1033-
. 'S'
968+
. 's'
1034969
. "\n",
1035970
$res,
1036971
);

0 commit comments

Comments
 (0)