capitalized names
This commit is contained in:
parent
62635d35e4
commit
bf833807f0
@ -6,19 +6,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestSub(t *testing.T) {
|
func TestSub(t *testing.T) {
|
||||||
p1 := point2d{10, 10}
|
p1 := Point2d{10, 10}
|
||||||
p2 := point2d{5, 5}
|
p2 := Point2d{5, 5}
|
||||||
|
|
||||||
v := p1.sub(p2)
|
v := p1.sub(p2)
|
||||||
|
|
||||||
if v != (vector2d{5, 5}) {
|
if v != (Vector2d{5, 5}) {
|
||||||
t.Errorf("Sub Error")
|
t.Errorf("Sub Error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMag(t *testing.T) {
|
func TestMag(t *testing.T) {
|
||||||
p1 := point2d{10, 10}
|
p1 := Point2d{10, 10}
|
||||||
p2 := point2d{7, 6}
|
p2 := Point2d{7, 6}
|
||||||
|
|
||||||
v := p1.sub(p2)
|
v := p1.sub(p2)
|
||||||
m := v.mag()
|
m := v.mag()
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
package govector
|
package govector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
type vector2d struct {
|
type Vector2d struct {
|
||||||
X float64 `json:"x"`
|
X float64 `json:"x"`
|
||||||
Y float64 `json:"y"`
|
Y float64 `json:"y"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type point2d struct {
|
type Point2d struct {
|
||||||
X float64 `json:"x"`
|
X float64 `json:"x"`
|
||||||
Y float64 `json:"y"`
|
Y float64 `json:"y"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const epsilon = 1e-7
|
const epsilon = 1e-7
|
||||||
|
|
||||||
func (p1 point2d) sub(p2 point2d) vector2d {
|
func (p1 Point2d) sub(p2 Point2d) Vector2d {
|
||||||
v := vector2d{p1.X - p2.X, p1.Y - p2.Y}
|
v := Vector2d{p1.X - p2.X, p1.Y - p2.Y}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v vector2d) mag() float64 {
|
func (v Vector2d) mag() float64 {
|
||||||
return math.Abs(math.Sqrt(v.X*v.X + v.Y*v.Y))
|
return math.Abs(math.Sqrt(v.X*v.X + v.Y*v.Y))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user