mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
vector: add StrokeOptions.MiterLimit
This commit is contained in:
parent
04680ff761
commit
225bf1bbb4
@ -95,14 +95,22 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
ow, oh := target.Size()
|
||||
size := min(ow/4, oh/4)
|
||||
offsetX, offsetY := (ow-size*3)/2, (oh-size*3)/2
|
||||
size := min(ow/5, oh/4)
|
||||
offsetX, offsetY := (ow-size*4)/2, (oh-size*3)/2
|
||||
|
||||
// Render the lines on the target.
|
||||
for j := 0; j < 3; j++ {
|
||||
for i, join := range []vector.LineJoin{vector.LineJoinMiter, vector.LineJoinBevel, vector.LineJoinRound} {
|
||||
for i, join := range []vector.LineJoin{
|
||||
vector.LineJoinMiter,
|
||||
vector.LineJoinMiter,
|
||||
vector.LineJoinBevel,
|
||||
vector.LineJoinRound} {
|
||||
r := image.Rect(i*size+offsetX, j*size+offsetY, (i+1)*size+offsetX, (j+1)*size+offsetY)
|
||||
g.drawLine(target, r, join)
|
||||
miterLimit := float32(5)
|
||||
if i == 1 {
|
||||
miterLimit = 10
|
||||
}
|
||||
g.drawLine(target, r, join, miterLimit)
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +127,7 @@ Press C to switch to draw the center lines.`
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
}
|
||||
|
||||
func (g *Game) drawLine(screen *ebiten.Image, region image.Rectangle, join vector.LineJoin) {
|
||||
func (g *Game) drawLine(screen *ebiten.Image, region image.Rectangle, join vector.LineJoin, miterLimit float32) {
|
||||
c0x := float64(region.Min.X + region.Dx()/4)
|
||||
c0y := float64(region.Min.Y + region.Dy()/4)
|
||||
c1x := float64(region.Max.X - region.Dx()/4)
|
||||
@ -137,6 +145,7 @@ func (g *Game) drawLine(screen *ebiten.Image, region image.Rectangle, join vecto
|
||||
// Draw the main line in white.
|
||||
op := &vector.StrokeOptions{}
|
||||
op.LineJoin = join
|
||||
op.MiterLimit = miterLimit
|
||||
op.Width = float32(r / 2)
|
||||
vs, is := path.AppendVerticesAndIndicesForStroke(g.vertices[:0], g.indices[:0], op)
|
||||
for i := range vs {
|
||||
|
@ -365,6 +365,12 @@ type StrokeOptions struct {
|
||||
// LineJoin is the way in which how two segments are joined.
|
||||
// The default (zero) value is LineJoiMiter.
|
||||
LineJoin LineJoin
|
||||
|
||||
// MiterLimit is the miter limit for LineJoinMiter.
|
||||
// For details, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-miterlimit.
|
||||
//
|
||||
// The default (zero) value is 0.
|
||||
MiterLimit float32
|
||||
}
|
||||
|
||||
// AppendVerticesAndIndicesForStroke appends vertices and indices to render a stroke of this path and returns them.
|
||||
@ -460,10 +466,9 @@ func (p *Path) AppendVerticesAndIndicesForStroke(vertices []ebiten.Vertex, indic
|
||||
|
||||
switch op.LineJoin {
|
||||
case LineJoinMiter:
|
||||
// TODO: Enable to configure this.
|
||||
const miterLimit = 10
|
||||
delta := math.Pi - da
|
||||
exceed := math.Abs(1/math.Sin(float64(delta/2))) > miterLimit
|
||||
exceed := float32(math.Abs(1/math.Sin(float64(delta/2)))) > op.MiterLimit
|
||||
|
||||
var quad Path
|
||||
quad.MoveTo(c.x, c.y)
|
||||
if da < math.Pi {
|
||||
|
Loading…
Reference in New Issue
Block a user