mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
internal/stroke: handle zero-length points
Fixes the edge case where a zero point would be normalized to NaN. Signed-off-by: Walter Werner SCHNEIDER <contact@schnwalter.eu>
This commit is contained in:
committed by
Elias Naur
parent
36a2fa37c7
commit
176570527d
@@ -327,6 +327,9 @@ func strokePathNorm(p0, p1, p2 f32.Point, t, d float32) f32.Point {
|
|||||||
func rot90CW(p f32.Point) f32.Point { return f32.Pt(+p.Y, -p.X) }
|
func rot90CW(p f32.Point) f32.Point { return f32.Pt(+p.Y, -p.X) }
|
||||||
|
|
||||||
func normPt(p f32.Point, l float32) f32.Point {
|
func normPt(p f32.Point, l float32) f32.Point {
|
||||||
|
if p.X == 0 && p.Y == 0 {
|
||||||
|
return f32.Point{}
|
||||||
|
}
|
||||||
isVerticalUnit := p.X == 0 && (p.Y == l || p.Y == -l)
|
isVerticalUnit := p.X == 0 && (p.Y == l || p.Y == -l)
|
||||||
isHorizontalUnit := p.Y == 0 && (p.X == l || p.X == -l)
|
isHorizontalUnit := p.Y == 0 && (p.X == l || p.X == -l)
|
||||||
if isVerticalUnit || isHorizontalUnit {
|
if isVerticalUnit || isHorizontalUnit {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ func TestNormPt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
|
// l!=0 && X=Y=0
|
||||||
|
{l: 10, ptIn: f32.Point{X: 0, Y: 0}, ptOut: f32.Point{X: 0, Y: 0}},
|
||||||
|
{l: -10, ptIn: f32.Point{X: 0, Y: 0}, ptOut: f32.Point{X: 0, Y: 0}},
|
||||||
|
|
||||||
// l>0 & X
|
// l>0 & X
|
||||||
{l: +20, ptIn: f32.Point{X: +30, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
{l: +20, ptIn: f32.Point{X: +30, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
{l: +20, ptIn: f32.Point{X: +20, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
{l: +20, ptIn: f32.Point{X: +20, Y: 0}, ptOut: f32.Point{X: +20, Y: 0}},
|
||||||
|
|||||||
Reference in New Issue
Block a user