Documentation ¶
Overview ¶
Package coord provides vector types for various coordinates systems.
Floating-point Coordinates ¶
Three structs with float32 fields give access to geometric transformations, and other useful mathematical operations (see subpackages plane and space):
// 2D cartesian coordinates var a = XY{1.0, 2.0} // 3D cartesian coordinates (or 2D projective coordinates) var b = XYZ{1.0, 2.0, 3.0} // 3D projective coordinates var c = XYZW{1.0, 2.0, 3.0, 4.0}
Integer Coordinates ¶
Two structs with int16 fields are used both for on-screen coordinates and in-game grids:
// 2D cartesian grid coordinates (e.g. pixel coordinates) var a = CR{1, 2} // CRD for 3D cartesian grid coordinates (e.g. voxel coordinates) var b = CRD{1, 2, 3}
Other Coordinate systems ¶
Various structs for hexagonal and triangular grids:
// Hexagonal grid coordinates var a = QR{1, 2} // Axial (hex) coordinates var b = AL{1.0, 2.0} // triangular grid coordinates var c = QRT{1, 2, 0}
And finally structs to manipulate angles:
// Polar coordinates var a = RA{1.0, 3.14} // Cylindrical coordinates var b = RAZ{1.0, 3.14, 2.0} // Spherical coordinates var c = RAS{1.0, 3.14, 6.28}
Index ¶
- type CR
- func (a CR) CRD(d int16) CRD
- func (a CR) Cartesian() (x, y, z float32)
- func (a CR) Col() CR
- func (a CR) FlipC() CR
- func (a CR) FlipR() CR
- func (a CR) Minus(b CR) CR
- func (a CR) MinusS(s int16) CR
- func (a CR) Mod(s int16) CR
- func (a CR) ModCR(b CR) CR
- func (a CR) Null() bool
- func (a CR) Opposite() CR
- func (a CR) Perp() CR
- func (a CR) Plus(b CR) CR
- func (a CR) PlusS(s int16) CR
- func (a CR) RC() CR
- func (a CR) Row() CR
- func (a CR) Slash(s int16) CR
- func (a CR) SlashCR(b CR) CR
- func (a CR) Times(s int16) CR
- func (a CR) TimesCR(b CR) CR
- func (a CR) XY() XY
- func (a CR) XYZ(z float32) XYZ
- func (a CR) XYZW(z, w float32) XYZW
- type CRD
- func (a CRD) Cartesian() (x, y, z float32)
- func (a CRD) Col() CRD
- func (a CRD) Depth() CRD
- func (a CRD) FlipC() CRD
- func (a CRD) FlipD() CRD
- func (a CRD) FlipR() CRD
- func (a CRD) Minus(b CRD) CRD
- func (a CRD) Minuss(s int16) CRD
- func (a CRD) Mod(s int16) CRD
- func (a CRD) Modcr(b CRD) CRD
- func (a CRD) Opposite() CRD
- func (a CRD) Plus(b CRD) CRD
- func (a CRD) Pluss(s int16) CRD
- func (a CRD) Row() CRD
- func (a CRD) Slash(s int16) CRD
- func (a CRD) Slashcr(b CRD) CRD
- func (a CRD) Times(s int16) CRD
- func (a CRD) Timescr(b CRD) CRD
- func (a CRD) XY() XY
- func (a CRD) XYZ() XYZ
- func (a CRD) XYZW(w float32) XYZW
- type Coordinates
- type RA
- type RA64
- type RAB
- type RAZ
- type XY
- func (a XY) CR() CR
- func (a XY) Cartesian() (x, y, z float32)
- func (a XY) Distance(b XY) float32
- func (a XY) Distance2(b XY) float32
- func (a XY) Dot(b XY) float32
- func (a XY) FlipX() XY
- func (a XY) FlipY() XY
- func (a XY) IsAlmostEqual(b XY, ulps uint32) bool
- func (a XY) IsNearlyEqual(b XY, epsilon float32) bool
- func (a XY) IsRoughlyEqual(b XY, epsilon float32) bool
- func (a XY) Length() float32
- func (a XY) Length2() float32
- func (a XY) Minus(b XY) XY
- func (a XY) Minuss(s float32) XY
- func (a XY) Mod(s float32) XY
- func (a XY) Modf() (intg, frac XY)
- func (a XY) Modxy(b XY) XY
- func (a XY) Normalized() XY
- func (a XY) Opposite() XY
- func (a XY) PerpDot(b XY) float32
- func (a XY) Plus(b XY) XY
- func (a XY) Pluss(s float32) XY
- func (a XY) RoundCR() CR
- func (a XY) Slash(s float32) XY
- func (a XY) Slashxy(b XY) XY
- func (a XY) Times(s float32) XY
- func (a XY) Timesxy(b XY) XY
- func (a XY) XY64() XY64
- func (a XY) XYZ(z float32) XYZ
- type XY64
- func (a XY64) Cartesian() (x, y, z float32)
- func (a XY64) Distance(b XY64) float64
- func (a XY64) Distance2(b XY64) float64
- func (a XY64) Dot(b XY64) float64
- func (a XY64) Length() float64
- func (a XY64) Length2() float64
- func (a XY64) Minus(b XY64) XY64
- func (a XY64) Minuss(s float64) XY64
- func (a XY64) Mod(s float64) XY64
- func (a XY64) Modf() (intg, frac XY64)
- func (a XY64) Modxy(b XY64) XY64
- func (a XY64) Normalized() XY64
- func (a XY64) Opposite() XY64
- func (a XY64) PerpDot(b XY64) float64
- func (a XY64) Plus(b XY64) XY64
- func (a XY64) Pluss(s float64) XY64
- func (a XY64) Slash(s float64) XY64
- func (a XY64) Slashxy(b XY64) XY64
- func (a XY64) Times(s float64) XY64
- func (a XY64) Timesxy(b XY64) XY64
- func (a XY64) XY() XY
- func (a XY64) XYZ64() XYZ64
- type XYZ
- func (a XYZ) Cartesian() (x, y, z float32)
- func (a XYZ) Cross(b XYZ) XYZ
- func (a XYZ) Distance(b XYZ) float32
- func (a XYZ) Distance2(b XYZ) float32
- func (a XYZ) Dot(b XYZ) float32
- func (a XYZ) IsAlmostEqual(b XYZ, ulps uint32) bool
- func (a XYZ) IsNearlyEqual(b XYZ, epsilon float32) bool
- func (a XYZ) IsRoughlyEqual(b XYZ, epsilon float32) bool
- func (a XYZ) Length() float32
- func (a XYZ) Length2() float32
- func (a XYZ) Minus(b XYZ) XYZ
- func (a XYZ) Mod(s float32) XYZ
- func (a XYZ) ModCW(b XYZ) XYZ
- func (a XYZ) Modf() (intg, frac XYZ)
- func (a XYZ) Normalized() XYZ
- func (a XYZ) Opposite() XYZ
- func (a XYZ) Plus(b XYZ) XYZ
- func (a XYZ) Slash(s float32) XYZ
- func (a XYZ) SlashCW(b XYZ) XYZ
- func (a XYZ) Times(s float32) XYZ
- func (a XYZ) TimesCW(b XYZ) XYZ
- func (a XYZ) XY() XY
- func (a XYZ) XYZW(w float32) XYZW
- func (a XYZ) XYproj() XY
- func (a XYZ) XZ() XY
- func (a XYZ) YX() XY
- func (a XYZ) YZ() XY
- func (a XYZ) ZX() XY
- func (a XYZ) ZY() XY
- type XYZ64
- type XYZW
- type XYZW64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CR ¶
type CR struct {
C, R int16
}
CR represents 2D integer coordinates. C stands for "column" and corresponds to the x-coordinate, while R stands for "row" and corresponds to the y-coordinate.
func CRof ¶
func CRof(v Coordinates) CR
CRof returns an integer vector corresponding to the first two coordinates of v.
func (CR) CRD ¶
CRD returns the integer coordinates of the vector in 3D space, with d as third coordinate.
func (CR) Cartesian ¶
Cartesian returns the coordinates of the vector in 3D space. C and R are casted to float32, and the third coordinate is always 0.
func (CR) Mod ¶
Mod returns the remainder (modulus) of the division by a scalar (which must be non-zero).
func (CR) ModCR ¶
ModCR returns the remainder (modulus) of the component-wise division by another vector (of which both C and R must be non-zero).
func (CR) Slash ¶
Slash returns the integer quotient of the division by a scalar (which must be non-zero).
func (CR) SlashCR ¶
SlashCR returns the integer quotients of the component-wise division by another vector (of which both C and R must be non-zero).
type CRD ¶
type CRD struct {
C, R, D int16
}
CRD represents 3D integer coordinates. C stands for "column" and corresponds to the x-coordinate, R stands for "row" and corresponds to the y-coordinate, and D stands for "depth" and corresponds to the z-coordinate.
func CRDof ¶
func CRDof(v Coordinates) CRD
CRDof returns the integer coordinates corresponding to v.
func (CRD) Cartesian ¶
Cartesian returns the coordinates of the vector in 3D space. C,R and D are casted to float32.
func (CRD) Mod ¶
Mod returns the remainder (modulus) of the division by a scalar (which must be non-zero).
func (CRD) Modcr ¶
Modcr returns the remainder (modulus) of the component-wise division by another vector (of which both C and R must be non-zero).
func (CRD) Slash ¶
Slash returns the integer quotient of the division by a scalar (which must be non-zero).
func (CRD) Slashcr ¶
Slashcr returns the integer quotients of the component-wise division by another vector (of which both C and R must be non-zero).
type Coordinates ¶
type Coordinates interface { // Cartesian returns the cartesian coordinates of the vector. Cartesian() (x, y, z float32) }
Coordinates represents any three-dimensional vector.
type RA ¶
type RA struct { R float32 // Distance from origin (i.e. radius) A float32 // Angle (counter-clockwise from 3 b'clock) }
RA represents polar coordinates.
Note: incomplete implementation.
type RA64 ¶
type RA64 struct { D float64 // Distance from origin (i.e. radius) A float64 // Angle //TODO: what angle? }
RA64 represents a two dimensional vector, defined by its polar coordinates.
type RAB ¶
type RAB struct { R float32 // Distance from origin (i.e. radius) A float32 // Angle (counter-clockwise from 3 b'clock) S float32 // Second angle }
RAB represents a three dimensional vector, defined by its spherical coordinates.
Note: not yet implemented.
type RAZ ¶
type RAZ struct { R float32 // Distance from origin (i.e. radius) A float32 // Angle (counter-clockwise from 3 b'clock) Z float32 // Depth }
RAZ represents a three dimensional vector, defined by its cylindrical coordinates.
Note: not yet implemented.
type XY ¶
XY represents 2D cartesian coordinates.
func (XY) IsAlmostEqual ¶
IsAlmostEqual returns true if the difference between the two vectors is less than the specified ULPs (Unit in the Last Place).
Handle special cases: zero, infinites, denormals.
See also IsNearlyEqual and IsRoughlyEqual.
func (XY) IsNearlyEqual ¶
IsNearlyEqual Returns true if the relative error between the two vectors is less than epsilon.
Handles special cases: zero, infinites, denormals.
See also IsAlmostEqual and IsRoughlyEqual.
func (XY) IsRoughlyEqual ¶
IsRoughlyEqual Returns true if the absolute error between the two vectors is less than epsilon.
See also IsNearlyEqual and IsAlmostEqual.
func (XY) Mod ¶
Mod returns the remainder (modulus) of the division by a scalar (which must be non-zero).
func (XY) Modf ¶
Modf returns the integer part and the fractional part of (each component of) the vector.
func (XY) Modxy ¶
Modxy returns the remainders (modulus) of the component-wise division by another vector (of which both X and Y must be non-zero).
func (XY) Normalized ¶
Normalized return the normalization of the vector (i.e. the vector divided by its length, which must be non-zero).
func (XY) Slashxy ¶
Slashxy returns the component-wise division by another vector (of which both X and Y must be non-zero).
type XY64 ¶
XY64 represents 64-bit 2D cartesian coordinates.
func (XY64) Cartesian ¶
Cartesian returns the cartesian coordinates of the vector.
This function implements the Vector interface.
func (XY64) Mod ¶
Mod returns the remainder (modulus) of the division by a scalar (which must be non-zero).
func (XY64) Modf ¶
Modf returns the integer part and the fractional part of (each component of) the vector.
func (XY64) Modxy ¶
Modxy returns the remainders (modulus) of the component-wise division by another vector (of which both X and Y must be non-zero).
func (XY64) Normalized ¶
Normalized return the normalization of the vector (i.e. the vector divided by its length, which must be non-zero).
func (XY64) PerpDot ¶
PerpDot returns the dot product with the perpendicular of a and another vector.
func (XY64) Slashxy ¶
Slashxy returns the component-wise division by another vector (of which both X and Y must be non-zero).
type XYZ ¶
XYZ represents either 3D cartesian coordinates, or 2D projective (homogeneous) coordinates.
func (XYZ) IsAlmostEqual ¶
IsAlmostEqual returns true if the difference between the two vectors is less than the specified ULPs (Unit in the Last Place).
Handle special cases: zero, infinites, denormals.
See also IsNearlyEqual and IsRoughlyEqual.
func (XYZ) IsNearlyEqual ¶
IsNearlyEqual Returns true if the relative error between the two vectors is less than epsilon.
Handles special cases: zero, infinites, denormals.
See also IsAlmostEqual and IsRoughlyEqual.
func (XYZ) IsRoughlyEqual ¶
IsRoughlyEqual Returns true if the absolute error between the two vectors is less than epsilon.
See also IsNearlyEqual and IsAlmostEqual.
func (XYZ) Mod ¶
Mod returns the remainder (modulus) of the division by a scalar (which must be non-zero).
func (XYZ) ModCW ¶
ModCW returns the remainders (modulus) of the component-wise division by another vector (of which X, Y and Z must be non-zero).
func (XYZ) Modf ¶
Modf returns the integer part and the fractional part of (each component of) the vector.
func (XYZ) Normalized ¶
Normalized return the normalization of the vector (i.e. the vector divided by its length, which must be non-zero).
func (XYZ) SlashCW ¶
SlashCW returns the component-wise division by another vector (of which X, Y and Z must be non-zero).
type XYZW ¶
XYZW represents 3D projective (homogeneous) coordinates.