shape

package
v0.0.0-...-e7bc4dc Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Static temporary rectangle. Use with care! Use only when sure other code will not also use self.
	Tmp = NewRectangleEmpty()

	// Static temporary rectangle. Use with care! Use only when sure other code will not also use self.
	Tmp2 = NewRectangleEmpty()
)

Functions

This section is empty.

Types

type Circle

type Circle struct {
	X, Y, Radius float32
}

A convenient 2D circle class. Implements Shape2D

func NewCircle

func NewCircle(x, y, radius float32) *Circle

Constructs a new circle with the given X and Y coordinates and the given radius.

func NewCircleC

func NewCircleC(c *Circle) *Circle

Copy constructor circle The circle to construct a copy of.

func NewCircleEmpty

func NewCircleEmpty() *Circle

Constructs a new circle with all values set to zero

func NewCircleV

func NewCircleV(position *Vector2, radius float32) *Circle

Constructs a new circle using a given {@link Vector2} that contains the desired X and Y coordinates, and a given radius. position The position {@link Vector2}. radius The radius

func NewCircleV2

func NewCircleV2(center, edge *Vector2) *Circle

Creates a new {@link Circle} in terms of its center and a point on its edge. center The center of the new circle edge Any point on the edge of the given circle

func (*Circle) Area

func (self *Circle) Area() float32

The area of this circle (as {@link MathUtils#PI} * radius * radius).

func (*Circle) Circumference

func (self *Circle) Circumference() float32

The circumference of this circle (as 2 * {@link MathUtils#PI2}) * {@code radius}

func (*Circle) Contains

func (self *Circle) Contains(x, y float32) bool

Checks whether or not this circle contains a given point. x X coordinate y Y coordinate true if this circle contains the given point.

func (*Circle) ContainsC

func (self *Circle) ContainsC(c *Circle) bool

c the other {@link Circle} whether this circle contains the other circle.

func (*Circle) ContainsV

func (self *Circle) ContainsV(point *Vector2) bool

Checks whether or not this circle contains a given point. point The {@link Vector2} that contains the point coordinates. true if this circle contains this point; false otherwise.

func (*Circle) Overlaps

func (self *Circle) Overlaps(c *Circle) bool

// c the other {@link Circle} // whether this circle overlaps the other circle.

func (*Circle) Set

func (self *Circle) Set(x, y, radius float32)

Sets a new location and radius for this circle.

func (*Circle) SetC

func (self *Circle) SetC(circle *Circle)

Sets a new location and radius for this circle, based upon another circle. circle The circle to copy the position and radius of.

func (*Circle) SetPosition

func (self *Circle) SetPosition(position *Vector2)

Sets the x and y-coordinates of circle center from vector position The position vector

func (*Circle) SetRadius

func (self *Circle) SetRadius(radius float32)

Sets the radius of circle radius The radius

func (*Circle) SetV

func (self *Circle) SetV(position *Vector2, radius float32)

Sets a new location and radius for this circle.

func (*Circle) SetV2

func (self *Circle) SetV2(center, edge *Vector2)

Sets this {@link Circle}'s values in terms of its center and a point on its edge. center The new center of the circle edge Any point on the edge of the given circle

func (*Circle) String

func (self *Circle) String() string

Returns a {@link String} representation of this {@link Circle} of the form {@code x,y,radius}.

type Ellipse

type Ellipse struct {
	X, Y, W, H float32
}

A convenient 2D ellipse class, based on the circle class Implements Shape2D

func NewEllipse

func NewEllipse(x, y, w, h float32) *Ellipse

Constructs a new ellipse param x X coordinate param y Y coordinate param width Width in pixels param height Height in pixels

func NewEllipseCircle

func NewEllipseCircle(circle *Circle) *Ellipse

Constructs a new {@link Ellipse} from the position and radius of a {@link Circle} (since circles are special cases of ellipses). param circle The circle to take the values of

func NewEllipseCopy

func NewEllipseCopy(ellipse *Ellipse) *Ellipse

Copy constructor param ellipse Ellipse to construct a copy of.

func NewEllipseEmpty

func NewEllipseEmpty() *Ellipse

Construct a new ellipse with all values set to zero

func NewEllipseV

func NewEllipseV(position *Vector2, w, h float32) *Ellipse

Costructs a new ellipse param position Position vector param width Width in pixels param height Height in pixels

func NewEllipseV2

func NewEllipseV2(position, size *Vector2) *Ellipse

func (*Ellipse) Area

func (self *Ellipse) Area() float32

return The area of this {@link Ellipse} as {@link MathUtils#PI} * {@link Ellipse#width} * {@link Ellipse#height}

func (*Ellipse) Circumference

func (self *Ellipse) Circumference() float32

Approximates the circumference of this {@link Ellipse}. Oddly enough, the circumference of an ellipse is actually difficult to compute exactly. return The Ramanujan approximation to the circumference of an ellipse if one dimension is at least three times longer than the other, else the simpler approximation

func (*Ellipse) Contains

func (self *Ellipse) Contains(x, y float32) bool

Checks whether or not this ellipse contains the given point. param x X coordinate param y Y coordinate return true if this ellipse contains the given point; false otherwise.

func (*Ellipse) ContainsV

func (self *Ellipse) ContainsV(point *Vector2) bool

Checks whether or not this ellipse contains the given point. param point Position vector return true if this ellipse contains the given point; false otherwise.

func (*Ellipse) Set

func (self *Ellipse) Set(x, y, w, h float32)

Sets a new position and size for this ellipse. param x X coordinate param y Y coordinate param width Width in pixels param height Height in pixels

func (*Ellipse) SetCircle

func (self *Ellipse) SetCircle(circle *Circle)

func (*Ellipse) SetCopy

func (self *Ellipse) SetCopy(ellipse *Ellipse)

Sets a new position and size for this ellipse based upon another ellipse. param ellipse The ellipse to copy the position and size of.

func (*Ellipse) SetPosition

func (self *Ellipse) SetPosition(x, y float32) *Ellipse

Sets the x and y-coordinates of ellipse center param x The x-coordinate param y The y-coordinate return this ellipse for chaining

func (*Ellipse) SetPositionV

func (self *Ellipse) SetPositionV(position *Vector2) *Ellipse

Sets the x and y-coordinates of ellipse center from a {@link Vector2}. param position The position vector return this ellipse for chaining

func (*Ellipse) SetSize

func (self *Ellipse) SetSize(w, h float32) *Ellipse

Sets the width and height of this ellipse param width The width param height The height return this ellipse for chaining

func (*Ellipse) SetV2

func (self *Ellipse) SetV2(position, size *Vector2)

type Polygon

type Polygon struct {
	X, Y             float32
	OriginX, OriginY float32
	Rotation         float32
	ScaleX, ScaleY   float32
	// contains filtered or unexported fields
}

Encapsulates a 2D polygon defined by it's vertices relative to an origin point (default of 0, 0).

func NewPolygon

func NewPolygon(vertices []float32) *Polygon

Constructs a new polygon from a float array of parts of vertex points. @param vertices an array where every even element represents the horizontal part of a point, and the following element

representing the vertical part

panics if less than 6 elements, representing 3 points, are provided

func NewPolygonEmpty

func NewPolygonEmpty() *Polygon

Constructs a new polygon with no vertices

func (*Polygon) Area

func (self *Polygon) Area() float32

Returns the area contained within the polygon.

func (*Polygon) Contains

func (self *Polygon) Contains(x, y float32) bool

Returns whether an x, y pair is contained within the polygon.

func (*Polygon) Dirty

func (self *Polygon) Dirty()

Sets the polygon's world vertices to be recalculated when calling {@link #getTransformedVertices() getTransformedVertices}.

func (*Polygon) GetBoundingRectangle

func (self *Polygon) GetBoundingRectangle() *Rectangle

Returns an axis-aligned bounding box of this polygon. Note the returned Rectangle is cached in this polygon, and will be reused if this Polygon is changed. @return this polygon's bounding box {@link Rectangle}

func (*Polygon) GetTransformedVertices

func (self *Polygon) GetTransformedVertices() []float32

Calculates and returns the vertices of the polygon after scaling, rotation, and positional translations have been applied, as they are position within the world.

@return vertices scaled, rotated, and offset by the polygon position.

func (*Polygon) GetVertices

func (self *Polygon) GetVertices() []float32

Returns the polygon's local vertices without scaling or rotation and without being offset by the polygon position.

func (*Polygon) Rotate

func (self *Polygon) Rotate(degrees float32)

Applies additional rotation to the polygon by the supplied degrees.

func (*Polygon) Scale

func (self *Polygon) Scale(amount float32)

Applies additional scaling to the polygon by the supplied amount.

func (*Polygon) SetPosition

func (self *Polygon) SetPosition(x, y float32)

Sets the polygon's position within the world.

func (*Polygon) SetRotation

func (self *Polygon) SetRotation(degrees float32)

Sets the polygon to be rotated by the supplied degrees.

func (*Polygon) SetScale

func (self *Polygon) SetScale(scaleX, scaleY float32)

Sets the amount of scaling to be applied to the polygon.

func (*Polygon) SetVertices

func (self *Polygon) SetVertices(vertices []float32)

Sets the polygon's local vertices relative to the origin point, without any scaling, rotating or translations being applied.

@param vertices float array where every even element represents the x-coordinate of a vertex, and the proceeding element representing the y-coordinate. panics if less than 6 elements, representing 3 points, are provided

func (*Polygon) Translate

func (self *Polygon) Translate(x, y float32)

Translates the polygon's position by the specified horizontal and vertical amounts.

type Polyline

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

func NewPolygonLine

func NewPolygonLine(vertices []float32) *Polyline

func NewPolygonLineEmpty

func NewPolygonLineEmpty() *Polyline

func (*Polyline) CalculateLength

func (self *Polyline) CalculateLength()

func (*Polyline) CalculateScaledLength

func (self *Polyline) CalculateScaledLength()

func (*Polyline) Dirty

func (self *Polyline) Dirty()

func (*Polyline) GetLength

func (self *Polyline) GetLength() float32

Returns the euclidean length of the polyline without scaling

func (*Polyline) GetOriginX

func (self *Polyline) GetOriginX() float32

func (*Polyline) GetOriginY

func (self *Polyline) GetOriginY() float32

func (*Polyline) GetRotation

func (self *Polyline) GetRotation() float32

func (*Polyline) GetScaleX

func (self *Polyline) GetScaleX() float32

func (*Polyline) GetScaleY

func (self *Polyline) GetScaleY() float32

func (*Polyline) GetScaledLength

func (self *Polyline) GetScaledLength() float32

Returns the euclidean length of the polyline

func (*Polyline) GetTransformedVertices

func (self *Polyline) GetTransformedVertices() []float32

Returns vertices scaled, rotated, and offset by the polyline position.

func (*Polyline) GetVertices

func (self *Polyline) GetVertices() []float32

Returns vertices without scaling or rotation and without being offset by the polyline position.

func (*Polyline) GetX

func (self *Polyline) GetX() float32

func (*Polyline) GetY

func (self *Polyline) GetY() float32

func (*Polyline) Rotate

func (self *Polyline) Rotate(degrees float32)

Applies additional rotation to the polyline by the supplied degrees.

func (*Polyline) Scale

func (self *Polyline) Scale(amount float32)

Applies additional scaling to the polyline by the supplied amount.

func (*Polyline) SetPosition

func (self *Polyline) SetPosition(x, y float32)

Sets the polyline's position within the world.

func (*Polyline) SetRotation

func (self *Polyline) SetRotation(degrees float32)

Sets the polyline to be rotated by the supplied degrees.

func (*Polyline) SetScale

func (self *Polyline) SetScale(scaleX, scaleY float32)

Sets the amount of scaling to be applied to the polyline.

func (*Polyline) SetVertices

func (self *Polyline) SetVertices(vertices []float32)

Sets the polyline's local vertices relative to the origin point, without any scaling, rotating or translations being applied.

@param vertices float array where every even element represents the x-coordinate of a vertex, and the proceeding element representing the y-coordinate. panics if less than 6 elements, representing 3 points, are provided

func (*Polyline) Translate

func (self *Polyline) Translate(x, y float32)

Translates the polyline's position by the specified horizontal and vertical amounts.

type Rectangle

type Rectangle struct {
	X, Y, W, H float32
}

Encapsulates a 2D rectangle defined by its corner point in the bottom left and its extents in x (width) and y (height). Implements Shape2D

func NewRectangle

func NewRectangle(x, y, w, h float32) *Rectangle

Constructs a new rectangle with the given corner point in the bottom left and dimensions.

func NewRectangleCopy

func NewRectangleCopy(rect *Rectangle) *Rectangle

Constructs a rectangle based on the given rectangle

func NewRectangleEmpty

func NewRectangleEmpty() *Rectangle

Constructs a new rectangle with all values set to zero

func (*Rectangle) Area

func (self *Rectangle) Area() float32

func (*Rectangle) Contains

func (self *Rectangle) Contains(x, y float32) bool

returns whether the point is contained in the rectangle

func (*Rectangle) ContainsRect

func (self *Rectangle) ContainsRect(r *Rectangle) bool

returns whether the other rectangle is contained in this rectangle.

func (*Rectangle) ContainsV

func (self *Rectangle) ContainsV(point *Vector2) bool

returns whether the point is contained in the rectangle

func (*Rectangle) Equals

func (self *Rectangle) Equals(rect *Rectangle) bool

func (*Rectangle) FitInside

func (self *Rectangle) FitInside(rect *Rectangle) *Rectangle

Fits this rectangle into another rectangle while maintaining aspect ratio. This scales and centers the rectangle to the other rectangle (e.g. Scaling a texture within a arbitrary cell without squeezing) param rect the other rectangle to fit this rectangle inside returns this rectangle for chaining

func (*Rectangle) FitOutside

func (self *Rectangle) FitOutside(rect *Rectangle) *Rectangle

Fits this rectangle around another rectangle while maintaining aspect ratio. This scales and centers the rectangle to the other rectangle (e.g. Having a camera translate and scale to show a given area) param rect the other rectangle to fit this rectangle around returns this rectangle for chaining

func (*Rectangle) GetAspectRatio

func (self *Rectangle) GetAspectRatio() float32

Calculates the aspect ratio ( width / height ) of this rectangle returns the aspect ratio of this rectangle. Returns Float.NaN if height is 0 to avoid ArithmeticException

func (*Rectangle) GetCenter

func (self *Rectangle) GetCenter(vector *Vector2) *Vector2

Calculates the center of the rectangle. Results are located in the given Vector2 returns the given vector with results stored inside

func (*Rectangle) GetH

func (self *Rectangle) GetH() float32

returns the height

func (*Rectangle) GetPosition

func (self *Rectangle) GetPosition(position *Vector2) *Vector2

return the Vector2 with coordinates of this rectangle

func (*Rectangle) GetSize

func (self *Rectangle) GetSize(size *Vector2) *Vector2

returns the Vector2 with size of this rectangle

func (*Rectangle) GetW

func (self *Rectangle) GetW() float32

returns the width

func (*Rectangle) GetX

func (self *Rectangle) GetX() float32

returns the x-coordinate of the bottom left corner

func (*Rectangle) GetY

func (self *Rectangle) GetY() float32

returns the y-coordinate of the bottom left corner

func (*Rectangle) HashCode

func (self *Rectangle) HashCode() int

func (*Rectangle) Merge

func (self *Rectangle) Merge(x, y float32) *Rectangle

Merges this rectangle with a point. The rectangle should not have negative width or negative height.

func (*Rectangle) MergeRect

func (self *Rectangle) MergeRect(rect *Rectangle) *Rectangle

Merges this rectangle with the other rectangle. The rectangle should not have negative width or negative height.

func (*Rectangle) MergeVec

func (self *Rectangle) MergeVec(vec *Vector2) *Rectangle

Merges this rectangle with a point. The rectangle should not have negative width or negative height.

func (*Rectangle) MergeVecs

func (self *Rectangle) MergeVecs(vecs []*Vector2) *Rectangle

Merges this rectangle with a list of points. The rectangle should not have negative width or negative height.

func (*Rectangle) Overlaps

func (self *Rectangle) Overlaps(r *Rectangle) bool

returns whether this rectangle overlaps the other rectangle.

func (*Rectangle) Perimeter

func (self *Rectangle) Perimeter() float32

func (*Rectangle) Set

func (self *Rectangle) Set(x, y, w, h float32) *Rectangle

func (*Rectangle) SetCenter

func (self *Rectangle) SetCenter(x, y float32) *Rectangle

Moves this rectangle so that its center point is located at a given position returns this for chaining

func (*Rectangle) SetCenterV

func (self *Rectangle) SetCenterV(position *Vector2) *Rectangle

Moves this rectangle so that its center point is located at a given position returns this for chaining

func (*Rectangle) SetH

func (self *Rectangle) SetH(h float32) *Rectangle

Sets the height of this rectangle

func (*Rectangle) SetPosition

func (self *Rectangle) SetPosition(x, y float32) *Rectangle

Sets the x and y-coordinates of the bottom left corner

func (*Rectangle) SetPositionV

func (self *Rectangle) SetPositionV(position *Vector2) *Rectangle

Sets the x and y-coordinates of the bottom left corner from vector

func (*Rectangle) SetR

func (self *Rectangle) SetR(rect *Rectangle) *Rectangle

Sets the values of the given rectangle to this rectangle.

func (*Rectangle) SetSize

func (self *Rectangle) SetSize(width, height float32) *Rectangle

Sets the width and height of this rectangle

func (*Rectangle) SetSizeXY

func (self *Rectangle) SetSizeXY(sizeXY float32) *Rectangle

Sets the squared size of this rectangle

func (*Rectangle) SetW

func (self *Rectangle) SetW(w float32) *Rectangle

Sets the width of this rectangle

func (*Rectangle) SetX

func (self *Rectangle) SetX(x float32) *Rectangle

Sets the x-coordinate of the bottom left corner param x The x-coordinate returns this rectangle for chaining

func (*Rectangle) SetY

func (self *Rectangle) SetY(y float32) *Rectangle

Sets the y-coordinate of the bottom left corner param y The y-coordinate returns this rectangle for chaining

func (*Rectangle) String

func (self *Rectangle) String() string

type Shape2D

type Shape2D interface {
}

Jump to

Keyboard shortcuts

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