This repository was archived by the owner on Apr 2, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle_test.go
More file actions
48 lines (40 loc) · 1.36 KB
/
circle_test.go
File metadata and controls
48 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package curve
import (
"math"
"slices"
"testing"
)
func TestCircleAreaSign(t *testing.T) {
approxEqual := func(x, y float64) bool {
return math.Abs(x-y) < 1e-7
}
center := Pt(5, 5)
c := Circle{center, 5}
if a := c.Area(); !approxEqual(a, 25*math.Pi) {
t.Errorf("got area %v, expected %v", a, 25.0*math.Pi)
}
if w := c.Winding(center); w != 1 {
t.Errorf("got winding number %d, expected 1", w)
}
p := BezPath(slices.Collect(c.PathElements(1e-9)))
if ca, pa := c.Area(), p.SignedArea(); !approxEqual(ca, pa) {
t.Errorf("got areas %v and %v, expected them to be equal", ca, pa)
}
if cw, pw := c.Winding(center), p.Winding(center); cw != pw {
t.Errorf("got winding numbers %d and %d, expected them to be equal", cw, pw)
}
cNegRadius := Circle{center, -5}
if a := cNegRadius.Area(); !approxEqual(a, 25.0*math.Pi) {
t.Errorf("got area %v, expected %v", a, 25.0*math.Pi)
}
if w := cNegRadius.Winding(center); w != 1 {
t.Errorf("got winding number %d, expected 1", w)
}
pNegRadius := BezPath(slices.Collect(cNegRadius.PathElements(1e-9)))
if ca, pa := cNegRadius.Area(), pNegRadius.SignedArea(); !approxEqual(ca, pa) {
t.Errorf("got areas %v and %v, expected them to be equal", ca, pa)
}
if cw, pw := cNegRadius.Winding(center), pNegRadius.Winding(center); cw != pw {
t.Errorf("got winding numbers %d and %d, expected them to be equal", cw, pw)
}
}