paths with sub-paths fixed
This commit is contained in:
parent
34ceb96676
commit
7be3a4383c
2 changed files with 34 additions and 17 deletions
31
paths.go
31
paths.go
|
@ -231,9 +231,16 @@ func (cv *Canvas) ClosePath() {
|
||||||
if isSamePoint(cv.linePath[len(cv.linePath)-1].tf, cv.linePath[0].tf, 0.1) {
|
if isSamePoint(cv.linePath[len(cv.linePath)-1].tf, cv.linePath[0].tf, 0.1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cv.LineTo(cv.linePath[0].pos[0], cv.linePath[0].pos[1])
|
closeIdx := 0
|
||||||
cv.linePath[len(cv.linePath)-1].next = cv.linePath[0].tf
|
for i := len(cv.linePath) - 1; i >= 0; i-- {
|
||||||
cv.polyPath[len(cv.polyPath)-1].next = cv.polyPath[0].tf
|
if cv.linePath[i].move {
|
||||||
|
closeIdx = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cv.LineTo(cv.linePath[closeIdx].pos[0], cv.linePath[closeIdx].pos[1])
|
||||||
|
cv.linePath[len(cv.linePath)-1].next = cv.linePath[closeIdx].tf
|
||||||
|
cv.polyPath[len(cv.polyPath)-1].next = cv.polyPath[closeIdx].tf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cv *Canvas) Stroke() {
|
func (cv *Canvas) Stroke() {
|
||||||
|
@ -424,14 +431,24 @@ func lineIntersection(a0, a1, b0, b1 vec) (vec, float64, float64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cv *Canvas) Fill() {
|
func (cv *Canvas) Fill() {
|
||||||
lastMove := 0
|
if len(cv.polyPath) < 3 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cv.activate()
|
||||||
|
start := 0
|
||||||
for i, p := range cv.polyPath {
|
for i, p := range cv.polyPath {
|
||||||
if p.move {
|
if !p.move {
|
||||||
lastMove = i
|
continue
|
||||||
}
|
}
|
||||||
|
if i >= start+3 {
|
||||||
|
cv.fillPoly(start, i)
|
||||||
}
|
}
|
||||||
|
start = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
path := cv.polyPath[lastMove:]
|
func (cv *Canvas) fillPoly(from, to int) {
|
||||||
|
path := cv.polyPath[from:to]
|
||||||
if len(path) < 3 {
|
if len(path) < 3 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,17 +113,17 @@ func (cv *Canvas) cutIntersections(path []pathPoint) []pathPoint {
|
||||||
var cutBuf [50]cut
|
var cutBuf [50]cut
|
||||||
cuts := cutBuf[:0]
|
cuts := cutBuf[:0]
|
||||||
|
|
||||||
for i := 0; i < len(cv.polyPath); i++ {
|
for i := 0; i < len(path); i++ {
|
||||||
ip := (i + len(cv.polyPath) - 1) % len(cv.polyPath)
|
ip := (i + len(path) - 1) % len(path)
|
||||||
a0 := cv.polyPath[ip].pos
|
a0 := path[ip].pos
|
||||||
a1 := cv.polyPath[i].pos
|
a1 := path[i].pos
|
||||||
for j := i + 1; j < len(cv.polyPath); j++ {
|
for j := i + 1; j < len(path); j++ {
|
||||||
jp := (j + len(cv.polyPath) - 1) % len(cv.polyPath)
|
jp := (j + len(path) - 1) % len(path)
|
||||||
if ip == j || jp == i {
|
if ip == j || jp == i {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b0 := cv.polyPath[jp].pos
|
b0 := path[jp].pos
|
||||||
b1 := cv.polyPath[j].pos
|
b1 := path[j].pos
|
||||||
p, r1, r2 := lineIntersection(a0, a1, b0, b1)
|
p, r1, r2 := lineIntersection(a0, a1, b0, b1)
|
||||||
if r1 <= 0 || r1 >= 1 || r2 <= 0 || r2 >= 1 {
|
if r1 <= 0 || r1 >= 1 || r2 <= 0 || r2 >= 1 {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue