shapes

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedValue = errors.New("error unexpected value")
)

Shapes errors

Functions

func DegreesToRadian

func DegreesToRadian(degrees float64) float64

DegreesToRadian return radian for given degrees

func GetAngle2D

func GetAngle2D(v1 Point, v2 Point) float64

GetAngle2D get angle between points in radian

func NormalizeDegrees

func NormalizeDegrees(value float64) float64

NormalizeDegrees return degrees n range 0-360

func RadianToDegree

func RadianToDegree(radian float64) float64

RadianToDegree return degree for given rad

Types

type Border

type Border struct {
	Box
}

Border special type of Box. Collision will return true, if object out of border

func NewBorder

func NewBorder(r Box) Border

NewBorder return new border

func (Border) Collision

func (b Border) Collision(o Spatial, dimensions int) (bool, []float64)

Collision check collisions

func (Border) Get

func (b Border) Get() Spatial

Get return Spatial

type Box

type Box struct {
	Point
	// contains filtered or unexported fields
}

Box describe rectangle

func NewBox

func NewBox(p Point, s ...float64) Box

NewBox return new box

func (Box) BoundingBox

func (b Box) BoundingBox(r2 Box) Box

BoundingBox constructs the smallest rectangle containing both r1 and r2.

func (Box) Bounds

func (b Box) Bounds() Box

Bounds return rectangle of object

func (Box) Center

func (b Box) Center() Point

Center return center point

func (Box) Contains

func (b Box) Contains(v Point) bool

Contains returns whether the specified point is contained in this box.

func (Box) ContainsPoint

func (b Box) ContainsPoint(p Point) bool

ContainsPoint tests whether p is located inside or on the boundary of r

func (Box) ContainsRectangle

func (b Box) ContainsRectangle(r2 Box) bool

ContainsRectangle tests whether r2 is is located inside r1.

func (Box) Equal

func (b Box) Equal(r2 Box) bool

Equal returns true if the two rectangles are equal

func (Box) Fit

func (b Box) Fit(o Box) bool

Fit returns whether the specified area is fully contained in the other area.

func (Box) Get

func (b Box) Get() Spatial

Get return Spatial

func (Box) Intersect

func (b Box) Intersect(r2 Box) (Box, bool)

Intersect computes the intersection of two rectangles

func (Box) Margin

func (b Box) Margin() float64

Margin computes the sum of the edge lengths of a rectangle.

func (Box) Move

func (b Box) Move(diff Point) Spatial

Move return new object for given diff

func (Box) Point1

func (b Box) Point1() Point

Point1 return first point

func (Box) Point2

func (b Box) Point2() Point

Point2 return second point of rectangle

func (Box) Size

func (b Box) Size(i int) float64

Size return size by dimension

func (Box) Sizes

func (b Box) Sizes() [3]float64

Sizes return all sizes

func (Box) Split

func (b Box) Split() [8]Box

Split split box into 8 boxes

func (Box) Support

func (b Box) Support(d Point) Point

Support return support point for box

func (Box) ToPolygon

func (b Box) ToPolygon() Polyhedron

ToPolygon return polygon from box

func (Box) ToPolyhedron

func (b Box) ToPolyhedron() Polyhedron

ToPolyhedron return polyhedron from box

func (Box) VectorSizes

func (b Box) VectorSizes() Point

VectorSizes return all sizes as vector

func (Box) Volume

func (b Box) Volume() float64

Volume return size of rectangle

type Collide

type Collide interface {
	Spatial
	Support(d Point) Point
}

Collide describe collide interface

type Ellipsoid

type Ellipsoid struct {
	Point
	// contains filtered or unexported fields
}

Ellipsoid contains point and sizes

func NewEllipsoid

func NewEllipsoid(p Point, s ...float64) Ellipsoid

NewEllipsoid return new circle

func (Ellipsoid) Bounds

func (e Ellipsoid) Bounds() Box

Bounds return rectangle of object

func (Ellipsoid) Center

func (e Ellipsoid) Center() Point

Center return center point

func (Ellipsoid) Get

func (e Ellipsoid) Get() Spatial

Get return Spatial

func (Ellipsoid) Move

func (e Ellipsoid) Move(diff Point) Spatial

Move return new object for given diff

func (Ellipsoid) Point1

func (e Ellipsoid) Point1() Point

Point1 return center point

func (Ellipsoid) Size

func (e Ellipsoid) Size(i int) float64

Size return size by dimension

func (Ellipsoid) Sizes

func (e Ellipsoid) Sizes() [3]float64

Sizes return all sizes

func (Ellipsoid) Support

func (e Ellipsoid) Support(d Point) Point

Support return support point for sphere

type Line

type Line struct {
	Point
	// contains filtered or unexported fields
}

Line describe line

func NewLine

func NewLine(p Point, p2 Point) Line

NewLine return new line

func (Line) Bounds

func (l Line) Bounds() Box

Bounds return box of object

func (Line) Center

func (l Line) Center() Point

Center return center point

func (Line) Get

func (l Line) Get() Spatial

Get return Spatial

func (Line) Move

func (l Line) Move(diff Point) Spatial

Move return new object for given diff

func (Line) Point1

func (l Line) Point1() Point

Point1 return first point

func (Line) Point2

func (l Line) Point2() Point

Point2 return second point

func (Line) ProjectForPoint

func (l Line) ProjectForPoint(p Point) Point

ProjectForPoint project point on line

func (Line) Support

func (l Line) Support(d Point) Point

Support return support point for box

type MultiObject

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

MultiObject contains different object to describe another object

func NewMultiObject

func NewMultiObject(objects ...Spatial) MultiObject

NewMultiObject return new multi-object

func (MultiObject) Bounds

func (m MultiObject) Bounds() Box

Bounds return rectangle of object

func (MultiObject) Center

func (m MultiObject) Center() Point

Center return center point

func (MultiObject) Coordinates

func (m MultiObject) Coordinates() [3]float64

Coordinates return 3d coordinates

func (MultiObject) Count

func (m MultiObject) Count() int

Count return count of objects

func (MultiObject) Get

func (m MultiObject) Get() Spatial

Get return Spatial

func (MultiObject) Move

func (m MultiObject) Move(diff Point) Spatial

Move return new object for given diff

func (MultiObject) Object

func (m MultiObject) Object(i int) Spatial

Object return single object

func (MultiObject) Objects

func (m MultiObject) Objects() []Spatial

Objects return all objects

func (MultiObject) Point1

func (m MultiObject) Point1() Point

Point1 return point1

func (MultiObject) Support

func (m MultiObject) Support(d Point) Point

Support return support point

type Point

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

Point describe point

func CoordinatesToPoint

func CoordinatesToPoint(c [3]float64) Point

CoordinatesToPoint return point by coordinates

func GetDiffPoint2D

func GetDiffPoint2D(angle, velocity float64) Point

GetDiffPoint2D return diff point 2D

func NewPoint

func NewPoint(s ...float64) Point

NewPoint return new point

func RotateBy

func RotateBy(p Point, angle float64, which int) Point

RotateBy rotate by single coordinate

func RotatePoint

func RotatePoint(p Point, yaw, pitch, roll float64) Point

RotatePoint rotate point by roll, yaw and pitch

func (Point) Abs

func (p Point) Abs() Point

Abs abs the point

func (Point) Add

func (p Point) Add(diff Point) Point

Add add diff to p

func (Point) Bounds

func (p Point) Bounds() Box

Bounds return rectangle of object

func (Point) Center

func (p Point) Center() Point

Center return center point

func (Point) Coordinate

func (p Point) Coordinate(i int) float64

Coordinate return coordinate for dimension (0-x, 1-y, 2-z)

func (Point) Coordinates

func (p Point) Coordinates() [3]float64

Coordinates return all coordinates

func (Point) Copy

func (p Point) Copy() Point

Copy return copy point

func (Point) Cross

func (p Point) Cross(p2 Point) Point

Cross calculate cross

func (Point) Decrease

func (p Point) Decrease(v float64) Point

Decrease remove value from given point

func (Point) Distance

func (p Point) Distance(p2 Point) float64

Distance return distance between positions (euclidean)

func (Point) DistanceSquare

func (p Point) DistanceSquare(p2 Point) float64

DistanceSquare return distance square between positions (euclidean)

func (Point) Divide

func (p Point) Divide(diff Point) Point

Divide get divide point

func (Point) Dot

func (p Point) Dot(p2 Point) float64

Dot scalar multiply

func (Point) Equals

func (p Point) Equals(p2 Point) bool

Equals return true if points approximately equal

func (Point) Get

func (p Point) Get() Spatial

Get return Spatial

func (Point) GetMinAxis

func (p Point) GetMinAxis() int

GetMinAxis return the axis with the minimal value

func (Point) Increase

func (p Point) Increase(v float64) Point

Increase add value to given point

func (Point) Invert

func (p Point) Invert() Point

Invert invert the point

func (Point) IsEmpty

func (p Point) IsEmpty() bool

IsEmpty return true if this is zero point

func (Point) Lerp

func (p Point) Lerp(other Point, f float64) Point

Lerp Returns the linear interpolation between two Point(s)

func (Point) ManhattanDistance

func (p Point) ManhattanDistance(p2 Point) float64

ManhattanDistance return manhattan distance

func (Point) Max

func (p Point) Max(other Point) Point

Max Returns the a vector where each component is the greater of the corresponding component in this and the specified vector

func (Point) Min

func (p Point) Min(other Point) Point

Min Returns the a vector where each component is the lesser of the corresponding component in this and the specified vector

func (Point) MinDistance

func (p Point) MinDistance(r Box) float64

MinDistance computes the square of the distance from a point to a rectangle.

func (Point) MinMaxDistance

func (p Point) MinMaxDistance(r Box) float64

MinMaxDistance computes the minimum of the maximum distances from p to points on r.

func (Point) Move

func (p Point) Move(diff Point) Spatial

Move return new object for given diff

func (Point) Multiply

func (p Point) Multiply(diff Point) Point

Multiply get multiple point

func (Point) Normal

func (p Point) Normal() float64

Normal returns the vector's norm.

func (Point) NormalSquare

func (p Point) NormalSquare() float64

NormalSquare returns the vector's norm square.

func (Point) Normalize

func (p Point) Normalize() Point

Normalize normalize point

func (Point) Point1

func (p Point) Point1() Point

Point1 return point1 point

func (Point) Reflect

func (p Point) Reflect(normal Point) Point

Reflect reflection by normal

func (Point) Refract

func (p Point) Refract(normal Point, eta float64) Point

Refract refraction by normal and eta

func (Point) Round

func (p Point) Round(precision float64) Point

Round round all coordinate with precision

func (Point) Scale

func (p Point) Scale(v float64) Point

Scale multiply point on given point

func (Point) Subtract

func (p Point) Subtract(diff Point) Point

Subtract get diff between points

func (Point) Support

func (p Point) Support(_ Point) Point

Support return support point

type Polyhedron

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

Polyhedron describe polygon

func NewPolyhedron

func NewPolyhedron(vectors ...Point) Polyhedron

NewPolyhedron return new polygon

func (Polyhedron) Bounds

func (p Polyhedron) Bounds() Box

Bounds return rectangle of object

func (Polyhedron) Center

func (p Polyhedron) Center() Point

Center return center point

func (Polyhedron) Coordinates

func (p Polyhedron) Coordinates() [3]float64

Coordinates return 3d coordinates

func (Polyhedron) Count

func (p Polyhedron) Count() int

Count return count of objects

func (Polyhedron) Get

func (p Polyhedron) Get() Spatial

Get return Spatial

func (Polyhedron) Move

func (p Polyhedron) Move(diff Point) Spatial

Move return new object for given diff

func (Polyhedron) Point1

func (p Polyhedron) Point1() Point

Point1 return first point

func (Polyhedron) Support

func (p Polyhedron) Support(d Point) Point

Support return support point

func (Polyhedron) ToLines

func (p Polyhedron) ToLines() (line []Line)

ToLines return lines of polyhedron

func (Polyhedron) Vector

func (p Polyhedron) Vector(i int) Point

Vector return single point

func (Polyhedron) Vectors

func (p Polyhedron) Vectors() []Point

Vectors return all vectors

type Rotatable

type Rotatable struct {
	Spatial
	Angle float64
}

func NewRotatable

func NewRotatable(spatial Spatial, angle float64) Rotatable

func (*Rotatable) GetAngle

func (r *Rotatable) GetAngle() float64

type RotatableBox

type RotatableBox struct {
	Polyhedron
	// contains filtered or unexported fields
}

RotatableBox describe rotatable box

func NewRotatableBox

func NewRotatableBox(c Point, b Box, byX, byY, byZ float64) RotatableBox

NewRotatableBox return new rotatable box by x,y,z

func (RotatableBox) Bounds

func (b RotatableBox) Bounds() Box

Bounds return rectangle of object

func (RotatableBox) Center

func (b RotatableBox) Center() Point

Center return center point

func (RotatableBox) Get

func (b RotatableBox) Get() Spatial

Get return Spatial

func (RotatableBox) Move

func (b RotatableBox) Move(diff Point) Spatial

Move return new object for given diff

func (RotatableBox) Rotate

func (b RotatableBox) Rotate(c Point, byX, byY, byZ float64) RotatableBox

Rotate rotate box

func (RotatableBox) Size

func (b RotatableBox) Size(i int) float64

Size return size by dimension

func (RotatableBox) Sizes

func (b RotatableBox) Sizes() [3]float64

Sizes return all sizes

func (RotatableBox) Support

func (b RotatableBox) Support(d Point) Point

Support return support point for box

type Spatial

type Spatial interface {
	Point1() Point
	Coordinates() [3]float64
	Center() Point
	Get() Spatial
	Move(diff Point) Spatial
	Bounds() Box
}

Spatial describe boundable object

type Sphere

type Sphere struct {
	Point
	// contains filtered or unexported fields
}

Sphere contains point and radius

func NewSphere

func NewSphere(p Point, radius float64) Sphere

NewSphere return new circle

func (Sphere) Bounds

func (s Sphere) Bounds() Box

Bounds return rectangle of object

func (Sphere) Center

func (s Sphere) Center() Point

Center return center point

func (Sphere) CollisionSphere

func (s Sphere) CollisionSphere(s2 Sphere) bool

CollisionSphere return true if two spheres collided

func (Sphere) Get

func (s Sphere) Get() Spatial

Get return Spatial

func (Sphere) Move

func (s Sphere) Move(diff Point) Spatial

Move return new object for given diff

func (Sphere) Point1

func (s Sphere) Point1() Point

Point1 return center point

func (Sphere) Radius

func (s Sphere) Radius() float64

Radius return radius

func (Sphere) Support

func (s Sphere) Support(d Point) Point

Support return support point for sphere

type Triangle

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

Triangle describe triangle by 3 points

func NewTriangle

func NewTriangle(ps ...Point) Triangle

NewTriangle return new triangle

func (Triangle) Bounds

func (t Triangle) Bounds() Box

Bounds return rectangle of object

func (Triangle) CalculateSurfaceNormal

func (t Triangle) CalculateSurfaceNormal() Point

CalculateSurfaceNormal return triangle normal

func (Triangle) Center

func (t Triangle) Center() Point

Center return center point

func (Triangle) Coordinates

func (t Triangle) Coordinates() [3]float64

Coordinates return coordinate for dimension (0-x, 1-y, 2-z)

func (Triangle) Get

func (t Triangle) Get() Spatial

Get return Spatial

func (Triangle) Move

func (t Triangle) Move(diff Point) Spatial

Move return new object for given diff

func (Triangle) Point1

func (t Triangle) Point1() Point

Point1 return point

func (Triangle) Support

func (t Triangle) Support(d Point) Point

Support return support point for triangle

Jump to

Keyboard shortcuts

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