Skip to content

Commit

Permalink
Fix bug for clockwise arc, fixes #324
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Nov 24, 2024
1 parent d02039c commit d014681
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
4 changes: 2 additions & 2 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2215,8 +2215,8 @@ func (p *Path) ToPDF() string {
// ToRasterizer rasterizes the path using the given rasterizer and resolution.
func (p *Path) ToRasterizer(ras *vector.Rasterizer, resolution Resolution) {
dpmm := resolution.DPMM()
// TODO: smoothen path using Ramer-... inside flatten
p = p.Flatten(PixelTolerance / dpmm) // tolerance of 1/10 of a pixel
// TODO: smoothen path using Ramer-...

dy := float64(ras.Bounds().Size().Y)
for i := 0; i < len(p.d); {
Expand All @@ -2233,7 +2233,7 @@ func (p *Path) ToRasterizer(ras *vector.Rasterizer, resolution Resolution) {
}
i += cmdLen(cmd)
}
if 0 < len(p.d) && p.d[len(p.d)-1] != CloseCmd {
if !p.Closed() {
// implicitly close path
ras.ClosePath()
}
Expand Down
19 changes: 5 additions & 14 deletions path_stroke.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ func (p *Path) Offset(w float64, fillRule FillRule, tolerance float64) *Path {
filling := p.Filling(fillRule)
for i, pi := range p.Split() {
r := &Path{}
ccw, closed := pi.CCW(), pi.Closed()
ccw := pi.CCW()
closed := pi.Closed()
rhs, lhs := pi.offset(w, ButtCap, RoundJoin, false, tolerance)
if !closed || (ccw != filling[i]) != positive {
r = rhs
Expand All @@ -634,11 +635,7 @@ func (p *Path) Offset(w float64, fillRule FillRule, tolerance float64) *Path {
}

if closed {
if ccw {
r = r.Settle(Positive)
} else {
r = r.Settle(Negative)
}
r = r.Settle(Positive)
if !filling[i] {
r = r.Reverse()
}
Expand All @@ -662,14 +659,8 @@ func (p *Path) Stroke(w float64, cr Capper, jr Joiner, tolerance float64) *Path
rhs, lhs := pi.offset(halfWidth, cr, jr, true, tolerance)
if lhs != nil { // closed path
// inner path should go opposite direction to cancel the outer path
if pi.CCW() {
q = q.Append(rhs.Settle(Positive))
q = q.Append(lhs.Settle(Positive).Reverse())
} else {
// outer first, then inner
q = q.Append(lhs.Settle(Negative))
q = q.Append(rhs.Settle(Negative).Reverse())
}
q = q.Append(rhs.Settle(Positive))
q = q.Append(lhs.Settle(Positive).Reverse())
} else {
q = q.Append(rhs.Settle(Positive))
}
Expand Down

0 comments on commit d014681

Please sign in to comment.