Documentation
¶
Index ¶
- Constants
- func AdjustAngle(angle float64) float64
- func Angle(a, b Vector) (float64, error)
- func AngleRadians(a, b Vector) (float64, error)
- func Approximate(shape Shape, moveDiff Vector, turnDiff float64, shapes Shapes, intensity int, ...) (Vector, float64, Shape, error)
- func CollisionCircleToCircle(a, b *Circle) (bool, error)
- func CollisionRectangleToCircle(rect *Rectangle, circle *Circle) (bool, error)
- func CollisionRectangleToRectangle(a, b *Rectangle) (bool, error)
- func Cross(a, b Vector) float64
- func Distance(a, b Vector) float64
- func Dot(a, b Vector) float64
- func IntersectionLineToCircle(line *Line, circle *Circle) (bool, error)
- func IntersectionLineToLine(a, b *Line) (bool, error)
- func IntersectionLineToRectangle(line *Line, rect *Rectangle) (bool, error)
- func LinesDistance(a, b *Line) (float64, error)
- func ResolveCollision(one, another Shape, useTags bool) (bool, error)
- func Sign(number float64) float64
- func SquaredDistance(a, b Vector) float64
- type Circle
- func (c *Circle) Angle() float64
- func (c *Circle) AngleRadians() float64
- func (c *Circle) Center() Vector
- func (c *Circle) ContainsPoint(point Vector) bool
- func (data *Circle) Data() interface{}
- func (t Circle) GetIdentity() int32
- func (t Circle) GetMask() int32
- func (c *Circle) Move(direction Vector) Vector
- func (circle *Circle) NormalTo(shape Shape) (Vector, error)
- func (circle *Circle) NormalToCircle(other *Circle) (Vector, error)
- func (circle *Circle) NormalToLine(line *Line) (Vector, error)
- func (circle *Circle) NormalToRectangle(rect *Rectangle) (Vector, error)
- func (c *Circle) Radius() float64
- func (c *Circle) Rotate(angle float64) float64
- func (c *Circle) RotateAround(angle float64, base Vector) Vector
- func (c *Circle) RotateAroundRadians(angle float64, base Vector) Vector
- func (c *Circle) RotateRadians(angle float64) float64
- func (c *Circle) SetAngle(angle float64) float64
- func (c *Circle) SetAngleRadians(angle float64) float64
- func (data *Circle) SetData(newData interface{})
- func (t *Circle) SetIdentity(newIdentity int32)
- func (t *Circle) SetMask(newMask int32)
- func (c *Circle) SetPosition(pos Vector) Vector
- func (t Circle) ShouldCollide(other Shape) (bool, error)
- func (c *Circle) TypeName() string
- type Line
- func (l *Line) Angle() float64
- func (l *Line) AngleRadians() float64
- func (l *Line) Center() Vector
- func (l *Line) CollinearTo(other *Line) (bool, error)
- func (l *Line) ContainsPoint(point Vector) bool
- func (data *Line) Data() interface{}
- func (l *Line) GetBoundingBox() (Vector, Vector)
- func (t Line) GetIdentity() int32
- func (t Line) GetMask() int32
- func (l *Line) Length() float64
- func (l *Line) Move(direction Vector) Vector
- func (line *Line) NormalTo(shape Shape) (Vector, error)
- func (line *Line) NormalToCircle(circle *Circle) (Vector, error)
- func (line *Line) NormalToLine(other *Line) (Vector, error)
- func (line *Line) NormalToRectangle(rect *Rectangle) (Vector, error)
- func (l *Line) Orientation(point Vector) int
- func (l *Line) P() Vector
- func (l *Line) ParallelTo(other *Line) (bool, error)
- func (l *Line) ProjectPoint(point Vector) Vector
- func (l *Line) Q() Vector
- func (l *Line) Rotate(angle float64) float64
- func (l *Line) RotateAround(angle float64, base Vector) Vector
- func (l *Line) RotateAroundRadians(angle float64, base Vector) Vector
- func (l *Line) RotateRadians(angle float64) float64
- func (l *Line) SameLineWith(other *Line) (bool, error)
- func (l *Line) SetAngle(angle float64) float64
- func (l *Line) SetAngleRadians(angle float64) float64
- func (data *Line) SetData(newData interface{})
- func (t *Line) SetIdentity(newIdentity int32)
- func (t *Line) SetMask(newMask int32)
- func (l *Line) SetPosition(pos Vector) Vector
- func (t Line) ShouldCollide(other Shape) (bool, error)
- func (l *Line) SquaredLength() float64
- func (l *Line) TypeName() string
- type Rectangle
- func (r *Rectangle) Angle() float64
- func (r *Rectangle) AngleRadians() float64
- func (r *Rectangle) Center() Vector
- func (r *Rectangle) ContainsPoint(point Vector) bool
- func (data *Rectangle) Data() interface{}
- func (t Rectangle) GetIdentity() int32
- func (t Rectangle) GetMask() int32
- func (r *Rectangle) Height() float64
- func (r *Rectangle) Max() Vector
- func (r *Rectangle) Min() Vector
- func (r *Rectangle) Move(direction Vector) Vector
- func (rect *Rectangle) NormalTo(shape Shape) (Vector, error)
- func (rect *Rectangle) NormalToCircle(circle *Circle) (Vector, error)
- func (rect *Rectangle) NormalToLine(line *Line) (Vector, error)
- func (rect *Rectangle) NormalToRectangle(other *Rectangle) (Vector, error)
- func (r *Rectangle) Rotate(angle float64) float64
- func (r *Rectangle) RotateAround(angle float64, base Vector) Vector
- func (r *Rectangle) RotateAroundRadians(angle float64, base Vector) Vector
- func (r *Rectangle) RotateRadians(angle float64) float64
- func (r *Rectangle) SetAngle(angle float64) float64
- func (r *Rectangle) SetAngleRadians(angle float64) float64
- func (data *Rectangle) SetData(newData interface{})
- func (t *Rectangle) SetIdentity(newIdentity int32)
- func (t *Rectangle) SetMask(newMask int32)
- func (r *Rectangle) SetPosition(pos Vector) Vector
- func (t Rectangle) ShouldCollide(other Shape) (bool, error)
- func (r *Rectangle) TypeName() string
- func (r *Rectangle) Vertices() [4]Vector
- func (r *Rectangle) Width() float64
- type Shape
- type Shapes
- func (shapes Shapes) Contains(shape Shape) (bool, error)
- func (shapes Shapes) Copy() Shapes
- func (shapes Shapes) FilterByCollision(shape Shape) (Shapes, error)
- func (shapes Shapes) FilterByCollisionLeft(shape Shape) (Shapes, error)
- func (shapes Shapes) FilterByCollisionRight(shape Shape) (Shapes, error)
- func (shapes Shapes) FilterByIdentity(identity int32) Shapes
- func (shapes Shapes) FilterByMask(mask int32) Shapes
- func (shapes Shapes) Insert(shapesToInsert ...Shape) error
- func (shapes Shapes) Items() []Shape
- func (shapes Shapes) Merge(otherShapes Shapes) error
- func (shapes Shapes) Remove(shape Shape) error
- type Space
- func (space *Space) Add(shapes ...Shape) error
- func (space *Space) AdjustShapePosition(shape Shape) error
- func (space *Space) Boxcast(rect *Rectangle) (Shapes, error)
- func (space *Space) Cells() map[*Rectangle]Shapes
- func (space *Space) Circlecast(circle *Circle) (Shapes, error)
- func (space *Space) Clear() error
- func (space *Space) CollidedBy(shape Shape) (Shapes, error)
- func (space *Space) CollidingShapes() (map[Shape]Shapes, error)
- func (space *Space) CollidingWith(shape Shape) (Shapes, error)
- func (space *Space) Contains(shape Shape) (bool, error)
- func (space *Space) InBounds(shape Shape) (bool, error)
- func (space *Space) Max() Vector
- func (space *Space) Min() Vector
- func (space *Space) Raycast(origin, direction Vector, distance float64, mask int32) (Shape, Vector, error)
- func (space *Space) Rebuild() error
- func (space *Space) Remove(shapes ...Shape) error
- func (space *Space) Shapes() Shapes
- func (space *Space) Update(shape Shape) (map[Vector]Shapes, error)
- func (space *Space) UseTags() bool
- func (space *Space) WouldBeCollidedBy(shape Shape, moveDiff Vector, turnDiff float64) (Shapes, error)
- func (space *Space) WouldBeCollidingWith(shape Shape, moveDiff Vector, turnDiff float64) (Shapes, error)
- type Vector
- func Contact(one, other Shape) ([]Vector, error)
- func ContactCircleToCircle(one, other *Circle) ([]Vector, error)
- func ContactLineToCircle(line *Line, circle *Circle) ([]Vector, error)
- func ContactLineToLine(one, other *Line) ([]Vector, error)
- func ContactLineToRectangle(line *Line, rect *Rectangle) ([]Vector, error)
- func ContactRectangleToCircle(rect *Rectangle, circle *Circle) ([]Vector, error)
- func ContactRectangleToRectangle(one, other *Rectangle) ([]Vector, error)
- func Down() Vector
- func Left() Vector
- func NewVector(x, y float64) Vector
- func Right() Vector
- func Up() Vector
- func Zero() Vector
- func (v Vector) Add(other Vector) Vector
- func (v Vector) ApproximatelyEqual(other Vector) bool
- func (v Vector) CollinearTo(other Vector) (bool, error)
- func (v Vector) Magnitude() float64
- func (v Vector) MultiplyBy(other Vector) Vector
- func (v Vector) MultiplyByScalar(scalar float64) Vector
- func (v Vector) Normalize() (Vector, error)
- func (v Vector) PerpendicularClockwise() Vector
- func (v Vector) PerpendicularCounterClockwise() Vector
- func (v Vector) Project(axis Vector) Vector
- func (v Vector) Rotate(angle float64) Vector
- func (v Vector) RotateAround(angle float64, base Vector) Vector
- func (v Vector) RotateAroundRadians(angle float64, base Vector) Vector
- func (v Vector) RotateRadians(angle float64) Vector
- func (v Vector) SquaredMagnitude() float64
- func (v Vector) Subtract(other Vector) Vector
Constants ¶
const ( // RadToDeg is a factor to transfrom radians to degrees. RadToDeg float64 = 180.0 / math.Pi // DegToRad is a factor to transform degrees to radians. DegToRad float64 = math.Pi / 180.0 // Epsilon is the constant for approximate comparisons. Epsilon float64 = 0.000001 // CollinearityThreshold is the constant to detect if two vectors // are effectively collinear. CollinearityThreshold float64 = 10.0 )
Variables ¶
This section is empty.
Functions ¶
func AdjustAngle ¶
AdjustAngle adjusts the value of the angle so it is bettween 0 and 360.
func AngleRadians ¶
AngleRadians returns the angle between two vectors (in radians).
func Approximate ¶
func Approximate(shape Shape, moveDiff Vector, turnDiff float64, shapes Shapes, intensity int, useTags bool) (Vector, float64, Shape, error)
Approximate attempts to move the shape in the specified direction to detect the closest point until the shape collides other shapes.
func CollisionCircleToCircle ¶
CollisionCircleToCircle detects if there's an intersection between two circles.
func CollisionRectangleToCircle ¶
CollisionRectangleToCircle detects if there's an intersection between an oriented rectangle and a circle.
func CollisionRectangleToRectangle ¶
CollisionRectangleToRectangle detects if there is an intersection between two oriented rectangles.
func IntersectionLineToCircle ¶
IntersectionLineToCircle detects if a line and a circle do intersect.
func IntersectionLineToLine ¶
IntersectionLineToLine detects if two lines intersect.
func IntersectionLineToRectangle ¶
IntersectionLineToRectangle detects if there's an intersection between a line and a rectangle.
func LinesDistance ¶
LinesDistance returns the shortest distance between two lines.
func ResolveCollision ¶
ResolveCollision assumes types of the given shapes and detects if they collide.
func SquaredDistance ¶
SquaredDistance returns the value of distance in the power of 2 between two points represented as vectors.
Types ¶
type Circle ¶
type Circle struct {
// contains filtered or unexported fields
}
Circle represents a geometric euclidian circle.
func (*Circle) Angle ¶
Angle doesn't return any valuable data because there is no sense to rotate the circle.
This method is added just to match the Shape interface.
func (*Circle) AngleRadians ¶
AngleRadians doesn't return any valuable data because there is no sense to rotate the circle.
This method is added just to match the Shape interface.
func (*Circle) ContainsPoint ¶
ContainsPoint detects if the given point is inside the circle.
func (*Circle) Data ¶
func (data *Circle) Data() interface{}
Data returns whatever is saved in the data field of the shape.
func (Circle) GetIdentity ¶
func (t Circle) GetIdentity() int32
GetIdentity returns the valye of the shape identity.
func (*Circle) NormalToCircle ¶
NormalToCircle returns the normal from the given circle to the other circle.
func (*Circle) NormalToLine ¶
NormalToLine returns the normal from the given circle to the line.
func (*Circle) NormalToRectangle ¶
NormalToRectangle returns the normal from the given circle to the rectangle.
func (*Circle) Rotate ¶
Rotate does nothing to the circle because there is no sense to rotate it.
This method is added just to match the Shape interface.
func (*Circle) RotateAround ¶
RotateAround rotates the circle around the specified point changing the circle's position.
func (*Circle) RotateAroundRadians ¶
RotateAroundRadians rotates the circle around the base point at the specified angle in radians.
func (*Circle) RotateRadians ¶
RotateRadians does nothing to the circle because there is no sense to rotate it.
This method is added just to match the Shape interface.
func (*Circle) SetAngle ¶
SetAngle does nothing to the circle because there is no sense to rotate it.
This method is added just to match the Shape interface.
func (*Circle) SetAngleRadians ¶
SetAngleRadians does nothing to the circle because there is no sense to rotate it.
This method is added just to match the Shape interface.
func (*Circle) SetData ¶
func (data *Circle) SetData(newData interface{})
SetData assigns new data to the shape.
func (*Circle) SetIdentity ¶
func (t *Circle) SetIdentity(newIdentity int32)
SetIdentity assigns a new value to the tag identity.
func (*Circle) SetMask ¶
func (t *Circle) SetMask(newMask int32)
SetMask assigns a new value to the tag mask.
func (*Circle) SetPosition ¶
SetPosition sets the circle position to the given coordinates.
func (Circle) ShouldCollide ¶
ShouldCollide returns true if the shape should collide another one accodring to their tags.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line represents a geometric euclidian line segment from p to q.
func (*Line) AngleRadians ¶
AngleRadians returns the rotation angle of the line (un radians).
func (*Line) CollinearTo ¶
CollinearTo returns true if the lines are collinear, and false otherwise.
func (*Line) ContainsPoint ¶
ContainsPoint detects if the point lies on the line.
func (*Line) Data ¶
func (data *Line) Data() interface{}
Data returns whatever is saved in the data field of the shape.
func (*Line) GetBoundingBox ¶
GetBoundingBox returns the bounding box for the line.
func (Line) GetIdentity ¶
func (t Line) GetIdentity() int32
GetIdentity returns the valye of the shape identity.
func (*Line) NormalToCircle ¶
NormalToCircle returns the normal from the given line to the circle.
func (*Line) NormalToLine ¶
NormalToLine returns the normal from the given line to the other line.
func (*Line) NormalToRectangle ¶
NormalToRectangle returns the normal from the given line to the rectangle.
func (*Line) Orientation ¶
Orientation returns 0 if the point is collinear to the line, 1 if orientation is clockwise, -1 if orientation is counter-clockwise.
func (*Line) ParallelTo ¶
ParallelTo checks if two line segments are collinear but don't lie on the same line.
func (*Line) ProjectPoint ¶
ProjectPoint returns the projection of the point onto the line.
func (*Line) Rotate ¶
Rotate rotates the line at the specified angle (in degrees).
Returns the rotation angle of the line (in degrees).
func (*Line) RotateAround ¶
RotateAround rotates the line around the base point.
func (*Line) RotateAroundRadians ¶
RotateAroundRadians rotates the line around the base point at the angle in radians.
func (*Line) RotateRadians ¶
RotateRadians rotates the line at the specified angle (in radians).
Returns the rotation angle of the line (in radians).
func (*Line) SameLineWith ¶
SameLineWith returns true if two line segments lie on the same line.
func (*Line) SetAngle ¶
SetAngle sets the rotation angle of the line to the specified value (in degrees).
func (*Line) SetAngleRadians ¶
SetAngleRadians sets the rotation angle of the line to the specified value (in radians).
func (*Line) SetData ¶
func (data *Line) SetData(newData interface{})
SetData assigns new data to the shape.
func (*Line) SetIdentity ¶
func (t *Line) SetIdentity(newIdentity int32)
SetIdentity assigns a new value to the tag identity.
func (*Line) SetMask ¶
func (t *Line) SetMask(newMask int32)
SetMask assigns a new value to the tag mask.
func (*Line) SetPosition ¶
SetPosition sets the position of the line to the given coordinates.
func (Line) ShouldCollide ¶
ShouldCollide returns true if the shape should collide another one accodring to their tags.
func (*Line) SquaredLength ¶
SquaredLength returns the length of the line in the power of 2.
type Rectangle ¶
type Rectangle struct {
// contains filtered or unexported fields
}
Rectangle represents an oriented euclidian rectangle.
func NewRectangle ¶
NewRectangle returns a new rectangle with specified parameters.
func (*Rectangle) AngleRadians ¶
AngleRadians returns the angle of the rectangle (in radians).
func (*Rectangle) ContainsPoint ¶
ContainsPoint detects if the given point is inside the rectangle.
func (*Rectangle) Data ¶
func (data *Rectangle) Data() interface{}
Data returns whatever is saved in the data field of the shape.
func (Rectangle) GetIdentity ¶
func (t Rectangle) GetIdentity() int32
GetIdentity returns the valye of the shape identity.
func (*Rectangle) Move ¶
Move moves the rectangle in the specified direction; returns its new position.
func (*Rectangle) NormalTo ¶
NormalTo returns the normal from the given rectangle to the other shape.
func (*Rectangle) NormalToCircle ¶
NormalToCircle returns the normal from the given rectangle to the circle.
func (*Rectangle) NormalToLine ¶
NormalToLine returns the normal between the given rectangle and the line.
func (*Rectangle) NormalToRectangle ¶
NormalToRectangle returns the normal from the given rectangle to the other rectangle.
func (*Rectangle) Rotate ¶
Rotate rotates the whole rectangle at the specified angle (in degrees).
Returns the new angle of the rectangle (in degrees).
func (*Rectangle) RotateAround ¶
RotateAround rotates the rectangle around the specified base point.
func (*Rectangle) RotateAroundRadians ¶
RotateAroundRadians rotates the rectangle around the specified base point at the angle in radians.
func (*Rectangle) RotateRadians ¶
RotateRadians rotates the whole rectangle at the specified angle (in radians).
Returns the new angle of the rectangle (in radians).
func (*Rectangle) SetAngle ¶
SetAngle sets the angle of the rectangle to the given value (in degrees).
func (*Rectangle) SetAngleRadians ¶
SetAngleRadians sets the angle of the rectangle to the given value (in radians).
func (*Rectangle) SetData ¶
func (data *Rectangle) SetData(newData interface{})
SetData assigns new data to the shape.
func (*Rectangle) SetIdentity ¶
func (t *Rectangle) SetIdentity(newIdentity int32)
SetIdentity assigns a new value to the tag identity.
func (*Rectangle) SetMask ¶
func (t *Rectangle) SetMask(newMask int32)
SetMask assigns a new value to the tag mask.
func (*Rectangle) SetPosition ¶
SetPosition sets the position of the rectangle to the given coordinates.
func (Rectangle) ShouldCollide ¶
ShouldCollide returns true if the shape should collide another one accodring to their tags.
type Shape ¶
type Shape interface { // Common methods. TypeName() string Center() Vector Angle() float64 AngleRadians() float64 Move(Vector) Vector Rotate(float64) float64 RotateRadians(float64) float64 RotateAround(float64, Vector) Vector RotateAroundRadians(float64, Vector) Vector SetPosition(Vector) Vector SetAngle(float64) float64 SetAngleRadians(float64) float64 ContainsPoint(Vector) bool NormalTo(Shape) (Vector, error) // Tag-related methods. GetIdentity() int32 SetIdentity(int32) GetMask() int32 SetMask(int32) ShouldCollide(Shape) (bool, error) // Data-related methods. Data() interface{} SetData(data interface{}) // contains filtered or unexported methods }
Shape represents a shape in the space.
type Shapes ¶
type Shapes map[Shape]none
Shapes represents a list of shapes.
func (Shapes) FilterByCollision ¶
FilterByCollision returns all the shapes that should collide or get collided by the given shape.
func (Shapes) FilterByCollisionLeft ¶
FilterByCollisionLeft returns all the shapes that should collide the given shape.
func (Shapes) FilterByCollisionRight ¶
FilterByCollisionRight returns all the shapes the given shape should collide.
func (Shapes) FilterByIdentity ¶
FilterByIdentity returns all the shapes matching the specified identity template.
func (Shapes) FilterByMask ¶
FilterByMask returns all the shapes matching the specified mask template.
type Space ¶
type Space struct {
// contains filtered or unexported fields
}
Space represents a geometric space with shapes within it.
func NewSpace ¶
func NewSpace( subdivisionFactor, shapesInArea int, width, height float64, min, max Vector, useTags bool, ) ( *Space, error, )
NewSpace creates a new empty space with the given parameters.
func (*Space) AdjustShapePosition ¶
AdjustShapePosition changes the position of the shape if it's out of bounds.
func (*Space) Boxcast ¶
Boxcast casts a box in the space and returns all the shapes overlapped by this box.
func (*Space) Circlecast ¶
Circlecast casts a circle in the space and returns all the shapes overlapped by the circle.
func (*Space) CollidedBy ¶
CollidedBy returns the set of shapes collided by the given shape.
func (*Space) CollidingShapes ¶
CollidingShapes returns the dictionary where key is a shape and value is the set of shapes colliding with the key shape.
func (*Space) CollidingWith ¶
CollidingWith returns the set of shapes colliding with the given shape.
func (*Space) Contains ¶
Contains returns true if the shape is within the space, and false otherwise.
func (*Space) Raycast ¶
func (space *Space) Raycast(origin, direction Vector, distance float64, mask int32) (Shape, Vector, error)
Raycast casts a ray in the space and returns the hit shape closest to the origin of the ray.
Ray cannot hit against the shape within which it's located.
type Vector ¶
Vector represents a 2-dimensional vector.
func ContactCircleToCircle ¶
ContactCircleToCircle returns the contact point between two circles (if it exists).
func ContactLineToCircle ¶
ContactLineToCircle returns the contact points between the line and the circle (if they exist).
func ContactLineToLine ¶
ContactLineToLine returns the contact point between two lines (if it exists).
func ContactLineToRectangle ¶
ContactLineToRectangle returns the contacts between the line and the rectangle (if they exist).
func ContactRectangleToCircle ¶
ContactRectangleToCircle returns the contacts between the rectangle and the circle (if they exist).
func ContactRectangleToRectangle ¶
ContactRectangleToRectangle returns the contacts between two rectangles (if they exist).
func (Vector) ApproximatelyEqual ¶
ApproximatelyEqual returns true if the vector is approximately equal to the other one, and false otherwise.
func (Vector) CollinearTo ¶
CollinearTo indicates if the given vector is collinear to the other vector.
func (Vector) MultiplyBy ¶
MultiplyBy multiplies components of the first vector by the components of the other vector.
func (Vector) MultiplyByScalar ¶
MultiplyByScalar returns the vector multiplied by the specified scalar.
func (Vector) PerpendicularClockwise ¶
PerpendicularClockwise returns a new vector perpendicular to the given one and turned in a clockwise direction relatively to it.
func (Vector) PerpendicularCounterClockwise ¶
PerpendicularCounterClockwise returns a new vector perpendicular to the given one and turned in a clockwise direction relatively to it.
func (Vector) RotateAround ¶
RotateAround returns the vector rotated at an angle of n degrees around the base vector.
func (Vector) RotateAroundRadians ¶
RotateAroundRadians returns the vector totated at an angle of n radians around the base vector.
func (Vector) RotateRadians ¶
RotateRadians returns the vector totated at an angle of n radians.
func (Vector) SquaredMagnitude ¶
SquaredMagnitude returns the vectors's magnitude in the power of 2.