Sorted methods in alphabetical order.
This commit is contained in:
parent
8ad3ad6a18
commit
2202b4d1a8
@ -4,19 +4,19 @@ import "opslag.de/schobers/geom"
|
|||||||
|
|
||||||
func basisToPoints(p1, p2, p3, p4 geom.PointF32) geom.Matrix3x3F32 {
|
func basisToPoints(p1, p2, p3, p4 geom.PointF32) geom.Matrix3x3F32 {
|
||||||
var m = geom.Mx3x3F32(geom.Vec3F32(p1.X, p1.Y, 1), geom.Vec3F32(p2.X, p2.Y, 1), geom.Vec3F32(p3.X, p3.Y, 1))
|
var m = geom.Mx3x3F32(geom.Vec3F32(p1.X, p1.Y, 1), geom.Vec3F32(p2.X, p2.Y, 1), geom.Vec3F32(p3.X, p3.Y, 1))
|
||||||
var v = m.Adj().MulV(geom.Vec3F32(p4.X, p4.Y, 1))
|
var v = m.Adj().MulVec(geom.Vec3F32(p4.X, p4.Y, 1))
|
||||||
return m.MulM(geom.Mx3x3F32(geom.Vec3F32(v.X, 0, 0), geom.Vec3F32(0, v.Y, 0), geom.Vec3F32(0, 0, v.Z)))
|
return m.MulMx(geom.Mx3x3F32(geom.Vec3F32(v.X, 0, 0), geom.Vec3F32(0, v.Y, 0), geom.Vec3F32(0, 0, v.Z)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Projection32 calculates the projection matrix to transformation a point in rectangle src1, src2, src3, src4 to a point in rectangle dst1, dst2, dst3 and dst4.
|
// Projection32 calculates the projection matrix to transformation a point in rectangle src1, src2, src3, src4 to a point in rectangle dst1, dst2, dst3 and dst4.
|
||||||
func Projection32(src1, dst1, src2, dst2, src3, dst3, src4, dst4 geom.PointF32) geom.Matrix3x3F32 {
|
func Projection32(src1, dst1, src2, dst2, src3, dst3, src4, dst4 geom.PointF32) geom.Matrix3x3F32 {
|
||||||
var s = basisToPoints(src1, src2, src3, src4)
|
var s = basisToPoints(src1, src2, src3, src4)
|
||||||
var d = basisToPoints(dst1, dst2, dst3, dst4)
|
var d = basisToPoints(dst1, dst2, dst3, dst4)
|
||||||
return d.MulM(s.Adj())
|
return d.MulMx(s.Adj())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Project32 projects a point pt using the projection matrix p and returns the resulting point.
|
// Project32 projects a point pt using the projection matrix p and returns the resulting point.
|
||||||
func Project32(p geom.Matrix3x3F32, pt geom.PointF32) geom.PointF32 {
|
func Project32(p geom.Matrix3x3F32, pt geom.PointF32) geom.PointF32 {
|
||||||
var res = p.MulV(geom.Vec3F32(pt.X, pt.Y, 1))
|
var res = p.MulVec(geom.Vec3F32(pt.X, pt.Y, 1))
|
||||||
return geom.PtF32(res.X/res.Z, res.Y/res.Z)
|
return geom.PtF32(res.X/res.Z, res.Y/res.Z)
|
||||||
}
|
}
|
||||||
|
@ -12,25 +12,27 @@ func Mx3x3F32(i, j, k Vector3F32) Matrix3x3F32 {
|
|||||||
return Matrix3x3F32{i, j, k}
|
return Matrix3x3F32{i, j, k}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScaleV scales the matrix m by vector v.
|
// Adj calculates the adjugate matrix of matrix m.
|
||||||
func (m Matrix3x3F32) ScaleV(v Vector3F32) Matrix3x3F32 {
|
func (m Matrix3x3F32) Adj() Matrix3x3F32 {
|
||||||
return Matrix3x3F32{
|
return Mx3x3F32(
|
||||||
Vec3F32(v.X*m.I.X, v.X*m.I.Y, v.X*m.I.Z),
|
Vec3F32(m.J.Y*m.K.Z-m.K.Y*m.J.Z, m.K.Y*m.I.Z-m.I.Y*m.K.Z, m.I.Y*m.J.Z-m.J.Y*m.I.Z),
|
||||||
Vec3F32(v.Y*m.I.X, v.Y*m.I.Y, v.Y*m.I.Z),
|
Vec3F32(m.K.X*m.J.Z-m.J.X*m.K.Z, m.I.X*m.K.Z-m.K.X*m.I.Z, m.J.X*m.I.Z-m.I.X*m.J.Z),
|
||||||
Vec3F32(v.Z*m.I.X, v.Z*m.I.Y, v.Z*m.I.Z),
|
Vec3F32(m.J.X*m.K.Y-m.K.X*m.J.Y, m.K.X*m.I.Y-m.I.X*m.K.Y, m.I.X*m.J.Y-m.J.X*m.I.Y),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MulV multiplies the matrix m with vector v.
|
// Det calculates the determinant of the matrix m.
|
||||||
func (m Matrix3x3F32) MulV(v Vector3F32) Vector3F32 {
|
func (m Matrix3x3F32) Det() float32 {
|
||||||
return Vec3F32(
|
return m.I.X*m.J.Y*m.K.Z +
|
||||||
v.X*m.I.X+v.Y*m.J.X+v.Z*m.K.X,
|
m.J.X*m.K.Y*m.I.Z +
|
||||||
v.X*m.I.Y+v.Y*m.J.Y+v.Z*m.K.Y,
|
m.K.X*m.I.Y*m.J.Z -
|
||||||
v.X*m.I.Z+v.Y*m.J.Z+v.Z*m.K.Z)
|
m.K.X*m.J.Y*m.I.Z -
|
||||||
|
m.J.X*m.I.Y*m.K.Z -
|
||||||
|
m.I.X*m.K.Y*m.J.Z
|
||||||
}
|
}
|
||||||
|
|
||||||
// MulM multiplies the matrix m with matrix n.
|
// MulMx multiplies the matrix m with matrix n.
|
||||||
func (m Matrix3x3F32) MulM(n Matrix3x3F32) Matrix3x3F32 {
|
func (m Matrix3x3F32) MulMx(n Matrix3x3F32) Matrix3x3F32 {
|
||||||
return Matrix3x3F32{
|
return Matrix3x3F32{
|
||||||
Vec3F32(
|
Vec3F32(
|
||||||
n.I.X*m.I.X+n.I.Y*m.J.X+n.I.Z*m.K.X,
|
n.I.X*m.I.X+n.I.Y*m.J.X+n.I.Z*m.K.X,
|
||||||
@ -47,21 +49,19 @@ func (m Matrix3x3F32) MulM(n Matrix3x3F32) Matrix3x3F32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Det calculates the determinant of the matrix m.
|
// MulVec multiplies the matrix m with vector v.
|
||||||
func (m Matrix3x3F32) Det() float32 {
|
func (m Matrix3x3F32) MulVec(v Vector3F32) Vector3F32 {
|
||||||
return m.I.X*m.J.Y*m.K.Z +
|
return Vec3F32(
|
||||||
m.J.X*m.K.Y*m.I.Z +
|
v.X*m.I.X+v.Y*m.J.X+v.Z*m.K.X,
|
||||||
m.K.X*m.I.Y*m.J.Z -
|
v.X*m.I.Y+v.Y*m.J.Y+v.Z*m.K.Y,
|
||||||
m.K.X*m.J.Y*m.I.Z -
|
v.X*m.I.Z+v.Y*m.J.Z+v.Z*m.K.Z)
|
||||||
m.J.X*m.I.Y*m.K.Z -
|
|
||||||
m.I.X*m.K.Y*m.J.Z
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adj calculates the adjugate matrix of matrix m.
|
// ScaleVec scales the matrix m by vector v.
|
||||||
func (m Matrix3x3F32) Adj() Matrix3x3F32 {
|
func (m Matrix3x3F32) ScaleVec(v Vector3F32) Matrix3x3F32 {
|
||||||
return Mx3x3F32(
|
return Matrix3x3F32{
|
||||||
Vec3F32(m.J.Y*m.K.Z-m.K.Y*m.J.Z, m.K.Y*m.I.Z-m.I.Y*m.K.Z, m.I.Y*m.J.Z-m.J.Y*m.I.Z),
|
Vec3F32(v.X*m.I.X, v.X*m.I.Y, v.X*m.I.Z),
|
||||||
Vec3F32(m.K.X*m.J.Z-m.J.X*m.K.Z, m.I.X*m.K.Z-m.K.X*m.I.Z, m.J.X*m.I.Z-m.I.X*m.J.Z),
|
Vec3F32(v.Y*m.I.X, v.Y*m.I.Y, v.Y*m.I.Z),
|
||||||
Vec3F32(m.J.X*m.K.Y-m.K.X*m.J.Y, m.K.X*m.I.Y-m.I.X*m.K.Y, m.I.X*m.J.Y-m.J.X*m.I.Y),
|
Vec3F32(v.Z*m.I.X, v.Z*m.I.Y, v.Z*m.I.Z),
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
20
pointf.go
20
pointf.go
@ -17,21 +17,11 @@ func PtF(x, y float64) PointF {
|
|||||||
return PointF{X: x, Y: y}
|
return PointF{X: x, Y: y}
|
||||||
}
|
}
|
||||||
|
|
||||||
// To32 transforms the point p into a PointF32.
|
|
||||||
func (p PointF) To32() PointF32 {
|
|
||||||
return PointF32{float32(p.X), float32(p.Y)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add adds q as a vector to p.
|
// Add adds q as a vector to p.
|
||||||
func (p PointF) Add(q PointF) PointF {
|
func (p PointF) Add(q PointF) PointF {
|
||||||
return PointF{p.X + q.X, p.Y + q.Y}
|
return PointF{p.X + q.X, p.Y + q.Y}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sub subtracts q as a vector from p.
|
|
||||||
func (p PointF) Sub(q PointF) PointF {
|
|
||||||
return PointF{p.X - q.X, p.Y - q.Y}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AngleTo calculates the angle [0..2*Pi) from point p to point q.
|
// AngleTo calculates the angle [0..2*Pi) from point p to point q.
|
||||||
func (p PointF) AngleTo(q PointF) float64 {
|
func (p PointF) AngleTo(q PointF) float64 {
|
||||||
a := math.Atan((p.Y - q.Y) / (p.X - q.X))
|
a := math.Atan((p.Y - q.Y) / (p.X - q.X))
|
||||||
@ -81,3 +71,13 @@ func (p PointF) InPolygon(q PolygonF) bool {
|
|||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sub subtracts q as a vector from p.
|
||||||
|
func (p PointF) Sub(q PointF) PointF {
|
||||||
|
return PointF{p.X - q.X, p.Y - q.Y}
|
||||||
|
}
|
||||||
|
|
||||||
|
// To32 transforms the point p into a PointF32.
|
||||||
|
func (p PointF) To32() PointF32 {
|
||||||
|
return PointF32{float32(p.X), float32(p.Y)}
|
||||||
|
}
|
||||||
|
20
pointf32.go
20
pointf32.go
@ -17,21 +17,11 @@ func PtF32(x, y float32) PointF32 {
|
|||||||
return PointF32{x, y}
|
return PointF32{x, y}
|
||||||
}
|
}
|
||||||
|
|
||||||
// To64 transforms the point p into a PointF.
|
|
||||||
func (p PointF32) To64() PointF {
|
|
||||||
return PointF{float64(p.X), float64(p.Y)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add adds q as a vector to p.
|
// Add adds q as a vector to p.
|
||||||
func (p PointF32) Add(q PointF32) PointF32 {
|
func (p PointF32) Add(q PointF32) PointF32 {
|
||||||
return PointF32{p.X + q.X, p.Y + q.Y}
|
return PointF32{p.X + q.X, p.Y + q.Y}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sub subtracts q as a vector from p.
|
|
||||||
func (p PointF32) Sub(q PointF32) PointF32 {
|
|
||||||
return PointF32{p.X - q.X, p.Y - q.Y}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AngleTo calculates the angle [0..2*Pi) from point p to point q.
|
// AngleTo calculates the angle [0..2*Pi) from point p to point q.
|
||||||
func (p PointF32) AngleTo(q PointF32) float32 {
|
func (p PointF32) AngleTo(q PointF32) float32 {
|
||||||
a := float32(math.Atan(float64((p.Y - q.Y) / (p.X - q.X))))
|
a := float32(math.Atan(float64((p.Y - q.Y) / (p.X - q.X))))
|
||||||
@ -63,3 +53,13 @@ func (p PointF32) In(r RectangleF32) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sub subtracts q as a vector from p.
|
||||||
|
func (p PointF32) Sub(q PointF32) PointF32 {
|
||||||
|
return PointF32{p.X - q.X, p.Y - q.Y}
|
||||||
|
}
|
||||||
|
|
||||||
|
// To64 transforms the point p into a PointF.
|
||||||
|
func (p PointF32) To64() PointF {
|
||||||
|
return PointF{float64(p.X), float64(p.Y)}
|
||||||
|
}
|
||||||
|
@ -25,6 +25,21 @@ func (r RectangleF) Add(p PointF) RectangleF {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Center returns the center of the rectangle.
|
||||||
|
func (r RectangleF) Center() PointF {
|
||||||
|
return PointF{r.Min.X + .5*(r.Max.X-r.Min.X), r.Min.Y + .5*(r.Max.Y-r.Min.Y)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dx returns the width of r.
|
||||||
|
func (r RectangleF) Dx() float64 {
|
||||||
|
return r.Max.X - r.Min.X
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dy returns the height of r.
|
||||||
|
func (r RectangleF) Dy() float64 {
|
||||||
|
return r.Max.Y - r.Min.Y
|
||||||
|
}
|
||||||
|
|
||||||
// Inset returns the rectangle r inset by n. The resulting rectangle will never have
|
// Inset returns the rectangle r inset by n. The resulting rectangle will never have
|
||||||
// a negative size.
|
// a negative size.
|
||||||
func (r RectangleF) Inset(n float64) RectangleF {
|
func (r RectangleF) Inset(n float64) RectangleF {
|
||||||
@ -45,21 +60,6 @@ func (r RectangleF) Inset(n float64) RectangleF {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dx returns the width of r.
|
|
||||||
func (r RectangleF) Dx() float64 {
|
|
||||||
return r.Max.X - r.Min.X
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dy returns the height of r.
|
|
||||||
func (r RectangleF) Dy() float64 {
|
|
||||||
return r.Max.Y - r.Min.Y
|
|
||||||
}
|
|
||||||
|
|
||||||
// Center returns the center of the rectangle.
|
|
||||||
func (r RectangleF) Center() PointF {
|
|
||||||
return PointF{r.Min.X + .5*(r.Max.X-r.Min.X), r.Min.Y + .5*(r.Max.Y-r.Min.Y)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size returns the size of the rectangle.
|
// Size returns the size of the rectangle.
|
||||||
func (r RectangleF) Size() PointF {
|
func (r RectangleF) Size() PointF {
|
||||||
return PointF{r.Max.X - r.Min.X, r.Max.Y - r.Min.Y}
|
return PointF{r.Max.X - r.Min.X, r.Max.Y - r.Min.Y}
|
||||||
|
@ -25,6 +25,21 @@ func (r RectangleF32) Add(p PointF32) RectangleF32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Center returns the center of the rectangle.
|
||||||
|
func (r RectangleF32) Center() PointF32 {
|
||||||
|
return PointF32{r.Min.X + .5*(r.Max.X-r.Min.X), r.Min.Y + .5*(r.Max.Y-r.Min.Y)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dx returns the width of r.
|
||||||
|
func (r RectangleF32) Dx() float32 {
|
||||||
|
return r.Max.X - r.Min.X
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dy returns the height of r.
|
||||||
|
func (r RectangleF32) Dy() float32 {
|
||||||
|
return r.Max.Y - r.Min.Y
|
||||||
|
}
|
||||||
|
|
||||||
// Inset returns the rectangle r inset by n. The resulting rectangle will never have
|
// Inset returns the rectangle r inset by n. The resulting rectangle will never have
|
||||||
// a negative size.
|
// a negative size.
|
||||||
func (r RectangleF32) Inset(n float32) RectangleF32 {
|
func (r RectangleF32) Inset(n float32) RectangleF32 {
|
||||||
@ -45,21 +60,6 @@ func (r RectangleF32) Inset(n float32) RectangleF32 {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dx returns the width of r.
|
|
||||||
func (r RectangleF32) Dx() float32 {
|
|
||||||
return r.Max.X - r.Min.X
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dy returns the height of r.
|
|
||||||
func (r RectangleF32) Dy() float32 {
|
|
||||||
return r.Max.Y - r.Min.Y
|
|
||||||
}
|
|
||||||
|
|
||||||
// Center returns the center of the rectangle.
|
|
||||||
func (r RectangleF32) Center() PointF32 {
|
|
||||||
return PointF32{r.Min.X + .5*(r.Max.X-r.Min.X), r.Min.Y + .5*(r.Max.Y-r.Min.Y)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size returns the size of the rectangle.
|
// Size returns the size of the rectangle.
|
||||||
func (r RectangleF32) Size() PointF32 {
|
func (r RectangleF32) Size() PointF32 {
|
||||||
return PointF32{r.Max.X - r.Min.X, r.Max.Y - r.Min.Y}
|
return PointF32{r.Max.X - r.Min.X, r.Max.Y - r.Min.Y}
|
||||||
|
Loading…
Reference in New Issue
Block a user