Skip to content

Commit d72f6b7

Browse files
committed
✨ (clockface): add minuteHandPoint
1 parent ec2fa0a commit d72f6b7

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

clockface_sample/clockface/clockface.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ func secondsInRadians(t time.Time) float64 {
3030
}
3131

3232
func secondHandPoint(t time.Time) Point {
33-
angle := secondsInRadians(t)
33+
return angleToPoint(secondsInRadians(t))
34+
}
35+
36+
func minutesInRadians(t time.Time) float64 {
37+
return (secondsInRadians(t) / 60) +
38+
(math.Pi / (30 / float64(t.Minute())))
39+
}
40+
41+
func angleToPoint(angle float64) Point {
3442
x := math.Sin(angle)
3543
y := math.Cos(angle)
3644

3745
return Point{x, y}
3846
}
3947

40-
func minutesInRadians(t time.Time) float64 {
41-
return (secondsInRadians(t) / 60) +
42-
(math.Pi / (30 / float64(t.Minute())))
48+
func minuteHandPoint(t time.Time) Point {
49+
return angleToPoint(minutesInRadians(t))
4350
}

clockface_sample/clockface/clockface_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,22 @@ func TestMinutesInRadians(t *testing.T) {
8181
})
8282
}
8383
}
84+
85+
func TestMinuteHandPoint(t *testing.T) {
86+
cases := []struct {
87+
time time.Time
88+
point Point
89+
}{
90+
{simpleTime(0, 30, 0), Point{0, -1}},
91+
{simpleTime(0, 45, 0), Point{-1, 0}},
92+
}
93+
94+
for _, c := range cases {
95+
t.Run(testName(c.time), func(t *testing.T) {
96+
got := minuteHandPoint(c.time)
97+
if !roughlyEqualPoint(got, c.point) {
98+
t.Fatalf("Wanted %v Point, but got %v", c.point, got)
99+
}
100+
})
101+
}
102+
}

0 commit comments

Comments
 (0)