summaryrefslogtreecommitdiff
path: root/go/triangle/triangle.go
blob: 482cb605b894785b8d4b8ea7442637f62bf9d6c4 (plain)
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
package triangle

import "math"

const testVersion = 2

func KindFromSides(a, b, c float64) Kind {
	invalid := func(n float64) bool {
		return math.IsNaN(n) || math.IsInf(n, 0) || n <= 0
	}
	if invalid(a) || invalid(b) || invalid(c) {
		return NaT
	}
	if a+b < c || a+c < b || b+c < a {
		return NaT
	}
	if a == b && b == c {
		return Equ
	}
	if a == b || b == c || a == c {
		return Iso
	}
	return Sca
}

type Kind string

const (
	NaT Kind = "not a triangle"
	Equ Kind = "equilateral"
	Iso Kind = "isosceles"
	Sca Kind = "scalene"
)