Skip to content

Commit

Permalink
Fix optimization of stroke's MoveTo when colinear with Close, see #74
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jun 18, 2021
1 parent 197132c commit 84d3dad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion path_stroke.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func closeInnerBends(p *Path, indices []int, closed bool) {

func optimizeMoveTo(p *Path) {
// move MoveTo to the initial position of the Close if they are colinear
if p.d[cmdLen(MoveToCmd)] == LineToCmd {
if p.d[cmdLen(MoveToCmd)] == LineToCmd && p.d[len(p.d)-cmdLen(CloseCmd)-1] == LineToCmd {
start := Point{p.d[len(p.d)-cmdLen(CloseCmd)-3], p.d[len(p.d)-cmdLen(CloseCmd)-2]}
mid := Point{p.d[1], p.d[2]}
end := Point{p.d[cmdLen(MoveToCmd)+1], p.d[cmdLen(MoveToCmd)+2]}
Expand Down
2 changes: 1 addition & 1 deletion path_stroke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestPathStroke(t *testing.T) {
{"M10 10z", 2.0, RoundCap, RoundJoin, ""},
{"M10 10L10 5", 2.0, RoundCap, RoundJoin, "M9 10L9 5A1 1 0 0 1 11 5L11 10A1 1 0 0 1 9 10z"},
{"M10 10L10 5", 2.0, ButtCap, RoundJoin, "M9 10L9 5L11 5L11 10z"},
{"M10 10L10 5", 2.0, SquareCap, RoundJoin, "M9 10L9 5L9 4L11 4L11 5L11 10L11 11L9 11z"},
{"M10 10L10 5", 2.0, SquareCap, RoundJoin, "M9 11L9 5L9 4L11 4L11 5L11 10L11 11z"},

{"M0 0L10 0L20 0", 2.0, ButtCap, RoundJoin, "M0 -1L10 -1L20 -1L20 1L10 1L0 1z"},
{"M0 0L10 0L10 10", 2.0, ButtCap, RoundJoin, "M0 -1L10 -1A1 1 0 0 1 11 0L11 10L9 10L9 1L0 1z"},
Expand Down

0 comments on commit 84d3dad

Please sign in to comment.