HomeUniDoc
...

Package transform

Overview ▾

Index ▾

type Matrix
    func IdentityMatrix() Matrix
    func NewMatrix(a, b, c, d, tx, ty float64) Matrix
    func NewMatrixFromTransforms(xScale, yScale, theta, tx, ty float64) Matrix
    func RotationMatrix(angle float64) Matrix
    func ScaleMatrix(x, y float64) Matrix
    func ShearMatrix(x, y float64) Matrix
    func TranslationMatrix(tx, ty float64) Matrix
    func (m Matrix) Angle() float64
    func (m *Matrix) Clone() Matrix
    func (m *Matrix) Concat(b Matrix)
    func (m Matrix) Identity() bool
    func (m Matrix) Inverse() (Matrix, bool)
    func (m Matrix) Mult(b Matrix) Matrix
    func (m Matrix) Rotate(theta float64) Matrix
    func (m Matrix) Round(precision float64) Matrix
    func (m Matrix) Scale(xScale, yScale float64) Matrix
    func (m Matrix) ScalingFactorX() float64
    func (m Matrix) ScalingFactorY() float64
    func (m *Matrix) Set(a, b, c, d, tx, ty float64)
    func (m *Matrix) Shear(x, y float64)
    func (m Matrix) Singular() bool
    func (m Matrix) String() string
    func (m Matrix) Transform(x, y float64) (float64, float64)
    func (m Matrix) Translate(tx, ty float64) Matrix
    func (m Matrix) Translation() (float64, float64)
    func (m Matrix) Unrealistic() bool
type Point
    func NewPoint(x, y float64) Point
    func (p Point) Displace(delta Point) Point
    func (a Point) Distance(b Point) float64
    func (a Point) Interpolate(b Point, t float64) Point
    func (p Point) Rotate(theta float64) Point
    func (p *Point) Set(x, y float64)
    func (p Point) String() string
    func (p *Point) Transform(a, b, c, d, tx, ty float64)

Package files

matrix.go point.go

type Matrix

Matrix is a linear transform matrix in homogenous coordinates. PDF coordinate transforms are always affine so we only need 6 of these. See newMatrix.

type Matrix [9]float64

func IdentityMatrix

func IdentityMatrix() Matrix

IdentityMatrix returns the identity transform.

func NewMatrix

func NewMatrix(a, b, c, d, tx, ty float64) Matrix

NewMatrix returns an affine transform matrix laid out in homogenous coordinates as

a  b  0
c  d  0
tx ty 1

func NewMatrixFromTransforms

func NewMatrixFromTransforms(xScale, yScale, theta, tx, ty float64) Matrix

NewMatrix returns an affine transform matrix that

scales by `xScale`, `yScale`,
rotated by `theta` degrees, and
translates by `tx`, `ty`.

func RotationMatrix

func RotationMatrix(angle float64) Matrix

RotationMatrix returns a matrix that rotates by angle `angle`, specified in radians.

func ScaleMatrix

func ScaleMatrix(x, y float64) Matrix

ScaleMatrix returns a matrix that scales by `x`,`y`.

func ShearMatrix

func ShearMatrix(x, y float64) Matrix

ShearMatrix returns a matrix that shears `x`,`y`.

func TranslationMatrix

func TranslationMatrix(tx, ty float64) Matrix

TranslationMatrix returns a matrix that translates by `tx`,`ty`.

func (Matrix) Angle

func (m Matrix) Angle() float64

Angle returns the angle of the affine transform in `m` in degrees.

func (*Matrix) Clone

func (m *Matrix) Clone() Matrix

Clone returns a copy of the current matrix.

func (*Matrix) Concat

func (m *Matrix) Concat(b Matrix)

Concat sets `m` to `b` × `m`. `b` needs to be created by newMatrix. i.e. It must be an affine transform.

b00 b01 0     m00 m01 0     b00*m00 + b01*m01        b00*m10 + b01*m11        0
b10 b11 0  ×  m10 m11 0  ➔  b10*m00 + b11*m01        b10*m10 + b11*m11        0
b20 b21 1     m20 m21 1     b20*m00 + b21*m10 + m20  b20*m01 + b21*m11 + m21  1

func (Matrix) Identity

func (m Matrix) Identity() bool

Identity returns true if `m` is the identity matrix.

func (Matrix) Inverse

func (m Matrix) Inverse() (Matrix, bool)

Inverse returns the inverse of `m` and a boolean to indicate whether the inverse exists.

func (Matrix) Mult

func (m Matrix) Mult(b Matrix) Matrix

Mult returns `b` × `m`.

func (Matrix) Rotate

func (m Matrix) Rotate(theta float64) Matrix

Rotate returns `m` with an extra rotation of `theta` degrees. NOTE: This rotation pre-multiplies `m` so it will be scaled and rotated by `m`.

func (Matrix) Round

func (m Matrix) Round(precision float64) Matrix

Round rounds off matrix to specified precision. E.g. m.Round(0.000001)

func (Matrix) Scale

func (m Matrix) Scale(xScale, yScale float64) Matrix

Scale returns `m` with an extra scaling of `xScale`,`yScale` to `m`. NOTE: This scaling pre-multiplies `m` so it will be scaled and rotated by `m`.

func (Matrix) ScalingFactorX

func (m Matrix) ScalingFactorX() float64

ScalingFactorX returns the X scaling of the affine transform.

func (Matrix) ScalingFactorY

func (m Matrix) ScalingFactorY() float64

ScalingFactorY returns the Y scaling of the affine transform.

func (*Matrix) Set

func (m *Matrix) Set(a, b, c, d, tx, ty float64)

Set sets `m` to affine transform a,b,c,d,tx,ty.

func (*Matrix) Shear

func (m *Matrix) Shear(x, y float64)

Shear shears the current matrix by `x',`y`.

func (Matrix) Singular

func (m Matrix) Singular() bool

Singular returns true if `m` contains a singular matrix. NOTE(peterwilliams97). We are just checking for bad "cm" commands. We don't need to compute the condition number.

func (Matrix) String

func (m Matrix) String() string

String returns a string describing `m`.

func (Matrix) Transform

func (m Matrix) Transform(x, y float64) (float64, float64)

Transform returns coordinates `x`,`y` transformed by `m`.

func (Matrix) Translate

func (m Matrix) Translate(tx, ty float64) Matrix

Translate returns `m` with an extra translation of `tx`,`ty`.

func (Matrix) Translation

func (m Matrix) Translation() (float64, float64)

Translation returns the translation part of `m`.

func (Matrix) Unrealistic

func (m Matrix) Unrealistic() bool

Unrealistic returns true if `m` is too small to have been created intentionally. If it returns true then `m` probably contains junk values, due to some processing error in the PDF generator or our code.

type Point

Point defines a point (X,Y) in Cartesian coordinates.

type Point struct {
    X float64
    Y float64
}

func NewPoint

func NewPoint(x, y float64) Point

NewPoint returns a Point at `(x,y)`.

func (Point) Displace

func (p Point) Displace(delta Point) Point

Displace returns a new Point at location `p` + `delta`.

func (Point) Distance

func (a Point) Distance(b Point) float64

Distance returns the distance between `a` and `b`.

func (Point) Interpolate

func (a Point) Interpolate(b Point, t float64) Point

Interpolate does linear interpolation between point `a` and `b` for value `t`.

func (Point) Rotate

func (p Point) Rotate(theta float64) Point

Rotate returns a new Point at `p` rotated by `theta` degrees.

func (*Point) Set

func (p *Point) Set(x, y float64)

Set mutates `p` and sets to coordinates `(x, y)`.

func (Point) String

func (p Point) String() string

String returns a string describing `p`.

func (*Point) Transform

func (p *Point) Transform(a, b, c, d, tx, ty float64)

Transform mutates and transforms `p` by the affine transformation a, b, c, d, tx, ty.