Documentation ¶
Index ¶
- Constants
- Variables
- func CDiv(p, q image.Point) image.Point
- func CFloat(p image.Point) (x, y float64)
- func CMul(p, q image.Point) image.Point
- func CSign(p image.Point) image.Point
- func Dot(p, q image.Point) int
- func FSign(m float64) float64
- func PolygonContains(convex []image.Point, p image.Point) bool
- func PolygonExtrema(polygon []image.Point) [4]image.Point
- func PolygonRectOverlap(convex []image.Point, rect image.Rectangle) bool
- func Project(π Projector, p Int3) image.Point
- func Sign(m int) int
- type Box
- func (b Box) Add(p Int3) Box
- func (b Box) Back(π Projector) image.Rectangle
- func (b Box) BoundingRect(π Projector) image.Rectangle
- func (b Box) Canon() Box
- func (b Box) Centre() Int3
- func (b Box) Empty() bool
- func (b Box) Eq(c Box) bool
- func (b Box) Front(π Projector) image.Rectangle
- func (b Box) Overlaps(c Box) bool
- func (b Box) Size() Int3
- func (b Box) String() string
- func (b Box) Sub(p Int3) Box
- func (b Box) XY() image.Rectangle
- func (b Box) XZ() image.Rectangle
- type CubicSpline
- type ElevationProjection
- type Float2
- func (p Float2) Add(q Float2) Float2
- func (p Float2) CDiv(q Float2) Float2
- func (p Float2) CMul(q Float2) Float2
- func (p Float2) Coord() (x, y float64)
- func (p Float2) Div(k float64) Float2
- func (p Float2) Dot(q Float2) float64
- func (p Float2) Mul(k float64) Float2
- func (p Float2) Neg() Float2
- func (p Float2) Sign() Float2
- func (p Float2) String() string
- func (p Float2) Sub(q Float2) Float2
- type Float3
- func (p Float3) Add(q Float3) Float3
- func (p Float3) CDiv(q Float3) Float3
- func (p Float3) CMul(q Float3) Float3
- func (p Float3) Coord() (x, y, z float64)
- func (p Float3) Div(k float64) Float3
- func (p Float3) Dot(q Float3) float64
- func (p Float3) Mul(k float64) Float3
- func (p Float3) Neg() Float3
- func (p Float3) Sign() Float3
- func (p Float3) String() string
- func (p Float3) Sub(q Float3) Float3
- type Int3
- func (p Int3) Add(q Int3) Int3
- func (p Int3) CDiv(q Int3) Int3
- func (p Int3) CMul(q Int3) Int3
- func (p Int3) Coord() (x, y, z int)
- func (p Int3) Div(k int) Int3
- func (p Int3) Dot(q Int3) int
- func (p Int3) Mul(k int) Int3
- func (p Int3) Neg() Int3
- func (p Int3) Sign() Int3
- func (p Int3) String() string
- func (p Int3) Sub(q Int3) Int3
- func (p Int3) XY() image.Point
- func (p Int3) XZ() image.Point
- type IntFloat
- func (x IntFloat) Add(y IntFloat) IntFloat
- func (x IntFloat) Canon() IntFloat
- func (x IntFloat) Div(y IntFloat) IntFloat
- func (x IntFloat) Float() float64
- func (x IntFloat) Gt(y IntFloat) bool
- func (x IntFloat) Inv() IntFloat
- func (x IntFloat) Lt(y IntFloat) bool
- func (x IntFloat) Mul(y IntFloat) IntFloat
- func (x IntFloat) Neg() IntFloat
- func (x IntFloat) String() string
- func (x IntFloat) Sub(y IntFloat) IntFloat
- type IntMatrix2x3
- type IntMatrix3
- type IntMatrix3x4
- type IntProjection
- type LinearSpline
- type Matrix3x4
- type Projection
- type Projector
- type Rat
- type RatMatrix3
- type SimpleProjection
Constants ¶
const ( East = iota North West South )
Cardinal directions, as used in the return from PolygonExtrema.
Variables ¶
var IdentityMatrix3x4 = Matrix3x4{ 0: [4]float64{0: 1}, 1: [4]float64{1: 1}, 2: [4]float64{2: 1}, }
IdentityMatrix3x4 is the identity matrix for Matrix3x4.
var IdentityRatMatrix3 = RatMatrix3{ 0: [3]Rat{0: {1, 1}}, 1: [3]Rat{1: {1, 1}}, 2: [3]Rat{2: {1, 1}}, }
IdentityRatMatrix3 is the identity matrix for RatMatrix3.
Functions ¶
func PolygonContains ¶
PolygonContains reports if a convex polygon contains a point. The polygon must be in clockwise order if +Y is pointing upwards, or anticlockwise if +Y is pointing downwards.
func PolygonExtrema ¶
PolygonExtrema returns the most easterly, northerly, westerly, and southerly points (north is in the -Y direction, east is in the +X direction, etc). If there are multiple points furthest in any direction, the first one is used.
func PolygonRectOverlap ¶
PolygonRectOverlap reports if a convex polygon overlaps a rectangle.
Types ¶
type Box ¶
type Box struct {
Min, Max Int3
}
Box describes an axis-aligned rectangular prism.
func (Box) Back ¶
Back returns an image.Rectangle representing the back of the box, using the given projection π.
func (Box) BoundingRect ¶
BoundingRect returns an image.Rectangle that bounds the box if it were projected.
func (Box) Eq ¶
Eq reports whether b and c contain the same set of points. All empty boxes are considered equal.
func (Box) Front ¶
Front returns an image.Rectangle representing the front of the box, using the given projection π.
type CubicSpline ¶
type CubicSpline struct { Points []Float2 // If false, CubicSpline defines a natural cubic spline (the slopes at the // endpoints are "free" and the moments at the ends are zero.) // If true, Preslope (or Postslope, or both) is used to set the slope. FixedPreslope, FixedPostslope bool // Slope of line before and after spline, for extrapolation. // If a natural cubic spline is being used, these are set by Prepare. // If instead FixedPreslope or FixedPostslope are true, these are read by // Prepare to determine the moments. Preslope, Postslope float64 // contains filtered or unexported fields }
CubicSpline implements a cubic spline. A cubic spline interpolates the given Points with cubic polynomials, ensuring first and second derivatives along the whole spline are continuous.
func (*CubicSpline) Interpolate ¶
func (s *CubicSpline) Interpolate(x float64) float64
Interpolate returns y where (x,y) is a point on the spline. If x is outside the spline, it extrapolates from the first or last point together with s.Preslope or s.Postslope.
func (*CubicSpline) Prepare ¶
func (s *CubicSpline) Prepare() error
Prepare sorts the points and computes internal information.
type ElevationProjection ¶
type ElevationProjection struct{}
ElevationProjection throws away Z.
func (ElevationProjection) Project ¶
func (ElevationProjection) Project(int) image.Point
Project returns the zero point.
func (ElevationProjection) Sign ¶
func (ElevationProjection) Sign() image.Point
Sign returns the zero point.
type Float2 ¶
type Float2 struct {
X, Y float64
}
Float2 is an element of float64^2
type Float3 ¶
type Float3 struct {
X, Y, Z float64
}
Float3 is an element of float64^3.
type Int3 ¶
type Int3 struct {
X, Y, Z int
}
Int3 is a an element of int^3.
type IntFloat ¶
IntFloat represents a number as an integer part plus a fractional part. This can represent reals in the int range with decent precision.
func ToIntFloat ¶
ToIntFloat converts a float64 directly into an IntFloat.
func (IntFloat) Canon ¶
Canon returns a value equal to x, in canonical form (0 ≤ F < 1). Each possible value only has one canonical form.
func (IntFloat) Gt ¶
Gt reports x > y. x and y must be in canonical form for the comparison to be meaningful.
type IntMatrix2x3 ¶
type IntMatrix2x3 struct{ X, Y Int3 }
IntMatrix2x3 implements a 2 row, 3 column matrix (as two row vectors).
type IntMatrix3 ¶
type IntMatrix3 [3][3]int
IntMatrix3 implements a 3x3 integer matrix.
func (IntMatrix3) Apply ¶
func (a IntMatrix3) Apply(v Int3) Int3
Apply applies the matrix to a vector to obtain a transformed vector.
func (IntMatrix3) Concat ¶
func (a IntMatrix3) Concat(b IntMatrix3) IntMatrix3
Concat returns the matrix equivalent to applying matrix a and then b.
type IntMatrix3x4 ¶
type IntMatrix3x4 [3][4]int
IntMatrix3x4 implements a 3 row, 4 column integer matrix, capable of describing any integer affine transformation.
func (IntMatrix3x4) Apply ¶
func (a IntMatrix3x4) Apply(v Int3) Int3
Apply applies the matrix to a vector to obtain a transformed vector.
func (IntMatrix3x4) ToRatMatrix3 ¶
func (a IntMatrix3x4) ToRatMatrix3() RatMatrix3
ToRatMatrix3 returns the 3x3 submatrix as a rational matrix equivalent.
func (IntMatrix3x4) Translation ¶
func (a IntMatrix3x4) Translation() Int3
Translation returns the translation component of the matrix (last column) i.e. what you get if you Apply the matrix to the zero vector.
type IntProjection ¶
IntProjection uses two integers to define a custom projection. It is designed for projecting Z onto X and Y with integer fractions as would be used in e.g. a diametric projection (IntProjection{X:0, Y:2}).
type LinearSpline ¶
type LinearSpline struct { Points []Float2 // contains filtered or unexported fields }
LinearSpline implements a linear spline.
func (*LinearSpline) Interpolate ¶
func (s *LinearSpline) Interpolate(x float64) float64
Interpolate returns y where (x,y) is a point on the spline. If x is outside the spline, it extrapolates from either the first or last segments of the spline.
func (*LinearSpline) Prepare ¶
func (s *LinearSpline) Prepare() error
Prepare sorts the points and computes internal information.
type Matrix3x4 ¶
type Matrix3x4 [3][4]float64
Matrix3x4 implements a 3x4 matrix with floating-point values.
func (Matrix3x4) Translation ¶
Translation returns the translation component of the matrix (last column) i.e. what you get if you Apply the matrix to the zero vector.
type Projection ¶
type Projection struct{ X, Y float64 }
Projection uses two floats to define a custom projection.
func (Projection) Project ¶
func (π Projection) Project(z int) image.Point
Project returns (z*π.X, z*π.Y).
func (Projection) Sign ¶
func (π Projection) Sign() image.Point
Sign returns the componentwise sign of π.
type Projector ¶
type Projector interface { // Sign returns a {-1, 0, 1}-valued 2D vector pointing in the direction that // positive Z values are projected to. Sign() image.Point // Project converts a Z coordinate to a 2D offset. Project(int) image.Point }
Projector types can be used to project 3D coordinates into 2D. It only supports projecting Z into a 2D offset (i.e. not a general projection).
type Rat ¶
type Rat struct{ N, D int }
Rat is a (small) rational number implementation. Overflow can happen.
type RatMatrix3 ¶
type RatMatrix3 [3][3]Rat
RatMatrix3 implements a 3x3 matrix with rational number entries.
func (RatMatrix3) Adjugate ¶
func (a RatMatrix3) Adjugate() RatMatrix3
Adjugate returns the adjugate of the matrix.
func (RatMatrix3) Concat ¶
func (a RatMatrix3) Concat(b RatMatrix3) RatMatrix3
Concat returns the matrix equivalent to applying matrix a and then b.
func (RatMatrix3) IntApply ¶
func (a RatMatrix3) IntApply(v Int3) Int3
IntApply applies the matrix to the integer vector v. Any remainder is lost.
func (RatMatrix3) Inverse ¶
func (a RatMatrix3) Inverse() (RatMatrix3, error)
Inverse returns the inverse of the matrix.
func (RatMatrix3) Mul ¶
func (a RatMatrix3) Mul(r Rat) RatMatrix3
Mul multiplies the whole matrix by a scalar.
type SimpleProjection ¶
type SimpleProjection struct{}
SimpleProjection projects Z onto Y only.