added support for miter limit
This commit is contained in:
parent
5da544d78b
commit
aabe03b003
3 changed files with 41 additions and 12 deletions
|
@ -115,12 +115,12 @@ These features *should* work just like their HTML5 counterparts, but there are l
|
||||||
- clearRect
|
- clearRect
|
||||||
- shadowColor
|
- shadowColor
|
||||||
- shadowOffset(X/Y)
|
- shadowOffset(X/Y)
|
||||||
|
- miterLimit
|
||||||
|
|
||||||
# Missing features
|
# Missing features
|
||||||
|
|
||||||
- globalCompositeOperation
|
- globalCompositeOperation
|
||||||
- lineDashOffset
|
- lineDashOffset
|
||||||
- miterLimit
|
|
||||||
- shadowBlur
|
- shadowBlur
|
||||||
- textBaseline
|
- textBaseline
|
||||||
- getLineDash
|
- getLineDash
|
||||||
|
|
|
@ -37,6 +37,7 @@ type drawState struct {
|
||||||
lineWidth float64
|
lineWidth float64
|
||||||
lineJoin lineJoin
|
lineJoin lineJoin
|
||||||
lineEnd lineEnd
|
lineEnd lineEnd
|
||||||
|
miterLimitSqr float64
|
||||||
globalAlpha float64
|
globalAlpha float64
|
||||||
|
|
||||||
lineDash []float64
|
lineDash []float64
|
||||||
|
@ -105,6 +106,7 @@ func New(x, y, w, h int) *Canvas {
|
||||||
cv.SetBounds(x, y, w, h)
|
cv.SetBounds(x, y, w, h)
|
||||||
cv.state.lineWidth = 1
|
cv.state.lineWidth = 1
|
||||||
cv.state.lineAlpha = 1
|
cv.state.lineAlpha = 1
|
||||||
|
cv.state.miterLimitSqr = 100
|
||||||
cv.state.globalAlpha = 1
|
cv.state.globalAlpha = 1
|
||||||
cv.state.fill.color = glColor{a: 1}
|
cv.state.fill.color = glColor{a: 1}
|
||||||
cv.state.stroke.color = glColor{a: 1}
|
cv.state.stroke.color = glColor{a: 1}
|
||||||
|
@ -583,6 +585,12 @@ func (cv *Canvas) SetLineDash(dash []float64) {
|
||||||
cv.state.lineDashOffset = 0
|
cv.state.lineDashOffset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMiterLimit sets the limit for how far a miter line join can be extend.
|
||||||
|
// The fallback is a bevel join
|
||||||
|
func (cv *Canvas) SetMiterLimit(limit float64) {
|
||||||
|
cv.state.miterLimitSqr = limit * limit
|
||||||
|
}
|
||||||
|
|
||||||
// SetGlobalAlpha sets the global alpha value
|
// SetGlobalAlpha sets the global alpha value
|
||||||
func (cv *Canvas) SetGlobalAlpha(alpha float64) {
|
func (cv *Canvas) SetGlobalAlpha(alpha float64) {
|
||||||
cv.state.globalAlpha = alpha
|
cv.state.globalAlpha = alpha
|
||||||
|
|
21
paths.go
21
paths.go
|
@ -431,6 +431,17 @@ func (cv *Canvas) lineJoint(p pathPoint, p0, p1, p2, l0p0, l0p1, l0p2, l0p3 vec,
|
||||||
ip0 = l0p1.add(l1p1).mulf(0.5)
|
ip0 = l0p1.add(l1p1).mulf(0.5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dist := ip0.sub(l0p1).lenSqr(); dist > cv.state.miterLimitSqr {
|
||||||
|
l1p1 := p1.sub(v3)
|
||||||
|
l1p3 := p1.add(v3)
|
||||||
|
|
||||||
|
tris = append(tris,
|
||||||
|
float32(p1[0]), float32(p1[1]), float32(l0p1[0]), float32(l0p1[1]), float32(l1p1[0]), float32(l1p1[1]),
|
||||||
|
float32(p1[0]), float32(p1[1]), float32(l1p3[0]), float32(l1p3[1]), float32(l0p3[0]), float32(l0p3[1]))
|
||||||
|
return tris
|
||||||
|
}
|
||||||
|
|
||||||
if l0p3.sub(l1p3).lenSqr() < 0.000000001 {
|
if l0p3.sub(l1p3).lenSqr() < 0.000000001 {
|
||||||
ip1 = l0p3.sub(l1p3).mulf(0.5).add(l1p3)
|
ip1 = l0p3.sub(l1p3).mulf(0.5).add(l1p3)
|
||||||
} else {
|
} else {
|
||||||
|
@ -441,6 +452,16 @@ func (cv *Canvas) lineJoint(p pathPoint, p0, p1, p2, l0p0, l0p1, l0p2, l0p3 vec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dist := ip1.sub(l1p1).lenSqr(); dist > cv.state.miterLimitSqr {
|
||||||
|
l1p1 := p1.sub(v3)
|
||||||
|
l1p3 := p1.add(v3)
|
||||||
|
|
||||||
|
tris = append(tris,
|
||||||
|
float32(p1[0]), float32(p1[1]), float32(l0p1[0]), float32(l0p1[1]), float32(l1p1[0]), float32(l1p1[1]),
|
||||||
|
float32(p1[0]), float32(p1[1]), float32(l1p3[0]), float32(l1p3[1]), float32(l0p3[0]), float32(l0p3[1]))
|
||||||
|
return tris
|
||||||
|
}
|
||||||
|
|
||||||
tris = append(tris,
|
tris = append(tris,
|
||||||
float32(p1[0]), float32(p1[1]), float32(l0p1[0]), float32(l0p1[1]), float32(ip0[0]), float32(ip0[1]),
|
float32(p1[0]), float32(p1[1]), float32(l0p1[0]), float32(l0p1[1]), float32(ip0[0]), float32(ip0[1]),
|
||||||
float32(p1[0]), float32(p1[1]), float32(ip0[0]), float32(ip0[1]), float32(l1p1[0]), float32(l1p1[1]),
|
float32(p1[0]), float32(p1[1]), float32(ip0[0]), float32(ip0[1]), float32(l1p1[0]), float32(l1p1[1]),
|
||||||
|
|
Loading…
Reference in a new issue