Skip to content

Commit d929c0c

Browse files
committed
✨ (clockface): add implementation for SecondHand
1 parent 0611af8 commit d929c0c

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

clockface/clockface.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ type Point struct {
1111
Y float64
1212
}
1313

14+
const secondHandLength = 90
15+
const clockCentreX = 150
16+
const clockCentreY = 150
17+
1418
// SecondHand is the unit vector of the second hand of an analogue clock at time `t`
15-
// represented as a Point
19+
// represented as a Point.
1620
func SecondHand(t time.Time) Point {
17-
return Point{150, 60}
21+
p := secondHandPoint(t)
22+
p = Point{p.X * secondHandLength, p.Y * secondHandLength}
23+
p = Point{p.X, -p.Y}
24+
p = Point{p.X + clockCentreX, p.Y + clockCentreY} //translate
25+
return p
1826
}
1927

2028
func secondsInRadians(t time.Time) float64 {

clockface/clockface_acceptance_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func TestSecondHandAtMidnight(t *testing.T) {
1818
}
1919
}
2020

21-
// func TestSecondHandAt30Seconds(t *testing.T) {
22-
// tm := time.Date(1337, time.January, 1, 0, 0, 30, 0, time.UTC)
21+
func TestSecondHandAt30Seconds(t *testing.T) {
22+
tm := time.Date(1337, time.January, 1, 0, 0, 30, 0, time.UTC)
2323

24-
// want := clockface.Point{X: 150, Y: 150 + 90}
25-
// got := clockface.SecondHand(tm)
24+
want := clockface.Point{X: 150, Y: 150 + 90}
25+
got := clockface.SecondHand(tm)
2626

27-
// if got != want {
28-
// t.Errorf("got %v, wanted %v", got, want)
29-
// }
30-
// }
27+
if got != want {
28+
t.Errorf("got %v, wanted %v", got, want)
29+
}
30+
}

0 commit comments

Comments
 (0)