formula

package
v0.0.0-...-78d9b97 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateCoordinateUsingWavePackets

func CalculateCoordinateUsingWavePackets(coordinate complex128, latticeVectors []complex128, wavePackets []WavePacket) complex128

CalculateCoordinateUsingWavePackets transforms the coordinate using the lattice and its wave packets.

func CalculateEulerTerm

func CalculateEulerTerm(z complex128, power1, power2 int, scale complex128, ignoreComplexConjugate bool) complex128

CalculateEulerTerm calculates e^(i*n*z) * e^(-i*m*zConj)

func CalculateExponentTerm

func CalculateExponentTerm(coordinate complex128, power1, power2 int, scale complex128, ignoreComplexConjugate bool) complex128

CalculateExponentTerm calculates (z^power * zConj^conjugatePower)

where z is a complex number, zConj is the complex conjugate
and power and conjugatePower are integers.

func CanWavePacketsBeGroupedAmongCoefficientRelationships

func CanWavePacketsBeGroupedAmongCoefficientRelationships(wavePackets []WavePacket, desiredRelationships []coefficient.Relationship) bool

CanWavePacketsBeGroupedAmongCoefficientRelationships returns true if the WavePackets involved satisfy the relationships.

func ContainsRelationship

func ContainsRelationship(relationships []coefficient.Relationship, target coefficient.Relationship) bool

ContainsRelationship returns true if the target relationship is in the list of relationships.

func ConvertToLatticeCoordinates

func ConvertToLatticeCoordinates(cartesianPoint complex128, latticeVectors []complex128) complex128

ConvertToLatticeCoordinates changes the coordinate to match the axes defined by the latticeVectors.

func GetAllPossibleTermRelationships3

func GetAllPossibleTermRelationships3(
	term1, term2 Term,
	term1Multiplier complex128,
	term2Multiplier complex128,
) []coefficient.Relationship

GetAllPossibleTermRelationships3 returns a list of relationships that all terms conform to.

func GetWavePacketRelationship

func GetWavePacketRelationship(wavePacket1, wavePacket2 WavePacket) []coefficient.Relationship

GetWavePacketRelationship returns a list of relationships that all of the wave packets conform to.

func HasSymmetry

func HasSymmetry(wavePackets []WavePacket, desiredSymmetry Symmetry, desiredSymmetryToCoefficients map[Symmetry][]coefficient.Relationship) bool

HasSymmetry returns true if the WavePackets involved form the desired symmetry.

func SatisfiesRelationship

func SatisfiesRelationship(term1, term2 Term, term1Multiplier, term2Multiplier complex128, relationship coefficient.Relationship) bool

SatisfiesRelationship sees if the all terms match the coefficient relationship.

func ValidateLatticeVectors

func ValidateLatticeVectors(latticeVectors []complex128) error

ValidateLatticeVectors returns an error if the lattice vectors are invalid.

Types

type Arbitrary

type Arbitrary interface {
	Calculate(coordinate complex128) complex128
	FormulaLevelTerms() []Term
	WavePackets() []WavePacket
	LatticeVectors() []complex128
	SymmetriesFound() []Symmetry
}

Arbitrary formulas have all of these methods.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is used to create formula objects.

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns a new object used to Build Formula objects.

func (*Builder) AddTerm

func (b *Builder) AddTerm(term *Term) *Builder

AddTerm adds a term to the formula.

func (*Builder) AddWavePacket

func (b *Builder) AddWavePacket(packet *WavePacket) *Builder

AddWavePacket adds a wave packet to the formula.

func (*Builder) Build

func (b *Builder) Build() (Arbitrary, error)

Build creates a new Formula object.

func (*Builder) DesiredSymmetry

func (b *Builder) DesiredSymmetry(symmetry Symmetry) *Builder

DesiredSymmetry sets the desired symmetry

func (*Builder) Frieze

func (b *Builder) Frieze() *Builder

Frieze sets the formula as a frieze formula.

func (*Builder) Generic

func (b *Builder) Generic() *Builder

Generic sets the formula as a generic formula.

func (*Builder) Hexagonal

func (b *Builder) Hexagonal() *Builder

Hexagonal sets the formula as a hexagonal formula.

func (*Builder) LatticeHeight

func (b *Builder) LatticeHeight(latticeHeight float64) *Builder

LatticeHeight sets the lattice height for wallpaper based patterns.

func (*Builder) LatticeWidth

func (b *Builder) LatticeWidth(latticeWidth float64) *Builder

LatticeWidth sets the lattice width for wallpaper based patterns.

func (*Builder) Rectangular

func (b *Builder) Rectangular() *Builder

Rectangular sets the formula as a rectangular formula.

func (*Builder) Rhombic

func (b *Builder) Rhombic() *Builder

Rhombic sets the formula as a rhombic formula.

func (*Builder) Rosette

func (b *Builder) Rosette() *Builder

Rosette sets the formula as a rosette formula.

func (*Builder) Square

func (b *Builder) Square() *Builder

Square sets the formula as a square formula.

func (*Builder) UsingJSONData

func (b *Builder) UsingJSONData(data []byte) *Builder

UsingJSONData updates the builder, given data

func (*Builder) UsingYAMLData

func (b *Builder) UsingYAMLData(data []byte) *Builder

UsingYAMLData updates the builder, given data

func (*Builder) WithMarshalOptions

func (b *Builder) WithMarshalOptions(marshaledOptions BuilderOptionMarshal) *Builder

WithMarshalOptions uses the options to populate the builder.

type BuilderOptionMarshal

type BuilderOptionMarshal struct {
	Type            string              `json:"type" yaml:"type"`
	Terms           []TermMarshal       `json:"terms" yaml:"terms"`
	LatticeWidth    float64             `json:"lattice_width" yaml:"lattice_width"`
	LatticeHeight   float64             `json:"lattice_height" yaml:"lattice_height"`
	WavePackets     []WavePacketMarshal `json:"wave_packets" yaml:"wave_packets"`
	DesiredSymmetry Symmetry            `json:"desired_symmetry" yaml:"desired_symmetry"`
}

BuilderOptionMarshal is a flattened representation of all Builder options.

type Frieze

type Frieze struct {
	// contains filtered or unexported fields
}

Frieze formulas transform points into a horizontal repeating strip, like the frieze patterns on ceilings and columns.

func NewFriezeFormula

func NewFriezeFormula(formulaLevelTerms []Term) (*Frieze, error)

NewFriezeFormula returns a new formula

func (*Frieze) Calculate

func (f *Frieze) Calculate(coordinate complex128) complex128

Calculate applies the Frieze formula to the complex number z.

func (*Frieze) FormulaLevelTerms

func (f *Frieze) FormulaLevelTerms() []Term

FormulaLevelTerms returns the terms this formula will use.

func (*Frieze) LatticeVectors

func (f *Frieze) LatticeVectors() []complex128

LatticeVectors returns an empty list, this formula does not use them

func (*Frieze) SymmetriesFound

func (f *Frieze) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Frieze) WavePackets

func (f *Frieze) WavePackets() []WavePacket

WavePackets returns an empty array, this type of formula does not use WavePackets.

type Generic

type Generic struct {
	// contains filtered or unexported fields
}

Generic formulas will transform points by returning the same coordinates.

func NewGenericFormula

func NewGenericFormula(packets []WavePacket, latticeWidth, latticeHeight float64, desiredSymmetry Symmetry) (*Generic, error)

NewGenericFormula returns a new formula object.

func (*Generic) Calculate

func (r *Generic) Calculate(coordinate complex128) complex128

Calculate transforms the coordinate using the Generic lattice's wave packets.

func (*Generic) FormulaLevelTerms

func (r *Generic) FormulaLevelTerms() []Term

FormulaLevelTerms returns an empty list, Generic formulas do not have base-level terms.

func (*Generic) LatticeVectors

func (r *Generic) LatticeVectors() []complex128

LatticeVectors returns the lattice vectors used to create the rectangle.

func (*Generic) SymmetriesFound

func (r *Generic) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Generic) WavePackets

func (r *Generic) WavePackets() []WavePacket

WavePackets returns the wave packets used.

type Hexagonal

type Hexagonal struct {
	// contains filtered or unexported fields
}

Hexagonal formulas will transform points by returning the same coordinates.

func NewHexagonalFormula

func NewHexagonalFormula(packets []WavePacket, desiredSymmetry Symmetry) (*Hexagonal, error)

NewHexagonalFormula returns a new formula object.

func (*Hexagonal) Calculate

func (r *Hexagonal) Calculate(coordinate complex128) complex128

Calculate transforms the coordinate using the Hexagonal lattice's wave packets.

func (*Hexagonal) FormulaLevelTerms

func (r *Hexagonal) FormulaLevelTerms() []Term

FormulaLevelTerms returns an empty list, Hexagonal formulas do not have base-level terms.

func (*Hexagonal) LatticeVectors

func (r *Hexagonal) LatticeVectors() []complex128

LatticeVectors returns the lattice vectors used to create the rectangle.

func (*Hexagonal) SymmetriesFound

func (r *Hexagonal) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Hexagonal) WavePackets

func (r *Hexagonal) WavePackets() []WavePacket

WavePackets returns the wave packets used.

type Identity

type Identity struct{}

Identity formulas will transform points by returning the same coordinates.

func (*Identity) Calculate

func (i *Identity) Calculate(coordinate complex128) complex128

Calculate returns the coordinate, the Identity formula returns the given input.

func (*Identity) FormulaLevelTerms

func (i *Identity) FormulaLevelTerms() []Term

FormulaLevelTerms returns an empty list, Identity formulas do not have terms.

func (*Identity) LatticeVectors

func (i *Identity) LatticeVectors() []complex128

LatticeVectors returns an empty list, this formula does not use them

func (*Identity) SymmetriesFound

func (i *Identity) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Identity) WavePackets

func (i *Identity) WavePackets() []WavePacket

WavePackets returns an empty array, this type of formula does not use WavePackets.

type Rectangular

type Rectangular struct {
	// contains filtered or unexported fields
}

Rectangular formulas will transform points by returning the same coordinates.

func NewRectangularFormula

func NewRectangularFormula(packets []WavePacket, latticeHeight float64, desiredSymmetry Symmetry) (*Rectangular, error)

NewRectangularFormula returns a new formula object.

func (*Rectangular) Calculate

func (r *Rectangular) Calculate(coordinate complex128) complex128

Calculate transforms the coordinate using the Rectangular lattice's wave packets.

func (*Rectangular) FormulaLevelTerms

func (r *Rectangular) FormulaLevelTerms() []Term

FormulaLevelTerms returns an empty list, Rectangular formulas do not have base-level terms.

func (*Rectangular) LatticeVectors

func (r *Rectangular) LatticeVectors() []complex128

LatticeVectors returns the lattice vectors used to create the rectangle.

func (*Rectangular) SymmetriesFound

func (r *Rectangular) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Rectangular) WavePackets

func (r *Rectangular) WavePackets() []WavePacket

WavePackets returns the wave packets used.

type Rhombic

type Rhombic struct {
	// contains filtered or unexported fields
}

Rhombic formulas will transform points by returning the same coordinates.

func NewRhombicFormula

func NewRhombicFormula(packets []WavePacket, latticeHeight float64, desiredSymmetry Symmetry) (*Rhombic, error)

NewRhombicFormula returns a new formula object.

func (*Rhombic) Calculate

func (r *Rhombic) Calculate(coordinate complex128) complex128

Calculate transforms the coordinate using the Rhombic lattice's wave packets.

func (*Rhombic) FormulaLevelTerms

func (r *Rhombic) FormulaLevelTerms() []Term

FormulaLevelTerms returns an empty list, Rhombic formulas do not have base-level terms.

func (*Rhombic) LatticeVectors

func (r *Rhombic) LatticeVectors() []complex128

LatticeVectors returns the lattice vectors used to create the rectangle.

func (*Rhombic) SymmetriesFound

func (r *Rhombic) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Rhombic) WavePackets

func (r *Rhombic) WavePackets() []WavePacket

WavePackets returns the wave packets used.

type Rosette

type Rosette struct {
	// contains filtered or unexported fields
}

Rosette formulas transform points around a central origin, similar to a rosette surrounding a center.

func NewRosetteFormula

func NewRosetteFormula(formulaLevelTerms []Term) (*Rosette, error)

NewRosetteFormula returns a new formula

func (*Rosette) Calculate

func (r *Rosette) Calculate(coordinate complex128) complex128

Calculate applies the Rosette formula to the complex number z.

func (*Rosette) FormulaLevelTerms

func (r *Rosette) FormulaLevelTerms() []Term

FormulaLevelTerms returns the terms this formula will use.

func (*Rosette) LatticeVectors

func (r *Rosette) LatticeVectors() []complex128

LatticeVectors returns an empty list, this formula does not use them

func (*Rosette) SymmetriesFound

func (r *Rosette) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Rosette) WavePackets

func (r *Rosette) WavePackets() []WavePacket

WavePackets returns an empty array, this type of formula does not use WavePackets.

type Square

type Square struct {
	// contains filtered or unexported fields
}

Square formulas will transform points by returning the same coordinates.

func NewSquareFormula

func NewSquareFormula(packets []WavePacket, desiredSymmetry Symmetry) (*Square, error)

NewSquareFormula returns a new formula object.

func (*Square) Calculate

func (r *Square) Calculate(coordinate complex128) complex128

Calculate transforms the coordinate using the Square lattice's wave packets.

func (*Square) FormulaLevelTerms

func (r *Square) FormulaLevelTerms() []Term

FormulaLevelTerms returns an empty list, Square formulas do not have base-level terms.

func (*Square) LatticeVectors

func (r *Square) LatticeVectors() []complex128

LatticeVectors returns the lattice vectors used to create the rectangle.

func (*Square) SymmetriesFound

func (r *Square) SymmetriesFound() []Symmetry

SymmetriesFound returns all symmetries found in this pattern.

func (*Square) WavePackets

func (r *Square) WavePackets() []WavePacket

WavePackets returns the wave packets used.

type Symmetry

type Symmetry string

Symmetry encodes all possible symmetries for wallpaper patterns.

const (
	P1   Symmetry = "p1"
	P2   Symmetry = "p2"
	P3   Symmetry = "p3"
	P3m1 Symmetry = "p3m1"
	P31m Symmetry = "p31m"
	P6   Symmetry = "p6"
	P6m  Symmetry = "p6m"
	P4   Symmetry = "p4"
	P4m  Symmetry = "p4m"
	P4g  Symmetry = "p4g"
	Cm   Symmetry = "cm"
	Cmm  Symmetry = "cmm"
	Pm   Symmetry = "pm"
	Pg   Symmetry = "pg"
	Pgg  Symmetry = "pgg"
	Pmm  Symmetry = "pmm"
	Pmg  Symmetry = "pmg"
)

All possible symmetries for wallpaper patterns, based on crystallography.

type Term

type Term struct {
	Multiplier               complex128
	PowerN                   int
	PowerM                   int
	IgnoreComplexConjugate   bool
	CoefficientRelationships []coefficient.Relationship
}

Term objects help shape the calculation of every formula.

func NewTerm

func NewTerm(multiplier complex128, powerN, powerM int, ignoreComplexConjugate bool, coefficientRelationships []coefficient.Relationship) *Term

NewTerm returns a new Term object.

func NewTermWithMultiplierAndPowers

func NewTermWithMultiplierAndPowers(multiplier complex128, powerN, powerM int) *Term

NewTermWithMultiplierAndPowers returns a new Term object using just the multiplier, PowerN and PowerM.

func (Term) CalculateInLatticeCoordinates

func (term Term) CalculateInLatticeCoordinates(zInLatticeCoordinates complex128) complex128

CalculateInLatticeCoordinates (z) = e ^ (2 PI i * (nX + mY))

where n amd m are PowerN and PowerM,
and TransformedX and TransformedY are the real and imag parts of (zInLatticeCoordinates)

func (Term) PowerSumIsEven

func (term Term) PowerSumIsEven() bool

PowerSumIsEven returns true if the sum of the term powers is divisible by 2.

type TermBuilder

type TermBuilder struct {
	// contains filtered or unexported fields
}

TermBuilder is used to create formula objects.

func NewTermBuilder

func NewTermBuilder() *TermBuilder

NewTermBuilder returns a new object used to build Term objects.

func (*TermBuilder) AddCoefficientRelationship

func (t *TermBuilder) AddCoefficientRelationship(coefficient coefficient.Relationship) *TermBuilder

AddCoefficientRelationship adds the coefficient.

func (*TermBuilder) Build

func (t *TermBuilder) Build() *Term

Build creates a new Term object.

func (*TermBuilder) IgnoreComplexConjugate

func (t *TermBuilder) IgnoreComplexConjugate() *TermBuilder

IgnoreComplexConjugate sets the field.

func (*TermBuilder) Multiplier

func (t *TermBuilder) Multiplier(multiplier complex128) *TermBuilder

Multiplier sets the field.

func (*TermBuilder) PowerM

func (t *TermBuilder) PowerM(coefficient int) *TermBuilder

PowerM sets the field.

func (*TermBuilder) PowerN

func (t *TermBuilder) PowerN(coefficient int) *TermBuilder

PowerN sets the field.

func (*TermBuilder) UsingJSONData

func (t *TermBuilder) UsingJSONData(data []byte) *TermBuilder

UsingJSONData updates the term, given data

func (*TermBuilder) UsingYAMLData

func (t *TermBuilder) UsingYAMLData(data []byte) *TermBuilder

UsingYAMLData updates the term, given data

func (*TermBuilder) WithMarshalOptions

func (t *TermBuilder) WithMarshalOptions(marshaledOptions TermMarshal) *TermBuilder

WithMarshalOptions updates the term builder using the options.

type TermMarshal

type TermMarshal struct {
	Multiplier               *utility.ComplexNumberForMarshal `json:"multiplier" yaml:"multiplier"`
	PowerN                   int                              `json:"power_n" yaml:"power_n"`
	PowerM                   int                              `json:"power_m" yaml:"power_m"`
	CoefficientRelationships []coefficient.Relationship       `json:"coefficient_relationships" yaml:"coefficient_relationships"`
	IgnoreComplexConjugate   bool                             `json:"ignore_complex_conjugate" yaml:"ignore_complex_conjugate"`
}

TermMarshal is a representation of a term object

type WavePacket

type WavePacket struct {
	// contains filtered or unexported fields
}

WavePacket for Waves mathematically creates repeating, cyclical mathematical patterns

in 2D space, similar to waves on the ocean.

func (WavePacket) Calculate

func (wavePacket WavePacket) Calculate(zInLatticeCoordinates complex128) complex128

Calculate takes the complex number zInLatticeCoordinates and processes it using the mathematical terms.

func (WavePacket) Multiplier

func (wavePacket WavePacket) Multiplier() complex128

Multiplier is a getter.

func (WavePacket) Terms

func (wavePacket WavePacket) Terms() []Term

Terms is a getter.

type WavePacketBuilder

type WavePacketBuilder struct {
	// contains filtered or unexported fields
}

WavePacketBuilder is used to create new WavePackets.

func NewWavePacketBuilder

func NewWavePacketBuilder() *WavePacketBuilder

NewWavePacketBuilder returns a blank WavePacketBuilder.

func (*WavePacketBuilder) AddTerm

func (w *WavePacketBuilder) AddTerm(term *Term) *WavePacketBuilder

AddTerm adds a term to the formula.

func (*WavePacketBuilder) Build

func (w *WavePacketBuilder) Build() *WavePacket

Build returns a new WavePacket.

func (*WavePacketBuilder) Multiplier

func (w *WavePacketBuilder) Multiplier(multiplier complex128) *WavePacketBuilder

Multiplier sets the wave packet's multiplier.

func (*WavePacketBuilder) UsingJSONData

func (w *WavePacketBuilder) UsingJSONData(data []byte) *WavePacketBuilder

UsingJSONData updates the term, given data

func (*WavePacketBuilder) UsingYAMLData

func (w *WavePacketBuilder) UsingYAMLData(data []byte) *WavePacketBuilder

UsingYAMLData updates the term, given data

func (*WavePacketBuilder) WithMarshalOptions

func (w *WavePacketBuilder) WithMarshalOptions(marshaledOptions WavePacketMarshal) *WavePacketBuilder

WithMarshalOptions updates the builder with options read from the options object.

type WavePacketMarshal

type WavePacketMarshal struct {
	Multiplier *utility.ComplexNumberForMarshal `json:"multiplier" yaml:"multiplier"`
	Terms      []TermMarshal                    `json:"terms" yaml:"terms"`
}

WavePacketMarshal is a representation of a term object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL