types

package
v0.0.0-...-f9d76ff Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package types implements the base types that the renderer uses

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCosineSimilarity

func GetCosineSimilarity(p1, p2, p3 Vector2d) float64

GetCosineSimilarity gets the cosine similarity between two vectors P1 is end 1 P2 is the pivot point P3 is end 2

Types

type Circle

type Circle struct {
	Center Vector2d
	Radius float64
}

Circle is a 2D Circle, it stores the Center and the Radius

func (*Circle) Render

func (cir *Circle) Render() ([]Vector2d, error)

Render returns a slice containing the points on the perimeter of the circle It's mildly complex with a circle, check the link in the code for how it works

func (*Circle) RotateAbout

func (cir *Circle) RotateAbout(vec Vector2d, angleRads float64)

RotateAbout rotates about an arbitrary point

func (*Circle) RotateAboutCenter

func (cir *Circle) RotateAboutCenter(float64)

RotateAboutCenter does nothing

func (*Circle) Scale

func (cir *Circle) Scale(scaleFactor float64)

Scale scales the radius

func (*Circle) ScaleX

func (cir *Circle) ScaleX(float64)

ScaleX does nothing

func (*Circle) ScaleXY

func (cir *Circle) ScaleXY(float64, float64)

ScaleXY does nothing

func (*Circle) ScaleY

func (cir *Circle) ScaleY(float64)

ScaleY does nothing

func (*Circle) Translate

func (cir *Circle) Translate(vec Vector2d)

Translate moves the circle

type NPoly

type NPoly struct {
	// each point is connected to the next and the last is connected to the 0th one
	Points []Vector2d `json:"Points"`
}

func (*NPoly) GetTriangles

func (np *NPoly) GetTriangles() []Triangle

GetTriangles decomposes a shape into it's composite triangles

func (*NPoly) Render

func (np *NPoly) Render() ([]Vector2d, error)

Render draws the poly as points

func (*NPoly) RenderComposite

func (np *NPoly) RenderComposite() ([][]Vector2d, error)

RenderComposite renders the NPoly as a collection of triangles as opposed to one Polygon, this is good for more complex draws

func (*NPoly) RotateAbout

func (np *NPoly) RotateAbout(vec Vector2d, angleRads float64)

RotateAbout rotates all points around some arbitrary point by some magnitude

func (*NPoly) RotateAboutCenter

func (np *NPoly) RotateAboutCenter(angleRads float64)

RotateAboutCenter rotates about the center of a polygon

func (*NPoly) Scale

func (np *NPoly) Scale(scaleFactor float64)

Scale scales all points by some value

func (*NPoly) ScaleX

func (np *NPoly) ScaleX(scaleFactor float64)

ScaleX scales the X value of all points by some value

func (*NPoly) ScaleXY

func (np *NPoly) ScaleXY(scaleFactorX float64, scaleFactorY float64)

ScaleXY scales X and Y values by different values

func (*NPoly) ScaleY

func (np *NPoly) ScaleY(scaleFactor float64)

ScaleY scales all Y values by some value

func (*NPoly) Translate

func (np *NPoly) Translate(vec Vector2d)

Translate moves all points by some vector

type Obj2D

type Obj2D interface {
	Translate(Vector2d)            // Move Obj2D by magnitude provided by vector passed
	Scale(float64)                 // Scale X,Y of all Points by Z magnitude
	ScaleX(float64)                // Scale X of all Points by Z magnitude
	ScaleY(float64)                // Scale Y of all Points by Z magnitude
	ScaleXY(float64, float64)      // Scale X and Y of all points by Z and A respectively
	RotateAbout(Vector2d, float64) // Rotate all points around given point by X degrees
	RotateAboutCenter(float64)     // Rotate a 2D Object about its center
}

Obj2D is an interface defining the API for any 2D object that can be handled by the renderer

type Obj3D

type Obj3D interface {
	Obj2D
	ScaleXZ(float64, float64)              // Scale X and Z values by A and B magnitudes
	ScaleYZ(float64, float64)              // Scale Y and Z values by A and B magnitudes
	ScaleXYZ(float64, float64)             // Scale X, Y, and Z values by A, B, and C magnitudes
	Scale3D(float64)                       // Scale all Values by some magnitude
	Translate3D(Vector3d)                  // Translate by a 3D value
	RotateAboutPoint3D(Vector3d, Vector3d) // Rotate about some point by some degrees X,Y,Z rads stored as a vector
	RotateAboutCenter3D(Vector3d)          // Rotate a 3D object About its center
}

Obj3D is an interface defining the API for any 3D object that can be handled by the renderer

type Quad

type Quad struct {
	/*
		Quad line mappings

		1->2
		1->3
		2->4
		3->4
	*/
	Point1 Vector2d `json:"Point1"` // Top Left
	Point2 Vector2d `json:"Point2"` // Top Right
	Point3 Vector2d `json:"Point3"` // Bottom Left
	Point4 Vector2d `json:"Point4"` // Bottom Right
}

Quad is a 4 point Polygon

func (*Quad) GetTriangles

func (q *Quad) GetTriangles() []Triangle

func (*Quad) Render

func (q *Quad) Render() ([]Vector2d, error)

Render renders the Quad

func (*Quad) RotateAbout

func (q *Quad) RotateAbout(vec Vector2d, angleRads float64)

RotateAbout rotates the entire poly about an arbitrary point

func (*Quad) RotateAboutCenter

func (q *Quad) RotateAboutCenter(angleRads float64)

RotateAboutCenter rotates about the center of the quad

func (*Quad) Scale

func (q *Quad) Scale(scaleFactor float64)

Scale scales the Quad on both X and Y values

func (*Quad) ScaleX

func (q *Quad) ScaleX(scaleFactor float64)

ScaleX scales the X value of all points

func (*Quad) ScaleXY

func (q *Quad) ScaleXY(scaleFactorX float64, scaleFactorY float64)

ScaleXY scales the X and Y values independent of one another

func (*Quad) ScaleY

func (q *Quad) ScaleY(scaleFactor float64)

ScaleY scales the Y value of all points

func (*Quad) Translate

func (q *Quad) Translate(vec Vector2d)

Translate moves a quad by whatever is in the vector

type Renderable

type Renderable interface {
	Render() ([]Vector2d, error)
}

type RenderableComposite

type RenderableComposite interface {
	GetTriangles() []Triangle
	RenderComposite() ([][]Vector2d, error)
}

RenderableComposite constructs an Obj2D image as a more complicated shape

type Triangle

type Triangle struct {
	Point1   Vector2d `json:"Point1"`   // Point 1 of the Triangle
	Point2   Vector2d `json:"Point2"`   // Point 2 of the Triangle
	Point3   Vector2d `json:"Point3"`   // Point 3 of the Triangle
	Centroid Vector2d `json:"Centroid"` // The Centroid of the Triangle
}

Triangle is a type describing a Triangle on a 2D plane

func MakeTriangle

func MakeTriangle(p1, p2, p3 Vector2d) Triangle

MakeTriangle creates a triangle struct populated with all the appropriate stuff

func (*Triangle) Render

func (t *Triangle) Render() ([]Vector2d, error)

Render renders the triangle

func (*Triangle) RotateAbout

func (t *Triangle) RotateAbout(vec Vector2d, angleRads float64)

RotateAbout rotates a triangle about a given point

func (*Triangle) RotateAboutCenter

func (t *Triangle) RotateAboutCenter(angleRads float64)

RotateAboutCenter rotates a triangle about the center of itself

func (*Triangle) Scale

func (t *Triangle) Scale(scaleFactor float64)

Scale scales all the points of a triangle by a given amount

func (*Triangle) ScaleX

func (t *Triangle) ScaleX(scaleFactorX float64)

ScaleX scales the X values of a triangle by a given amount

func (*Triangle) ScaleXY

func (t *Triangle) ScaleXY(scaleFactorX float64, scaleFactorY float64)

ScaleXY scales the X and Y values of a triangle by a given amount

func (*Triangle) ScaleY

func (t *Triangle) ScaleY(scaleFactorY float64)

ScaleY scales the Y values of a triangle by a given amount

func (*Triangle) Translate

func (t *Triangle) Translate(vec Vector2d)

Translate translates a triangle by some vector X,Y

type Vector2d

type Vector2d struct {
	X float64 `json:"X"` // X Coordinate
	Y float64 `json:"Y"` // Y Coordinate
}

Vector2d is a 2d Vector storing doubles

func DrawCurve

func DrawCurve(quantity uint, points ...Vector2d) ([]Vector2d, error)

DrawCurve returns a slice containing points on a given types.curve, Bezier curves take control points as arguments, the only time that All points given are guaranteed to exist on a line is when there's Only two points provided. this outputs it in whatever scale you provided the input in If the coords are in world space, it returns world space If they're screen space, it returns screen space, if it's pixels, it returns pixels etc. etc.

func GetCompositeVector2dMinMax

func GetCompositeVector2dMinMax(inpVec [][]Vector2d) ([2]Vector2d, error)

GetCompositeVector2dMinMax does the same but for 2d arrays

func GetVector2dMinMax

func GetVector2dMinMax(inpVec []Vector2d) ([2]Vector2d, error)

GetVector2dMinMax returns the minimum and maximum X,Y values shared across a group of vectors

func (*Vector2d) GetAbs

func (v2d *Vector2d) GetAbs() float64

GetAbs gets the absolute value of the vector

func (*Vector2d) GetDotProduct

func (v2d *Vector2d) GetDotProduct(vector Vector2d) float64

GetDotProduct gets the Dot Product of two vectors

func (*Vector2d) GetRelativeCoords

func (v2d *Vector2d) GetRelativeCoords(point Vector2d) Vector2d

GetRelativeCoords gets the relative coordinates of a point from another given point

func (*Vector2d) Render

func (v2d *Vector2d) Render() ([]Vector2d, error)

Render returns the vector itself in a slice

func (*Vector2d) RotateAbout

func (v2d *Vector2d) RotateAbout(point Vector2d, angleRads float64)

RotateAbout rotates a point around an arbitrary point by some amount of radians

func (*Vector2d) RotateAboutCenter

func (v2d *Vector2d) RotateAboutCenter(angleRads float64)

RotateAboutCenter does nothing on a 2D vector

func (*Vector2d) Scale

func (v2d *Vector2d) Scale(scaleFactor float64)

Scale does what you think it does. it also deliberately allows for negative values so you can invert it this way :)

func (*Vector2d) ScaleX

func (v2d *Vector2d) ScaleX(scaleFactor float64)

ScaleX scales the X by a given value

func (*Vector2d) ScaleXY

func (v2d *Vector2d) ScaleXY(scaleFactorX float64, scaleFactorY float64)

ScaleXY allows you to scale X and Y by different vals in one function

func (*Vector2d) ScaleY

func (v2d *Vector2d) ScaleY(scaleFactor float64)

ScaleY scales the Y by a given value

func (*Vector2d) Translate

func (v2d *Vector2d) Translate(translate Vector2d)

TranslateAndScale moves the Vector by X,Y

type Vector3d

type Vector3d struct {
	Vector2d
	Z float64 `json:"Z"`
}

Vector3d is the primitive type for all 3D objects

func (*Vector3d) GetRelativeCoords3D

func (v3d *Vector3d) GetRelativeCoords3D(point Vector3d) Vector3d

GetRelativeCoords3D gets the relative coordinates to some point in 3d space

func (*Vector3d) RotateAbout3D

func (v3d *Vector3d) RotateAbout3D(point, amounts Vector3d)

RotateAbout3D rotates the vector about some point on the X, Y, and Z axes (in that order) values in the amounts vector should be angles in radians

func (*Vector3d) RotateAboutCenter3D

func (v3d *Vector3d) RotateAboutCenter3D(ret Vector3d)

RotateAboutCenter3D does nothing on this as it's the center of itself

func (*Vector3d) RotateAboutX

func (v3d *Vector3d) RotateAboutX(degRads float64)

RotateAboutX rotates the vector about X by some rads

func (*Vector3d) RotateAboutY

func (v3d *Vector3d) RotateAboutY(degRads float64)

RotateAboutY rotates about Y by some rads

func (*Vector3d) RotateAboutZ

func (v3d *Vector3d) RotateAboutZ(degRads float64)

RotateAboutZ rotates about the Z axis by some amount

func (*Vector3d) Scale3D

func (v3d *Vector3d) Scale3D(scaleFactor float64)

Scale3D scales X,Y,and Z by some factor

func (*Vector3d) ScaleXYZ

func (v3d *Vector3d) ScaleXYZ(scaleX, scaleY, scaleZ float64)

ScaleXYZ scales X, Y, and Z values by some factor

func (*Vector3d) ScaleXZ

func (v3d *Vector3d) ScaleXZ(scaleX, scaleZ float64)

ScaleXZ scales X and Z values by some factors

func (*Vector3d) ScaleYZ

func (v3d *Vector3d) ScaleYZ(scaleY, scaleZ float64)

ScaleYZ scales Y and Z values by some factors

func (*Vector3d) Translate3D

func (v3d *Vector3d) Translate3D(vector Vector3d)

Translate3D moves the vector by some point

Directories

Path Synopsis
testapps
tools

Jump to

Keyboard shortcuts

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