float32 -> float64
This commit is contained in:
+19
-19
@@ -31,13 +31,13 @@ func (p Polygon2d) Edge(i int) (Point2d, Vector2d) {
|
||||
}
|
||||
|
||||
type Vector2d struct {
|
||||
X float32 `json:"x"`
|
||||
Y float32 `json:"y"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"y"`
|
||||
}
|
||||
|
||||
type Point2d struct {
|
||||
X float32 `json:"x"`
|
||||
Y float32 `json:"y"`
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"y"`
|
||||
}
|
||||
|
||||
const Epsilon = 1e-7
|
||||
@@ -52,27 +52,27 @@ func (p Point2d) Add(v Vector2d) Point2d {
|
||||
return Point2d{p.X + v.X, p.Y + v.Y}
|
||||
}
|
||||
|
||||
func (v Vector2d) Mag() float32 {
|
||||
return float32(math.Abs(math.Sqrt(float64(v.X*v.X) + float64(v.Y*v.Y))))
|
||||
func (v Vector2d) Mag() float64 {
|
||||
return math.Abs(math.Sqrt(v.X*v.X + v.Y*v.Y))
|
||||
}
|
||||
|
||||
func (v Vector2d) MagSquared() float32 {
|
||||
return float32(math.Abs(float64(v.X*v.X) + float64(v.Y*v.Y)))
|
||||
func (v Vector2d) MagSquared() float64 {
|
||||
return math.Abs(v.X*v.X + v.Y*v.Y)
|
||||
}
|
||||
|
||||
func (v Vector2d) PopPop() float32 {
|
||||
func (v Vector2d) PopPop() float64 {
|
||||
return v.Mag()
|
||||
}
|
||||
|
||||
func (v Vector2d) Scale(s float32) Vector2d {
|
||||
func (v Vector2d) Scale(s float64) Vector2d {
|
||||
return Vector2d{v.X * s, v.Y * s}
|
||||
}
|
||||
|
||||
func (v1 Vector2d) Cross(v2 Vector2d) float32 {
|
||||
func (v1 Vector2d) Cross(v2 Vector2d) float64 {
|
||||
return v1.X*v2.Y - v1.Y*v2.X
|
||||
}
|
||||
|
||||
func (v1 Vector2d) Dot(v2 Vector2d) float32 {
|
||||
func (v1 Vector2d) Dot(v2 Vector2d) float64 {
|
||||
return (v1.X * v2.X) + (v1.Y * v2.Y)
|
||||
}
|
||||
|
||||
@@ -84,17 +84,17 @@ func (v Vector2d) ToPoint() Point2d {
|
||||
return Point2d{v.X, v.Y}
|
||||
}
|
||||
|
||||
func (v1 Vector2d) Rotate(a float32) Vector2d {
|
||||
func (v1 Vector2d) Rotate(a float64) Vector2d {
|
||||
x := float64(v1.X)*math.Cos(float64(a)) - float64(v1.Y)*math.Sin(float64(a))
|
||||
y := float64(v1.X)*math.Sin(float64(a)) + float64(v1.Y)*math.Cos(float64(a))
|
||||
return Vector2d{float32(x), float32(y)}
|
||||
return Vector2d{x, y}
|
||||
}
|
||||
|
||||
func PointInRect(p Point2d, r AABB2d) bool {
|
||||
return (p.X > r.A.X) && (p.X < r.B.X) && (p.Y > r.A.Y) && (p.Y < r.B.Y)
|
||||
}
|
||||
|
||||
func AASquareAtPoint(p Point2d, edgeLength float32) AABB2d {
|
||||
func AASquareAtPoint(p Point2d, edgeLength float64) AABB2d {
|
||||
size := edgeLength / 2.0
|
||||
return AABB2d{
|
||||
A: Point2d{X: p.X - size, Y: p.Y - size},
|
||||
@@ -113,7 +113,7 @@ func (r AABB2d) ToPolygon() Polygon2d {
|
||||
return p
|
||||
}
|
||||
|
||||
func OrientedSquare(center Point2d, heading Vector2d, size float32) Polygon2d {
|
||||
func OrientedSquare(center Point2d, heading Vector2d, size float64) Polygon2d {
|
||||
out := Polygon2d{}
|
||||
out.Origin.X = center.X
|
||||
out.Origin.Y = center.Y
|
||||
@@ -136,12 +136,12 @@ func (v Vector2d) Normalize() Vector2d {
|
||||
return Vector2d{v.X / m, v.Y / m}
|
||||
}
|
||||
|
||||
func Distance(p1, p2 Point2d) float32 {
|
||||
func Distance(p1, p2 Point2d) float64 {
|
||||
return p1.Sub(p2).Mag()
|
||||
}
|
||||
|
||||
// returns radians
|
||||
func Angle(v1, v2 Vector2d) float32 {
|
||||
func Angle(v1, v2 Vector2d) float64 {
|
||||
x := (v1.Dot(v2) / (v1.Mag() * v2.Mag()))
|
||||
angle := math.Acos(float64(x))
|
||||
|
||||
@@ -158,5 +158,5 @@ func Angle(v1, v2 Vector2d) float32 {
|
||||
if v1.Y*v2.X > v1.X*v2.Y {
|
||||
angle = angle * -1.0
|
||||
}
|
||||
return float32(angle)
|
||||
return angle
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user