(t *testing.T)
| 127 | } |
| 128 | |
| 129 | func TestRadialGradientAt(t *testing.T) { |
| 130 | red := color.RGBA{255, 0, 0, 255} |
| 131 | blue := color.RGBA{0, 0, 255, 255} |
| 132 | |
| 133 | // Helper to build a radial gradient with red at t=0 and blue at t=1. |
| 134 | makeGrad := func(c0 Point, r0 float64, c1 Point, r1 float64) *RadialGradient { |
| 135 | g := NewRadialGradient(c0, r0, c1, r1) |
| 136 | g.Add(0.0, red) |
| 137 | g.Add(1.0, blue) |
| 138 | return g |
| 139 | } |
| 140 | |
| 141 | // colorApproxEqual allows small rounding differences from interpolation. |
| 142 | colorApproxEqual := func(a, b color.RGBA) bool { |
| 143 | diff := func(x, y uint8) int { |
| 144 | d := int(x) - int(y) |
| 145 | if d < 0 { |
| 146 | return -d |
| 147 | } |
| 148 | return d |
| 149 | } |
| 150 | return diff(a.R, b.R) <= 1 && diff(a.G, b.G) <= 1 && diff(a.B, b.B) <= 1 && diff(a.A, b.A) <= 1 |
| 151 | } |
| 152 | |
| 153 | tests := []struct { |
| 154 | name string |
| 155 | grad *RadialGradient |
| 156 | x, y float64 |
| 157 | want color.RGBA |
| 158 | }{ |
| 159 | { |
| 160 | name: "empty gradient returns transparent", |
| 161 | grad: NewRadialGradient(Point{0, 0}, 0, Point{0, 0}, 10), |
| 162 | x: 5, |
| 163 | y: 0, |
| 164 | want: Transparent, |
| 165 | }, |
| 166 | { |
| 167 | name: "concentric at center returns first stop", |
| 168 | grad: makeGrad(Point{0, 0}, 0, Point{0, 0}, 10), |
| 169 | x: 0, |
| 170 | y: 0, |
| 171 | want: red, |
| 172 | }, |
| 173 | { |
| 174 | name: "concentric at outer edge returns last stop", |
| 175 | grad: makeGrad(Point{0, 0}, 0, Point{0, 0}, 10), |
| 176 | x: 10, |
| 177 | y: 0, |
| 178 | want: blue, |
| 179 | }, |
| 180 | { |
| 181 | name: "concentric beyond outer edge clamps to last stop", |
| 182 | grad: makeGrad(Point{0, 0}, 0, Point{0, 0}, 10), |
| 183 | x: 20, |
| 184 | y: 0, |
| 185 | want: blue, |
| 186 | }, |
nothing calls this directly
no test coverage detected