Skip to main content
Version: Phaser v4.0.0

Phaser.Geom.Circle

Area

<static> Area(circle)

Description:

Calculates the area of the circle.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to get the area of.

Returns: number - The area of the Circle.

Source: src/geom/circle/Area.js#L7
Since: 3.0.0

Circumference

<static> Circumference(circle)

Description:

Returns the circumference of the given Circle.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to get the circumference of.

Returns: number - The circumference of the Circle.

Source: src/geom/circle/Circumference.js#L7
Since: 3.0.0

CircumferencePoint

<static> CircumferencePoint(circle, angle, [out])

Description:

Returns a Vector2 object containing the coordinates of a point on the circumference of the Circle based on the given angle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to get the circumference point on.
anglenumberNoThe angle from the center of the Circle to the circumference to return the point from. Given in radians.
outPhaser.Math.Vector2YesA Vector2 to store the results in. If not given a Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object where the x and y properties are the point on the circumference.

Source: src/geom/circle/CircumferencePoint.js#L9
Since: 3.0.0

Clone

<static> Clone(source)

Description:

Creates a new Circle instance based on the values contained in the given source.

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.Circle | objectNoThe Circle to be cloned. Can be an instance of a Circle or a circle-like object, with x, y and radius properties.

Returns: Phaser.Geom.Circle - A clone of the source Circle.

Source: src/geom/circle/Clone.js#L9
Since: 3.0.0

Contains

<static> Contains(circle, x, y)

Description:

Check to see if the Circle contains the given x / y coordinates.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to check.
xnumberNoThe x coordinate to check within the circle.
ynumberNoThe y coordinate to check within the circle.

Returns: boolean - True if the coordinates are within the circle, otherwise false.

Source: src/geom/circle/Contains.js#L7
Since: 3.0.0

ContainsPoint

<static> ContainsPoint(circle, vec)

Description:

Check to see if the Circle contains the given x and y coordinates as stored in the Vector2.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to check.
vecPhaser.Math.Vector2NoThe Vector2 object to check if its coordinates are within the Circle or not.

Returns: boolean - True if the Vector2 coordinates are within the circle, otherwise false.

Source: src/geom/circle/ContainsPoint.js#L9
Since: 3.0.0

ContainsRect

<static> ContainsRect(circle, rect)

Description:

Check to see if the Circle contains all four points of the given Rectangle object.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to check.
rectPhaser.Geom.Rectangle | objectNoThe Rectangle object to check if it's within the Circle or not.

Returns: boolean - True if all of the Rectangle coordinates are within the circle, otherwise false.

Source: src/geom/circle/ContainsRect.js#L9
Since: 3.0.0

CopyFrom

<static> CopyFrom(source, dest)

Description:

Copies the x, y and radius properties from the source Circle into the given dest Circle, then returns the dest Circle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.CircleNoThe source Circle to copy the values from.
destPhaser.Geom.CircleNoThe destination Circle to copy the values to.

Returns: Phaser.Geom.Circle - The destination Circle.

Source: src/geom/circle/CopyFrom.js#L7
Since: 3.0.0

Equals

<static> Equals(circle, toCompare)

Description:

Compares the x, y and radius properties of the two given Circles. Returns true if they all match, otherwise returns false.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe first Circle to compare.
toComparePhaser.Geom.CircleNoThe second Circle to compare.

Returns: boolean - true if the two Circles equal each other, otherwise false.

Source: src/geom/circle/Equals.js#L7
Since: 3.0.0

GetBounds

<static> GetBounds(circle, [out])

Description:

Returns the bounds of the Circle object.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to get the bounds from.
outPhaser.Geom.Rectangle | objectYesA Rectangle, or rectangle-like object, to store the circle bounds in. If not given a new Rectangle will be created.

Returns: Phaser.Geom.Rectangle, object - The Rectangle object containing the Circle's bounds.

Source: src/geom/circle/GetBounds.js#L9
Since: 3.0.0

GetPoint

<static> GetPoint(circle, position, [out])

Description:

Returns a Vector2 object containing the coordinates of a point on the circumference of the Circle based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point at 180 degrees around the circle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to get the circumference point on.
positionnumberNoA value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle.
outPhaser.Math.Vector2YesA Vector2 instance to store the return values in. If not given a new Vector2 object will be created.

Returns: Phaser.Math.Vector2 - A Vector2 containing the coordinates of the point around the circle.

Source: src/geom/circle/GetPoint.js#L12
Since: 3.0.0

GetPoints

<static> GetPoints(circle, quantity, [stepRate], [out])

Description:

Returns an array of Vector2 objects containing the coordinates of the points around the circumference of the Circle, based on the given quantity or stepRate values.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to get the points from.
quantitynumberNoThe amount of points to return. If a falsy value the quantity will be derived from the stepRate instead.
stepRatenumberYesSets the quantity by getting the circumference of the circle and dividing it by the stepRate.
outarrayYesAn array to insert the points in to. If not provided a new array will be created.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 objects pertaining to the points around the circumference of the circle.

Source: src/geom/circle/GetPoints.js#L12
Since: 3.0.0

Offset

<static> Offset(circle, x, y)

Description:

Offsets the Circle by the values given.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to be offset (translated.)
xnumberNoThe amount to horizontally offset the Circle by.
ynumberNoThe amount to vertically offset the Circle by.

Returns: Phaser.Geom.Circle - The Circle that was offset.

Source: src/geom/circle/Offset.js#L7
Since: 3.0.0

OffsetPoint

<static> OffsetPoint(circle, vec)

Description:

Offsets the Circle by the values given in the x and y properties of the Vector2 object.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to be offset (translated.)
vecPhaser.Math.Vector2NoThe Vector2 object containing the values to offset the Circle by.

Returns: Phaser.Geom.Circle - The Circle that was offset.

Source: src/geom/circle/OffsetPoint.js#L7
Since: 3.0.0

Random

<static> Random(circle, [out])

Description:

Returns a uniformly distributed random point from anywhere within the given Circle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe Circle to get a random point from.
outPhaser.Math.Vector2YesA Vector2 object to set the random x and y values in.

Returns: Phaser.Math.Vector2 - A Vector2 object with the random values set in the x and y properties.

Source: src/geom/circle/Random.js#L9
Since: 3.0.0

Phaser.Geom.Ellipse

Area

<static> Area(ellipse)

Description:

Calculates the area of the given Ellipse using the formula: π × majorRadius × minorRadius. Returns 0 if the Ellipse is empty (i.e. has no width or height).

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the area of.

Returns: number - The area of the Ellipse, or 0 if the Ellipse is empty.

Source: src/geom/ellipse/Area.js#L7
Since: 3.0.0

Circumference

<static> Circumference(ellipse)

Description:

Returns the circumference of the given Ellipse.

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the circumference of.

Returns: number - The circumference of the Ellipse.

Source: src/geom/ellipse/Circumference.js#L7
Since: 3.0.0

CircumferencePoint

<static> CircumferencePoint(ellipse, angle, [out])

Description:

Returns a Vector2 containing the coordinates of a point on the circumference of the Ellipse based on the given angle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the circumference point on.
anglenumberNoThe angle from the center of the Ellipse to the circumference to return the point from. Given in radians.
outPhaser.Math.Vector2YesA Vector2 to store the results in. If not given a Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object where the x and y properties are the point on the circumference.

Source: src/geom/ellipse/CircumferencePoint.js#L9
Since: 3.0.0

Clone

<static> Clone(source)

Description:

Creates a new Ellipse instance based on the values contained in the given source.

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.EllipseNoThe Ellipse to be cloned. Can be an instance of an Ellipse or an ellipse-like object, with x, y, width and height properties.

Returns: Phaser.Geom.Ellipse - A clone of the source Ellipse.

Source: src/geom/ellipse/Clone.js#L9
Since: 3.0.0

Contains

<static> Contains(ellipse, x, y)

Description:

Check to see if the Ellipse contains the given x / y coordinates.

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to check.
xnumberNoThe x coordinate to check within the ellipse.
ynumberNoThe y coordinate to check within the ellipse.

Returns: boolean - True if the coordinates are within the ellipse, otherwise false.

Source: src/geom/ellipse/Contains.js#L7
Since: 3.0.0

ContainsPoint

<static> ContainsPoint(ellipse, vec)

Description:

Check to see if the Ellipse contains the given x and y coordinates as stored in the Vector2.

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to check.
vecPhaser.Math.Vector2NoThe Vector2 object to check if its coordinates are within the Ellipse or not.

Returns: boolean - True if the Vector2 coordinates are within the ellipse, otherwise false.

Source: src/geom/ellipse/ContainsPoint.js#L9
Since: 3.0.0

ContainsRect

<static> ContainsRect(ellipse, rect)

Description:

Check to see if the Ellipse contains all four points of the given Rectangle object.

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to check.
rectPhaser.Geom.Rectangle | objectNoThe Rectangle object to check if it's within the Ellipse or not.

Returns: boolean - True if all of the Rectangle coordinates are within the ellipse, otherwise false.

Source: src/geom/ellipse/ContainsRect.js#L9
Since: 3.0.0

CopyFrom

<static> CopyFrom(source, dest)

Description:

Copies the x, y, width and height properties from the source Ellipse into the given dest Ellipse, then returns the dest Ellipse.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.EllipseNoThe source Ellipse to copy the values from.
destPhaser.Geom.EllipseNoThe destination Ellipse to copy the values to.

Returns: Phaser.Geom.Ellipse - The destination Ellipse.

Source: src/geom/ellipse/CopyFrom.js#L7
Since: 3.0.0

Equals

<static> Equals(ellipse, toCompare)

Description:

Compares the x, y, width and height properties of the two given Ellipses. Returns true if they all match, otherwise returns false.

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe first Ellipse to compare.
toComparePhaser.Geom.EllipseNoThe second Ellipse to compare.

Returns: boolean - true if the two Ellipse equal each other, otherwise false.

Source: src/geom/ellipse/Equals.js#L7
Since: 3.0.0

GetBounds

<static> GetBounds(ellipse, [out])

Description:

Returns the bounds of the Ellipse object.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the bounds from.
outPhaser.Geom.Rectangle | objectYesA Rectangle, or rectangle-like object, to store the ellipse bounds in. If not given a new Rectangle will be created.

Returns: Phaser.Geom.Rectangle, object - The Rectangle object containing the Ellipse bounds.

Source: src/geom/ellipse/GetBounds.js#L9
Since: 3.0.0

GetPoint

<static> GetPoint(ellipse, position, [out])

Description:

Returns a Vector2 object containing the coordinates of a point on the circumference of the Ellipse based on the given angle normalized to the range 0 to 1. i.e. a value of 0.5 will give the point at 180 degrees around the ellipse.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the circumference point on.
positionnumberNoA value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 degrees around the ellipse.
outPhaser.Math.Vector2YesA Vector2 object to store the return values in. If not given a new Vector2 object will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object, containing the coordinates of the point around the ellipse.

Source: src/geom/ellipse/GetPoint.js#L12
Since: 3.0.0

GetPoints

<static> GetPoints(ellipse, quantity, [stepRate], [out])

Description:

Returns an array of Vector2 objects containing the coordinates of the points around the circumference of the Ellipse, based on the given quantity or stepRate values.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the points from.
quantitynumberNoThe amount of points to return. If a falsy value the quantity will be derived from the stepRate instead.
stepRatenumberYesSets the quantity by getting the circumference of the ellipse and dividing it by the stepRate.
outArray.<Phaser.Math.Vector2>YesAn array to insert the Vector2 objects into. If not provided a new array will be created.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 objects pertaining to the points around the circumference of the ellipse.

Source: src/geom/ellipse/GetPoints.js#L12
Since: 3.0.0

Offset

<static> Offset(ellipse, x, y)

Description:

Offsets the Ellipse by the values given.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to be offset (translated).
xnumberNoThe amount to horizontally offset the Ellipse by.
ynumberNoThe amount to vertically offset the Ellipse by.

Returns: Phaser.Geom.Ellipse - The Ellipse that was offset.

Source: src/geom/ellipse/Offset.js#L7
Since: 3.0.0

OffsetPoint

<static> OffsetPoint(ellipse, vec)

Description:

Offsets the Ellipse by the values given in the x and y properties of the Vector2 object.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to be offset (translated.)
vecPhaser.Math.Vector2NoThe Vector2 object containing the values to offset the Ellipse by.

Returns: Phaser.Geom.Ellipse - The Ellipse that was offset.

Source: src/geom/ellipse/OffsetPoint.js#L7
Since: 3.0.0

Random

<static> Random(ellipse, [out])

Description:

Returns a uniformly distributed random point from anywhere within the given Ellipse.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get a random point from.
outPhaser.Math.Vector2YesA Vector2 object to set the random x and y values in.

Returns: Phaser.Math.Vector2 - A Vector2 object with the random values set in the x and y properties.

Source: src/geom/ellipse/Random.js#L9
Since: 3.0.0

Phaser.Geom.Intersects

CircleToCircle

<static> CircleToCircle(circleA, circleB)

Description:

Checks if two Circles intersect.

Parameters:

nametypeoptionaldescription
circleAPhaser.Geom.CircleNoThe first Circle to check for intersection.
circleBPhaser.Geom.CircleNoThe second Circle to check for intersection.

Returns: boolean - true if the two Circles intersect, otherwise false.

Source: src/geom/intersects/CircleToCircle.js#L9
Since: 3.0.0

CircleToRectangle

<static> CircleToRectangle(circle, rect)

Description:

Checks for intersection between a circle and a rectangle.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe circle to be checked.
rectPhaser.Geom.RectangleNoThe rectangle to be checked.

Returns: boolean - true if the two objects intersect, otherwise false.

Source: src/geom/intersects/CircleToRectangle.js#L7
Since: 3.0.0

GetCircleToCircle

<static> GetCircleToCircle(circleA, circleB, [out])

Description:

Checks if two Circles intersect and returns the intersection points as a Point object array.

Parameters:

nametypeoptionaldescription
circleAPhaser.Geom.CircleNoThe first Circle to check for intersection.
circleBPhaser.Geom.CircleNoThe second Circle to check for intersection.
outArray.<Phaser.Math.Vector2>YesAn optional array of Vector2 objects in which to store the points of intersection.

Returns: Array.<Phaser.Math.Vector2> - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetCircleToCircle.js#L11
Since: 3.0.0

GetCircleToRectangle

<static> GetCircleToRectangle(circle, rect, [out])

Description:

Checks for intersection between a circle and a rectangle, and returns the intersection points as an array of Point objects. If the shapes do not intersect, an empty array is returned. If they do intersect, each of the rectangle's four edges is tested against the circle and any intersection points found are added to the output array.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe circle to be checked.
rectPhaser.Geom.RectangleNoThe rectangle to be checked.
outarrayYesAn optional array in which to store the points of intersection.

Returns: array - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetCircleToRectangle.js#L11
Since: 3.0.0

GetLineToCircle

<static> GetLineToCircle(line, circle, [out])

Description:

Checks for intersection between the line segment and circle, and returns the intersection points as a Vector2 object array.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line segment to check.
circlePhaser.Geom.CircleNoThe circle to check against the line.
outArray.<Phaser.Math.Vector2>YesAn optional array of Vector2 objects in which to store the points of intersection.

Returns: Array.<Phaser.Math.Vector2> - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetLineToCircle.js#L11
Since: 3.0.0

GetLineToLine

<static> GetLineToLine(line1, line2, [isRay], [out])

Description:

Checks for intersection between the two line segments, or a ray and a line segment, and returns the intersection point as a Vector3, or null if the lines are parallel, or do not intersect.

The z property of the Vector3 contains the parametric t value (a scalar between 0 and 1) representing how far along line1 the intersection occurs. This can be used to sort or compare multiple intersection results to find the closest intersecting point from a group of line segments.

Parameters:

nametypeoptionaldefaultdescription
line1Phaser.Geom.LineNoThe first line segment, or a ray, to check.
line2Phaser.Geom.LineNoThe second line segment to check.
isRaybooleanYesfalseIs line1 a ray or a line segment?
outPhaser.Math.Vector3YesA Vector3 to store the intersection results in.

Returns: Phaser.Math.Vector3 - A Vector3 where x and y are the intersection point coordinates and z is the parametric t value along line1, or null if the lines do not intersect.

Source: src/geom/intersects/GetLineToLine.js#L9
Since: 3.50.0

GetLineToPoints

<static> GetLineToPoints(line, points, [isRay], [out])

Description:

Checks for the closest point of intersection between a line segment and an array of points, where each consecutive pair of points is converted to a line segment for the intersection tests. The array is treated as a closed shape, meaning the last point is connected back to the first point.

If no intersection is found, this function returns null.

If intersection was found, a Vector3 is returned with the following properties:

The x and y components contain the point of the intersection. The z component contains the closest distance.

Parameters:

nametypeoptionaldefaultdescription
linePhaser.Geom.LineNoThe line segment, or ray, to check. If a ray, set the isRay parameter to true.
pointsArray.<Phaser.Math.Vector2> | Array.<Phaser.Math.Vector2>NoAn array of points to check.
isRaybooleanYesfalseIs line a ray or a line segment?
outPhaser.Math.Vector3YesA Vector3 to store the intersection results in.

Returns: Phaser.Math.Vector3 - A Vector3 containing the intersection results, or null.

Source: src/geom/intersects/GetLineToPoints.js#L17
Since: 3.50.0

GetLineToPolygon

<static> GetLineToPolygon(line, polygons, [isRay], [out])

Description:

Checks for the closest point of intersection between a line segment and an array of polygons.

If no intersection is found, this function returns null.

If intersection was found, a Vector4 is returned with the following properties:

The x and y components contain the point of the intersection. The z component contains the closest distance. The w component contains the index of the polygon, in the given array, that triggered the intersection.

Parameters:

nametypeoptionaldefaultdescription
linePhaser.Geom.LineNoThe line segment, or ray, to check. If a ray, set the isRay parameter to true.
polygonsPhaser.Geom.Polygon | Array.<Phaser.Geom.Polygon>NoA single polygon, or array of polygons, to check.
isRaybooleanYesfalseIs line a ray or a line segment?
outPhaser.Math.Vector4YesA Vector4 to store the intersection results in.

Returns: Phaser.Math.Vector4 - A Vector4 containing the intersection results, or null.

Source: src/geom/intersects/GetLineToPolygon.js#L14
Since: 3.50.0

GetLineToRectangle

<static> GetLineToRectangle(line, rect, [out])

Description:

Checks for intersection between the Line and a Rectangle shape, and returns the intersection points as a Vector2 array.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe Line to check for intersection.
rectPhaser.Geom.RectangleNoThe Rectangle to check for intersection.
outArray.<Phaser.Math.Vector2>YesAn optional array of Vector2 objects in which to store the points of intersection.

Returns: Array.<Phaser.Math.Vector2> - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetLineToRectangle.js#L12
Since: 3.0.0

GetRaysFromPointToPolygon

<static> GetRaysFromPointToPolygon(x, y, polygons)

Description:

Projects rays out from the given point to each vertex of the polygons.

If the rays intersect with the polygons, the points of intersection are returned in an array.

If no intersections are found, the returned array will be empty.

Each Vector4 intersection result has the following properties:

The x and y components contain the point of the intersection. The z component contains the angle of the projected ray, in radians. The w component contains the index of the polygon, in the given array, that triggered the intersection.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate to project the rays from.
ynumberNoThe y coordinate to project the rays from.
polygonsPhaser.Geom.Polygon | Array.<Phaser.Geom.Polygon>NoA single polygon, or array of polygons, to check against the rays.

Returns: Array.<Phaser.Math.Vector4> - An array containing all intersections in Vector4s.

Source: src/geom/intersects/GetRaysFromPointToPolygon.js#L40
Since: 3.50.0

GetRectangleIntersection

<static> GetRectangleIntersection(rectA, rectB, [output])

Description:

Checks if two Rectangle shapes intersect and returns the area of this intersection as Rectangle object.

If optional output parameter is omitted, new Rectangle object is created and returned. If there is intersection, it will contain intersection area. If there is no intersection, it will be empty Rectangle (all values set to zero).

If Rectangle object is passed as output and there is intersection, then intersection area data will be loaded into it and it will be returned. If there is no intersection, it will be returned without any change.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle object.
rectBPhaser.Geom.RectangleNoThe second Rectangle object.
outputPhaser.Geom.RectangleYesOptional Rectangle object. If given, the intersection data will be loaded into it (in case of no intersection, it will be left unchanged). Otherwise, new Rectangle object will be created and returned with either intersection data or empty (all values set to zero), if there is no intersection.

Returns: Phaser.Geom.Rectangle - A rectangle object with intersection data.

Source: src/geom/intersects/GetRectangleIntersection.js#L10
Since: 3.0.0

GetRectangleToRectangle

<static> GetRectangleToRectangle(rectA, rectB, [out])

Description:

Checks if two Rectangles intersect and returns the intersection points as a Point object array.

A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. As such, the two Rectangles are considered "solid". A Rectangle with no width or no height will never intersect another Rectangle.

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to check for intersection.
rectBPhaser.Geom.RectangleNoThe second Rectangle to check for intersection.
outarrayYesAn optional array in which to store the points of intersection.

Returns: array - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetRectangleToRectangle.js#L11
Since: 3.0.0

GetRectangleToTriangle

<static> GetRectangleToTriangle(rect, triangle, [out])

Description:

Checks for intersection between Rectangle shape and Triangle shape, and returns the intersection points as a Point object array.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoRectangle object to test.
trianglePhaser.Geom.TriangleNoTriangle object to test.
outarrayYesAn optional array in which to store the points of intersection.

Returns: array - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetRectangleToTriangle.js#L11
Since: 3.0.0

GetTriangleToCircle

<static> GetTriangleToCircle(triangle, circle, [out])

Description:

Checks if a Triangle and a Circle intersect, and returns the intersection points as a Point object array.

A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to check for intersection.
circlePhaser.Geom.CircleNoThe Circle to check for intersection.
outarrayYesAn optional array in which to store the points of intersection.

Returns: array - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetTriangleToCircle.js#L11
Since: 3.0.0

GetTriangleToLine

<static> GetTriangleToLine(triangle, line, [out])

Description:

Checks if a Triangle and a Line intersect, and returns the intersection points as a Point object array.

The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid".

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to check with.
linePhaser.Geom.LineNoThe Line to check with.
outArray.<Phaser.Math.Vector2>YesAn optional array of Vector2 objects in which to store the points of intersection.

Returns: Array.<Phaser.Math.Vector2> - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetTriangleToLine.js#L12
Since: 3.0.0

GetTriangleToTriangle

<static> GetTriangleToTriangle(triangleA, triangleB, [out])

Description:

Checks if two Triangles intersect, and returns the intersection points as a Point object array.

A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid".

Parameters:

nametypeoptionaldescription
triangleAPhaser.Geom.TriangleNoThe first Triangle to check for intersection.
triangleBPhaser.Geom.TriangleNoThe second Triangle to check for intersection.
outarrayYesAn optional array in which to store the points of intersection.

Returns: array - An array with the points of intersection if objects intersect, otherwise an empty array.

Source: src/geom/intersects/GetTriangleToTriangle.js#L11
Since: 3.0.0

LineToCircle

<static> LineToCircle(line, circle, [nearest])

Description:

Checks for intersection between the line segment and circle.

Based on code by Matt DesLauriers.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line segment to check.
circlePhaser.Geom.CircleNoThe circle to check against the line.
nearestPhaser.Math.Vector2YesAn optional Vector2 object. If given the closest point on the Line where the circle intersects will be stored in this object.

Returns: boolean - true if the two objects intersect, otherwise false.

Source: src/geom/intersects/LineToCircle.js#L12
Since: 3.0.0

LineToLine

<static> LineToLine(line1, line2, [out])

Description:

Checks if two Lines intersect. If the Lines are identical, they will be treated as parallel and thus non-intersecting.

Parameters:

nametypeoptionaldescription
line1Phaser.Geom.LineNoThe first Line to check.
line2Phaser.Geom.LineNoThe second Line to check.
outPhaser.Types.Math.Vector2LikeYesAn optional point-like object in which to store the coordinates of intersection, if needed.

Returns: boolean - true if the two Lines intersect, and the out object will be populated, if given. Otherwise, false.

Source: src/geom/intersects/LineToLine.js#L10
Since: 3.0.0

LineToRectangle

<static> LineToRectangle(line, rect)

Description:

Checks for intersection between the Line and a Rectangle shape, or a rectangle-like object, with public x, y, right and bottom properties, such as a Sprite or Body.

An intersection is considered valid if:

The line starts within, or ends within, the Rectangle. The line segment intersects one of the 4 rectangle edges.

For the purposes of this function rectangles are considered 'solid'.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe Line to check for intersection.
rectPhaser.Geom.Rectangle | objectNoThe Rectangle to check for intersection.

Returns: boolean - true if the Line and the Rectangle intersect, false otherwise.

Source: src/geom/intersects/LineToRectangle.js#L7
Since: 3.0.0

PointToLine

<static> PointToLine(point, line, [lineThickness])

Description:

Checks if a Point falls between the two end-points of a Line, based on the given line thickness.

Assumes that the line end points are circular, not square.

Parameters:

nametypeoptionaldefaultdescription
pointPhaser.Math.Vector2 | anyNoThe point, or point-like object to check.
linePhaser.Geom.LineNoThe line segment to test for intersection on.
lineThicknessnumberYes1The line thickness. Assumes that the line end points are circular.

Returns: boolean - true if the Point falls on the Line, otherwise false.

Source: src/geom/intersects/PointToLine.js#L8
Since: 3.0.0

PointToLineSegment

<static> PointToLineSegment(point, line)

Description:

Checks if a Point is located on the given line segment.

Parameters:

nametypeoptionaldescription
pointPhaser.Math.Vector2NoThe Point to check for intersection.
linePhaser.Geom.LineNoThe line segment to check for intersection.

Returns: boolean - true if the Point is on the given line segment, otherwise false.

Source: src/geom/intersects/PointToLineSegment.js#L9
Since: 3.0.0

RectangleToRectangle

<static> RectangleToRectangle(rectA, rectB)

Description:

Checks if two Rectangles intersect.

A Rectangle intersects another Rectangle if any part of its bounds is within the other Rectangle's bounds. As such, the two Rectangles are considered "solid". A Rectangle with no width or no height will never intersect another Rectangle.

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to check for intersection.
rectBPhaser.Geom.RectangleNoThe second Rectangle to check for intersection.

Returns: boolean - true if the two Rectangles intersect, otherwise false.

Source: src/geom/intersects/RectangleToRectangle.js#L7
Since: 3.0.0

RectangleToTriangle

<static> RectangleToTriangle(rect, triangle)

Description:

Checks for intersection between a Rectangle and a Triangle shape.

The test is performed in multiple stages of increasing cost. First, the bounding boxes of the two shapes are compared for a quick early-out. If they overlap, the test checks whether any triangle vertex lies inside the rectangle, then whether any edge of the triangle intersects any edge of the rectangle, and finally whether any corner of the rectangle lies inside the triangle.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to test.
trianglePhaser.Geom.TriangleNoThe Triangle to test.

Returns: boolean - A value of true if objects intersect; otherwise false.

Source: src/geom/intersects/RectangleToTriangle.js#L12
Since: 3.0.0

RectangleToValues

<static> RectangleToValues(rect, left, right, top, bottom, [tolerance])

Description:

Checks if a Rectangle intersects with a region defined by explicit left, right, top, and bottom boundary values.

Parameters:

nametypeoptionaldefaultdescription
rectPhaser.Geom.RectangleNoThe Rectangle to check for intersection.
leftnumberNoThe x coordinate of the left edge of the region to check against.
rightnumberNoThe x coordinate of the right edge of the region to check against.
topnumberNoThe y coordinate of the top edge of the region to check against.
bottomnumberNoThe y coordinate of the bottom edge of the region to check against.
tolerancenumberYes0Tolerance allowed in the calculation, expressed in pixels.

Returns: boolean - Returns true if there is an intersection.

Source: src/geom/intersects/RectangleToValues.js#L7
Since: 3.0.0

TriangleToCircle

<static> TriangleToCircle(triangle, circle)

Description:

Checks if a Triangle and a Circle intersect.

A Circle intersects a Triangle if its center is located within it or if any of the Triangle's sides intersect the Circle. As such, the Triangle and the Circle are considered "solid" for the intersection.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to check for intersection.
circlePhaser.Geom.CircleNoThe Circle to check for intersection.

Returns: boolean - true if the Triangle and the Circle intersect, otherwise false.

Source: src/geom/intersects/TriangleToCircle.js#L10
Since: 3.0.0

TriangleToLine

<static> TriangleToLine(triangle, line)

Description:

Checks if a Triangle and a Line intersect.

The Line intersects the Triangle if it starts inside of it, ends inside of it, or crosses any of the Triangle's sides. Thus, the Triangle is considered "solid".

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to check with.
linePhaser.Geom.LineNoThe Line to check with.

Returns: boolean - true if the Triangle and the Line intersect, otherwise false.

Source: src/geom/intersects/TriangleToLine.js#L9
Since: 3.0.0

TriangleToTriangle

<static> TriangleToTriangle(triangleA, triangleB)

Description:

Checks if two Triangles intersect.

A Triangle intersects another Triangle if any pair of their lines intersects or if any point of one Triangle is within the other Triangle. Thus, the Triangles are considered "solid".

Parameters:

nametypeoptionaldescription
triangleAPhaser.Geom.TriangleNoThe first Triangle to check for intersection.
triangleBPhaser.Geom.TriangleNoThe second Triangle to check for intersection.

Returns: boolean - true if the Triangles intersect, otherwise false.

Source: src/geom/intersects/TriangleToTriangle.js#L11
Since: 3.0.0

Phaser.Geom.Line

Angle

<static> Angle(line)

Description:

Calculate the angle of the line in radians.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the angle of.

Returns: number - The angle of the line, in radians.

Source: src/geom/line/Angle.js#L7
Since: 3.0.0

BresenhamPoints

<static> BresenhamPoints(line, [stepRate], [results])

Description:

Using Bresenham's line algorithm this will return an array of all coordinates on the given line.

The start and end points are rounded before this runs as the algorithm works on integers.

Parameters:

nametypeoptionaldefaultdescription
linePhaser.Geom.LineNoThe line.
stepRatenumberYes1Controls how densely the points are sampled along the line. A value of 1 returns every integer coordinate; a value of 2 returns every other coordinate, and so on.
resultsArray.<Phaser.Types.Math.Vector2Like>YesAn optional array to push the resulting coordinates into.

Returns: Array.<Phaser.Types.Math.Vector2Like> - The array of coordinates on the line.

Source: src/geom/line/BresenhamPoints.js#L7
Since: 3.0.0

CenterOn

<static> CenterOn(line, x, y)

Description:

Center a line on the given coordinates.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to center.
xnumberNoThe horizontal coordinate to center the line on.
ynumberNoThe vertical coordinate to center the line on.

Returns: Phaser.Geom.Line - The centered line.

Source: src/geom/line/CenterOn.js#L8
Since: 3.0.0

Clone

<static> Clone(source)

Description:

Clone the given line.

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.LineNoThe source line to clone.

Returns: Phaser.Geom.Line - The cloned line.

Source: src/geom/line/Clone.js#L9
Since: 3.0.0

CopyFrom

<static> CopyFrom(source, dest)

Description:

Copy the values of one line to a destination line.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.LineNoThe source line to copy the values from.
destPhaser.Geom.LineNoThe destination line to copy the values to.

Returns: Phaser.Geom.Line - The destination line.

Source: src/geom/line/CopyFrom.js#L7
Since: 3.0.0

Equals

<static> Equals(line, toCompare)

Description:

Compares two lines for strict equality. Two lines are considered equal if their start and end point coordinates all match exactly: x1, y1, x2, and y2.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe first line to compare.
toComparePhaser.Geom.LineNoThe second line to compare.

Returns: boolean - true if the two lines have identical start and end point coordinates, otherwise false.

Source: src/geom/line/Equals.js#L7
Since: 3.0.0

Extend

<static> Extend(line, left, [right])

Description:

Extends the start and end points of a Line by the given amounts.

The amounts can be positive or negative. Positive values will increase the length of the line, while negative ones will decrease it.

If no right value is provided it will extend the length of the line equally in both directions.

Pass a value of zero to leave the start or end point unchanged.

The left value extends outward from the start point (x1, y1) along the line's direction, and the right value extends outward from the end point (x2, y2).

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line instance to extend.
leftnumberNoThe amount to extend the start of the line by.
rightnumberYesThe amount to extend the end of the line by. If not given it will be set to the left value.

Returns: Phaser.Geom.Line - The modified Line instance.

Source: src/geom/line/Extend.js#L9
Since: 3.16.0

GetEasedPoints

<static> GetEasedPoints(line, ease, quantity, [collinearThreshold], [easeParams])

Description:

Returns an array of quantity Points where each point is taken from the given Line, spaced out according to the ease function specified.


const line = new Phaser.Geom.Line(100, 300, 700, 300);

const points = Phaser.Geom.Line.GetEasedPoints(line, 'sine.out', 32)

In the above example, the points array will contain 32 points spread-out across the length of line, where the position of each point is determined by the Sine.out ease function.

You can optionally provide a collinear threshold. In this case, the resulting points are checked against each other, and if they are < collinearThreshold distance apart, they are dropped from the results. This can help avoid lots of clustered points at far ends of the line with tightly-packed eases such as Quartic. Leave the value set to zero to skip this check.

Note that if you provide a collinear threshold, the resulting array may not always contain quantity points.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
linePhaser.Geom.LineNoThe Line object.
easestring | functionNoThe ease to use. This can be either a string from the EaseMap, or a custom function.
quantitynumberNoThe number of points to return. Note that if you provide a collinearThreshold, the resulting array may not always contain this number of points.
collinearThresholdnumberYes0An optional threshold. The final array is reduced so that each point is spaced out at least this distance apart. This helps reduce clustering in noisy eases.
easeParamsArray.<number>YesAn optional array of ease parameters to go with the ease.

Returns: Array.<Phaser.Math.Vector2> - An array of Math.Vector2s containing the coordinates of the points on the line.

Source: src/geom/line/GetEasedPoints.js#L11
Since: 3.23.0

GetMidPoint

<static> GetMidPoint(line, [out])

Description:

Get the midpoint of the given line.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to get the midpoint of.
outPhaser.Math.Vector2YesAn optional Vector2 object to store the midpoint in.

Returns: Phaser.Math.Vector2 - The midpoint of the Line.

Source: src/geom/line/GetMidPoint.js#L9
Since: 3.0.0

GetNearestPoint

<static> GetNearestPoint(line, vec, [out])

Description:

Gets the nearest point on the infinite line defined by the given Line segment to the specified point. Note that the returned point is projected onto the full line, not clamped to the segment endpoints.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to get the nearest point on.
vecPhaser.Math.Vector2NoThe Vector2 to get the nearest point to.
outPhaser.Math.Vector2YesAn optional Vector2 object, to store the coordinates of the nearest point on the line.

Returns: Phaser.Math.Vector2 - The nearest point on the line.

Source: src/geom/line/GetNearestPoint.js#L10
Since: 3.16.0

GetNormal

<static> GetNormal(line, [out])

Description:

Calculate the normal of the given line.

The normal of a line is a vector that points perpendicular from it.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the normal of.
outPhaser.Math.Vector2YesAn optional Vector2 object to store the normal in.

Returns: Phaser.Math.Vector2 - The normal of the Line.

Source: src/geom/line/GetNormal.js#L11
Since: 3.0.0

GetPoint

<static> GetPoint(line, position, [out])

Description:

Get a point on a line that's a given percentage along its length.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line.
positionnumberNoA value between 0 and 1, where 0 is the start, 0.5 is the middle and 1 is the end of the line.
outPhaser.Math.Vector2YesAn optional Vector2 object to store the coordinates of the point on the line.

Returns: Phaser.Math.Vector2 - The point on the line.

Source: src/geom/line/GetPoint.js#L9
Since: 3.0.0

GetPoints

<static> GetPoints(line, quantity, [stepRate], [out])

Description:

Get a number of evenly-spaced points along a line, starting from the first endpoint (x1, y1). The last endpoint (x2, y2) is not included in the returned points.

Provide a quantity to get an exact number of points along the line.

Provide a stepRate to ensure a specific distance between each point on the line. Set quantity to 0 when providing a stepRate.

See also GetEasedPoints for a way to distribute the points across the line according to an ease type or input function.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line.
quantitynumberNoThe number of points to place on the line. Set to 0 to use stepRate instead.
stepRatenumberYesThe distance between each point on the line. When set, quantity is calculated as the line length divided by this value; quantity should be set to 0.
outArray.<Phaser.Math.Vector2>YesAn optional array of Vector2 objects to store the coordinates of the points on the line.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 objects containing the coordinates of the points on the line.

Source: src/geom/line/GetPoints.js#L10
Since: 3.0.0

GetShortestDistance

<static> GetShortestDistance(line, point)

Description:

Calculates the shortest (perpendicular) distance from an infinite line, defined by the two endpoints of the given Line object, to the given Point. If the line has zero length (both endpoints are identical), this function returns false.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to get the distance from.
pointPhaser.Types.Math.Vector2LikeNoThe point to get the shortest distance to.

Returns: boolean, number - The shortest perpendicular distance from the line to the point, or false if the line has zero length.

Source: src/geom/line/GetShortestDistance.js#L8
Since: 3.16.0

Height

<static> Height(line)

Description:

Calculate the height of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the height of.

Returns: number - The height of the line.

Source: src/geom/line/Height.js#L7
Since: 3.0.0

Length

<static> Length(line)

Description:

Calculate the length of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the length of.

Returns: number - The length of the line.

Source: src/geom/line/Length.js#L7
Since: 3.0.0

NormalAngle

<static> NormalAngle(line)

Description:

Get the angle of the normal of the given line in radians.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the angle of the normal of.

Returns: number - The angle of the normal of the line in radians.

Source: src/geom/line/NormalAngle.js#L11
Since: 3.0.0

NormalX

<static> NormalX(line)

Description:

Returns the x component of the normal vector of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe Line object to get the normal value from.

Returns: number - The x component of the normal vector of the line.

Source: src/geom/line/NormalX.js#L10
Since: 3.0.0

NormalY

<static> NormalY(line)

Description:

The Y value of the normal of the given line. The normal of a line is a vector that points perpendicular from it.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the normal of.

Returns: number - The Y value of the normal of the Line.

Source: src/geom/line/NormalY.js#L10
Since: 3.0.0

Offset

<static> Offset(line, x, y)

Description:

Translates both endpoints of the given Line by the specified horizontal and vertical amounts, effectively moving the line to a new position in 2D space while preserving its length and angle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to offset.
xnumberNoThe horizontal offset to add to the line.
ynumberNoThe vertical offset to add to the line.

Returns: Phaser.Geom.Line - The modified Line object, with both endpoints moved by the given offset.

Source: src/geom/line/Offset.js#L7
Since: 3.0.0

PerpSlope

<static> PerpSlope(line)

Description:

Calculate the perpendicular slope of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the perpendicular slope of.

Returns: number - The perpendicular slope of the line.

Source: src/geom/line/PerpSlope.js#L7
Since: 3.0.0

Random

<static> Random(line, [out])

Description:

Returns a random point on a given Line.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe Line to calculate the random point on.
outPhaser.Math.Vector2YesAn instance of a Vector2 to be modified.

Returns: Phaser.Math.Vector2 - A random point on the Line stored in a Vector2.

Source: src/geom/line/Random.js#L9
Since: 3.0.0

ReflectAngle

<static> ReflectAngle(lineA, lineB)

Description:

Calculates the reflected angle of Line A off the surface represented by Line B. This is the outgoing angle based on the angle of incidence (Line A) and the surface normal of Line B. The result is in radians.

Parameters:

nametypeoptionaldescription
lineAPhaser.Geom.LineNoThe incident line whose angle of incidence is used.
lineBPhaser.Geom.LineNoThe surface line, used to calculate the normal angle of reflection.

Returns: number - The reflected angle of Line A off the surface of Line B, in radians.

Source: src/geom/line/ReflectAngle.js#L10
Since: 3.0.0

Rotate

<static> Rotate(line, angle)

Description:

Rotate a line around its midpoint by the given angle in radians.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to rotate.
anglenumberNoThe angle of rotation in radians.

Returns: Phaser.Geom.Line - The rotated line.

Source: src/geom/line/Rotate.js#L9
Since: 3.0.0

RotateAroundPoint

<static> RotateAroundPoint(line, point, angle)

Description:

Rotate a line around a point by the given angle in radians.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to rotate.
pointPhaser.Math.Vector2NoThe point to rotate the line around.
anglenumberNoThe angle of rotation in radians.

Returns: Phaser.Geom.Line - The rotated line.

Source: src/geom/line/RotateAroundPoint.js#L9
Since: 3.0.0

RotateAroundXY

<static> RotateAroundXY(line, x, y, angle)

Description:

Rotate a line around the given coordinates by the given angle in radians.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to rotate.
xnumberNoThe horizontal coordinate to rotate the line around.
ynumberNoThe vertical coordinate to rotate the line around.
anglenumberNoThe angle of rotation in radians.

Returns: Phaser.Geom.Line - The rotated line.

Source: src/geom/line/RotateAroundXY.js#L7
Since: 3.0.0

SetToAngle

<static> SetToAngle(line, x, y, angle, length)

Description:

Set a line to a given position, angle and length.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to set.
xnumberNoThe horizontal start position of the line.
ynumberNoThe vertical start position of the line.
anglenumberNoThe angle of the line in radians.
lengthnumberNoThe length of the line.

Returns: Phaser.Geom.Line - The updated line.

Source: src/geom/line/SetToAngle.js#L7
Since: 3.0.0

Slope

<static> Slope(line)

Description:

Calculate the slope of the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the slope of.

Returns: number - The slope of the line.

Source: src/geom/line/Slope.js#L7
Since: 3.0.0

Width

<static> Width(line)

Description:

Calculates the width of the given line, defined as the absolute difference between the x-coordinates of its two endpoints (x1 and x2). This represents the horizontal extent of the line, not its geometric length. To get the true length of the line, use Phaser.Geom.Line.Length instead.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to calculate the width of.

Returns: number - The width of the line, i.e. the absolute difference between its x1 and x2 coordinates.

Source: src/geom/line/Width.js#L7
Since: 3.0.0

Phaser.Geom.Polygon

Clone

<static> Clone(polygon)

Description:

Create a new polygon which is a copy of the specified polygon

Parameters:

nametypeoptionaldescription
polygonPhaser.Geom.PolygonNoThe polygon to create a clone of

Returns: Phaser.Geom.Polygon - A new separate Polygon cloned from the specified polygon, based on the same points.

Source: src/geom/polygon/Clone.js#L9
Since: 3.0.0

Contains

<static> Contains(polygon, x, y)

Description:

Checks if a point is within the bounds of a Polygon.

Parameters:

nametypeoptionaldescription
polygonPhaser.Geom.PolygonNoThe Polygon to check against.
xnumberNoThe X coordinate of the point to check.
ynumberNoThe Y coordinate of the point to check.

Returns: boolean - true if the point is within the bounds of the Polygon, otherwise false.

Source: src/geom/polygon/Contains.js#L10
Since: 3.0.0

ContainsPoint

<static> ContainsPoint(polygon, vec)

Description:

Checks the given Point against the Polygon to see if the Point lays within its vertices.

Parameters:

nametypeoptionaldescription
polygonPhaser.Geom.PolygonNoThe Polygon to check.
vecPhaser.Math.Vector2NoThe Vector2 point to check if it's within the Polygon.

Returns: boolean - true if the point is within the Polygon, otherwise false.

Source: src/geom/polygon/ContainsPoint.js#L9
Since: 3.0.0

Earcut

<static> Earcut(data, [holeIndices], [dimensions])

Description:

This module implements a modified ear slicing algorithm, optimized by z-order curve hashing and extended to handle holes, twisted polygons, degeneracies and self-intersections in a way that doesn't guarantee correctness of triangulation, but attempts to always produce acceptable results for practical data.

Example:


const triangles = Phaser.Geom.Polygon.Earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1]

Each group of three vertex indices in the resulting array forms a triangle.


// triangulating a polygon with a hole

earcut([0,0, 100,0, 100,100, 0,100, 20,20, 80,20, 80,80, 20,80], [4]);

// [3,0,4, 5,4,0, 3,4,7, 5,0,1, 2,3,7, 6,5,1, 2,7,6, 6,1,2]



// triangulating a polygon with 3d coords

earcut([10,0,1, 0,50,2, 60,60,3, 70,10,4], null, 3);

// [1,0,3, 3,2,1]

If you pass a single vertex as a hole, Earcut treats it as a Steiner point.

If your input is a multi-dimensional array (e.g. GeoJSON Polygon), you can convert it to the format expected by Earcut with Phaser.Geom.Polygon.Earcut.flatten:


var data = earcut.flatten(geojson.geometry.coordinates);

var triangles = earcut(data.vertices, data.holes, data.dimensions);

After getting a triangulation, you can verify its correctness with Phaser.Geom.Polygon.Earcut.deviation:


var deviation = earcut.deviation(vertices, holes, dimensions, triangles);

```Returns the relative difference between the total area of triangles and the area of the input polygon. 0 means the triangulation is fully correct.

For more information see [https://github.com/mapbox/earcut](https://github.com/mapbox/earcut)

**Parameters:**
| name | type | optional | default | description |
| ---- | ---- | -------- | ------- | ----------- |
| data | Array.\<number> | No | | A flat array of vertex coordinates, like [x0,y0, x1,y1, x2,y2, ...] |
| holeIndices | Array.\<number> | Yes | | An array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11). |
| dimensions | number | Yes | 2 | The number of coordinates per vertex in the input array (2 by default). |


**Returns:** Array.\<number> - An array of triangulated data.


> Source: [src/geom/polygon/Earcut.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/Earcut.js#L7)
Since: 3.50.0


### GetAABB

#### \<static> GetAABB(polygon, [out])


**Description:**

Calculates the bounding AABB rectangle of a polygon.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | The polygon that should be calculated. |
| out | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) \| object | Yes | The rectangle or object that has x, y, width, and height properties to store the result. Optional. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md), object - The resulting rectangle or object that is passed in with position and dimensions of the polygon's AABB.


> Source: [src/geom/polygon/GetAABB.js#L9](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/GetAABB.js#L9)
Since: 3.0.0


### GetNumberArray

#### \<static> GetNumberArray(polygon, [output])


**Description:**

Stores all of the points of a Polygon into a flat array of numbers following the sequence [ x,y, x,y, x,y ], i.e. each point of the Polygon, in the order it's defined, corresponds to two elements of the resultant array for the point's X and Y coordinate.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | The Polygon whose points to export. |
| output | array \| Array.\<number> | Yes | An array to which the points' coordinates should be appended. |


**Returns:** array, Array.\<number> - The modified `output` array, or a new array if none was given.


> Source: [src/geom/polygon/GetNumberArray.js#L9](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/GetNumberArray.js#L9)
Since: 3.0.0


### GetPoints

#### \<static> GetPoints(polygon, quantity, [stepRate], [output])


**Description:**

Returns an array of Vector2 objects containing the coordinates of the points around the perimeter of the Polygon, based on the given quantity or stepRate values.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | The Polygon to get the points from. |
| quantity | number | No | The amount of points to return. If a falsy value the quantity will be derived from the `stepRate` instead. |
| stepRate | number | Yes | Sets the quantity by getting the perimeter of the Polygon and dividing it by the stepRate. |
| output | array | Yes | An array to insert the points in to. If not provided a new array will be created. |


**Returns:** Array.\<[Phaser.Math.Vector2](../class/Phaser.Math.Vector2.md)> - An array of Vector2 objects pertaining to the points around the perimeter of the Polygon.


> Source: [src/geom/polygon/GetPoints.js#L11](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/GetPoints.js#L11)
Since: 3.12.0


### Perimeter

#### \<static> Perimeter(polygon)


**Description:**

Returns the perimeter of the given Polygon by summing the lengths of all its edges. The polygon is treated as closed, so the edge between the last point and the first point is included in the total.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | The Polygon to get the perimeter of. |


**Returns:** number - The perimeter of the Polygon.


> Source: [src/geom/polygon/Perimeter.js#L10](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/Perimeter.js#L10)
Since: 3.12.0


### Reverse

#### \<static> Reverse(polygon)


**Description:**

Reverses the order of the points of a Polygon.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | The Polygon to modify. |


**Returns:** [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) - The modified Polygon.


> Source: [src/geom/polygon/Reverse.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/Reverse.js#L7)
Since: 3.0.0


### Simplify

#### \<static> Simplify(polygon, [tolerance], [highestQuality])


**Description:**

Takes a Polygon object and simplifies the points by running them through a combination of Douglas-Peucker and Radial Distance algorithms. Simplification dramatically reduces the number of points in a polygon while retaining its shape, giving a huge performance boost when processing it and also reducing visual noise.

**Tags:**

- generic

**Parameters:**
| name | type | optional | default | description |
| ---- | ---- | -------- | ------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | | The polygon to be simplified. The polygon will be modified in-place and returned. |
| tolerance | number | Yes | 1 | Affects the amount of simplification (in the same metric as the point coordinates). |
| highestQuality | boolean | Yes | false | Excludes distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower. |


**Returns:** [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) - The input polygon.


> Source: [src/geom/polygon/Simplify.js#L160](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/Simplify.js#L160)
Since: 3.50.0


### Smooth

#### \<static> Smooth(polygon)


**Description:**

Takes a Polygon object and applies Chaikin's smoothing algorithm on its points.

Chaikin's algorithm is a corner-cutting technique that replaces each edge between two consecutive points with two new points positioned along that edge, resulting in a smoother curve. Each iteration of the algorithm increases the total number of points in the polygon. The original first and last points are preserved, while all intermediate points are replaced by pairs of new points at 85% and 15% along each edge.

The polygon is modified in-place and the same polygon object is returned.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | The polygon to be smoothed. The polygon will be modified in-place and returned. |


**Returns:** [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) - The input polygon.


> Source: [src/geom/polygon/Smooth.js#L19](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/Smooth.js#L19)
Since: 3.13.0


### Translate

#### \<static> Translate(polygon, x, y)


**Description:**

Translates the points of the given Polygon.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| polygon | [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) | No | The Polygon to modify. |
| x | number | No | The amount to horizontally translate the points by. |
| y | number | No | The amount to vertically translate the points by. |


**Returns:** [Phaser.Geom.Polygon](../class/Phaser.Geom.Polygon.md) - The modified Polygon.


> Source: [src/geom/polygon/Translate.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/polygon/Translate.js#L7)
Since: 3.50.0


# Phaser.Geom.Rectangle

### Area

#### \<static> Area(rect)


**Description:**

Calculates the area of the given Rectangle object.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The rectangle to calculate the area of. |


**Returns:** number - The area of the Rectangle object.


> Source: [src/geom/rectangle/Area.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/Area.js#L7)
Since: 3.0.0


### Ceil

#### \<static> Ceil(rect)


**Description:**

Rounds a Rectangle's position up to the smallest integer greater than or equal to each current coordinate.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle to adjust. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The adjusted Rectangle.


> Source: [src/geom/rectangle/Ceil.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/Ceil.js#L7)
Since: 3.0.0


### CeilAll

#### \<static> CeilAll(rect)


**Description:**

Rounds a Rectangle's position and size up to the smallest integer greater than or equal to each respective value.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle to modify. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The modified Rectangle.


> Source: [src/geom/rectangle/CeilAll.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/CeilAll.js#L7)
Since: 3.0.0


### CenterOn

#### \<static> CenterOn(rect, x, y)


**Description:**

Moves the top-left corner of a Rectangle so that its center is at the given coordinates.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle to be centered. |
| x | number | No | The X coordinate of the Rectangle's center. |
| y | number | No | The Y coordinate of the Rectangle's center. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The centered rectangle.


> Source: [src/geom/rectangle/CenterOn.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/CenterOn.js#L7)
Since: 3.0.0


### Clone

#### \<static> Clone(source)


**Description:**

Creates a new Rectangle which is identical to the given one.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| source | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle to clone. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The newly created Rectangle, which is separate from the given one.


> Source: [src/geom/rectangle/Clone.js#L9](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/Clone.js#L9)
Since: 3.0.0


### Contains

#### \<static> Contains(rect, x, y)


**Description:**

Checks if a given point is inside a Rectangle's bounds.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle to check. |
| x | number | No | The X coordinate of the point to check. |
| y | number | No | The Y coordinate of the point to check. |


**Returns:** boolean - `true` if the point is within the Rectangle's bounds, otherwise `false`.


> Source: [src/geom/rectangle/Contains.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/Contains.js#L7)
Since: 3.0.0


### ContainsPoint

#### \<static> ContainsPoint(rect, vec)


**Description:**

Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle object. |
| vec | [Phaser.Math.Vector2](../class/Phaser.Math.Vector2.md) | No | The Vector2 object to check the coordinates of. |


**Returns:** boolean - A value of true if the Rectangle object contains the specified point, otherwise false.


> Source: [src/geom/rectangle/ContainsPoint.js#L9](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/ContainsPoint.js#L9)
Since: 3.0.0


### ContainsRect

#### \<static> ContainsRect(rectA, rectB)


**Description:**

Tests if one rectangle fully contains another. A rectangle is considered fully contained if all four of its edges (left, right, top, and bottom) lie strictly within the bounds of the outer rectangle. Rectangles that merely touch or overlap are not considered contained.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rectA | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The outer rectangle to test as the container. |
| rectB | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The inner rectangle to test for full containment within rectA. |


**Returns:** boolean - True only if rectA fully contains rectB.


> Source: [src/geom/rectangle/ContainsRect.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/ContainsRect.js#L7)
Since: 3.0.0


### CopyFrom

#### \<static> CopyFrom(source, dest)


**Description:**

Copy the values of one Rectangle to a destination Rectangle.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| source | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The source Rectangle to copy the values from. |
| dest | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The destination Rectangle to copy the values to. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The destination Rectangle.


> Source: [src/geom/rectangle/CopyFrom.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/CopyFrom.js#L7)
Since: 3.0.0


### Decompose

#### \<static> Decompose(rect, [out])


**Description:**

Creates an array of plain `{x, y}` point objects for each of the four corners of a Rectangle, in the order: top-left, top-right, bottom-right, bottom-left. If an output array is provided, each point object will be pushed to the end of it, otherwise a new array will be created and returned.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle object to be decomposed. |
| out | array | Yes | If provided, each point will be added to this array. |


**Returns:** array - Will return the array you specified or a new array containing the points of the Rectangle.


> Source: [src/geom/rectangle/Decompose.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/Decompose.js#L7)
Since: 3.0.0


### Equals

#### \<static> Equals(rect, toCompare)


**Description:**

Compares the `x`, `y`, `width` and `height` properties of two rectangles. Returns `true` only if all four values match exactly using strict equality. This function does not consider rectangles with the same area but different positions or dimensions to be equal.

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The first rectangle to compare. |
| toCompare | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The second rectangle to compare against. |


**Returns:** boolean - `true` if the rectangles' properties are an exact match, otherwise `false`.


> Source: [src/geom/rectangle/Equals.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/Equals.js#L7)
Since: 3.0.0


### FitInside

#### \<static> FitInside(target, source)


**Description:**

Adjusts the target rectangle, changing its width, height and position, so that it fits inside the area of the source rectangle, while maintaining its original aspect ratio.

Unlike the `FitOutside` function, there may be some space inside the source area not covered.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| target | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The target rectangle to adjust. |
| source | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The source rectangle to envelop the target in. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The modified target rectangle instance.


> Source: [src/geom/rectangle/FitInside.js#L9](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/FitInside.js#L9)
Since: 3.0.0


### FitOutside

#### \<static> FitOutside(target, source)


**Description:**

Adjusts the target rectangle, changing its width, height and position, so that it fully covers the area of the source rectangle, while maintaining its original aspect ratio.

Unlike the `FitInside` function, the target rectangle may extend further out than the source.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| target | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The target rectangle to adjust. |
| source | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The source rectangle to envelope the target in. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The modified target rectangle instance.


> Source: [src/geom/rectangle/FitOutside.js#L9](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/FitOutside.js#L9)
Since: 3.0.0


### Floor

#### \<static> Floor(rect)


**Description:**

Rounds down (floors) the top left X and Y coordinates of the given Rectangle to the largest integer less than or equal to them

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The rectangle to floor the top left X and Y coordinates of |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The rectangle that was passed to this function with its coordinates floored.


> Source: [src/geom/rectangle/Floor.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/Floor.js#L7)
Since: 3.0.0


### FloorAll

#### \<static> FloorAll(rect)


**Description:**

Rounds a Rectangle's position and size down to the largest integer less than or equal to each current coordinate or dimension.

**Tags:**

- generic

**Parameters:**
| name | type | optional | description |
| ---- | ---- | -------- | ----------- |
| rect | [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) | No | The Rectangle to adjust. |


**Returns:** [Phaser.Geom.Rectangle](../class/Phaser.Geom.Rectangle.md) - The adjusted Rectangle.


> Source: [src/geom/rectangle/FloorAll.js#L7](https://github.com/phaserjs/phaser/blob/v4.0.0/src/geom/rectangle/FloorAll.js#L7)
Since: 3.0.0


### FromPoints

#### \<static> FromPoints(points, [out])


**Description:**

Constructs a new Rectangle or repositions and resizes an existing Rectangle so that all of the given points are on or within its bounds.

The `points` parameter is an array of Point-like objects:

```js

const points = [

[100, 200],

[200, 400],

{ x: 30, y: 60 }

]

Tags:

  • generic

Parameters:

nametypeoptionaldescription
pointsarrayNoAn array of points (either arrays with two elements corresponding to the X and Y coordinate or an object with public x and y properties) which should be surrounded by the Rectangle.
outPhaser.Geom.RectangleYesOptional Rectangle to adjust.

Returns: Phaser.Geom.Rectangle - The adjusted out Rectangle, or a new Rectangle if none was provided.

Source: src/geom/rectangle/FromPoints.js#L10
Since: 3.0.0

FromXY

<static> FromXY(x1, y1, x2, y2, [out])

Description:

Create the smallest Rectangle containing two coordinate pairs.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
x1numberNoThe X coordinate of the first point.
y1numberNoThe Y coordinate of the first point.
x2numberNoThe X coordinate of the second point.
y2numberNoThe Y coordinate of the second point.
outPhaser.Geom.RectangleYesOptional Rectangle to adjust.

Returns: Phaser.Geom.Rectangle - The adjusted out Rectangle, or a new Rectangle if none was provided.

Source: src/geom/rectangle/FromXY.js#L9
Since: 3.23.0

GetAspectRatio

<static> GetAspectRatio(rect)

Description:

Calculates the width/height ratio of a rectangle.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe rectangle.

Returns: number - The width/height ratio of the rectangle.

Source: src/geom/rectangle/GetAspectRatio.js#L7
Since: 3.0.0

GetCenter

<static> GetCenter(rect, [out])

Description:

Returns the center of a Rectangle as a Point.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to get the center of.
outPhaser.Math.Vector2YesOptional Vector2 object to update with the center coordinates.

Returns: Phaser.Math.Vector2 - The modified out object, or a new Vector2 if none was provided.

Source: src/geom/rectangle/GetCenter.js#L9
Since: 3.0.0

GetPoint

<static> GetPoint(rectangle, position, [out])

Description:

Calculates the coordinates of a point at a certain position on the Rectangle's perimeter.

The position is a fraction between 0 and 1 which defines how far into the perimeter the point is.

A value of 0 or 1 returns the point at the top left corner of the rectangle, while a value of 0.5 returns the point at the bottom right corner of the rectangle. Values between 0 and 0.5 are on the top or the right side and values between 0.5 and 1 are on the bottom or the left side.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectanglePhaser.Geom.RectangleNoThe Rectangle to get the perimeter point from.
positionnumberNoThe normalized distance into the Rectangle's perimeter to return.
outPhaser.Math.Vector2YesA Vector2 object to update with the x and y coordinates of the point.

Returns: Phaser.Math.Vector2 - The updated out object, or a new Vector2 if no out object was given.

Source: src/geom/rectangle/GetPoint.js#L10
Since: 3.0.0

GetPoints

<static> GetPoints(rectangle, quantity, stepRate, [out])

Description:

Return an array of Vector2 points from the perimeter of the rectangle, each spaced out based on the quantity or step required.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectanglePhaser.Geom.RectangleNoThe Rectangle object to get the points from.
quantitynumberNoThe number of evenly spaced points from the rectangle's perimeter to return. If falsey, stepRate param will be used to calculate the number of points.
stepRatenumberNoStep between points. Used to calculate the number of points to return when quantity is falsey. Ignored if quantity is positive.
outArray.<Phaser.Math.Vector2>YesAn optional array to store the points in.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 points from the perimeter of the rectangle.

Source: src/geom/rectangle/GetPoints.js#L10
Since: 3.0.0

GetSize

<static> GetSize(rect, [out])

Description:

Returns the size of the Rectangle, expressed as a Vector2 object. With the value of the width as the x property and the height as the y property.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to get the size from.
outPhaser.Math.Vector2YesThe Vector2 object to store the size in. If not given, a new Vector2 instance is created.

Returns: Phaser.Math.Vector2 - A Vector2 object where x holds the width and y holds the height of the Rectangle.

Source: src/geom/rectangle/GetSize.js#L9
Since: 3.0.0

Inflate

<static> Inflate(rect, x, y)

Description:

Increases the size of a Rectangle by a specified amount.

The center of the Rectangle stays the same. The amounts are added to each side, so the actual increase in width or height is two times bigger than the respective argument.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to inflate.
xnumberNoHow many pixels the left and the right side should be moved by horizontally.
ynumberNoHow many pixels the top and the bottom side should be moved by vertically.

Returns: Phaser.Geom.Rectangle - The inflated Rectangle.

Source: src/geom/rectangle/Inflate.js#L9
Since: 3.0.0

Intersection

<static> Intersection(rectA, rectB, [out])

Description:

Takes two Rectangles and first checks to see if they intersect. If they intersect it will return the area of intersection in the out Rectangle. If they do not intersect, the out Rectangle will have a width and height of zero.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to get the intersection from.
rectBPhaser.Geom.RectangleNoThe second Rectangle to get the intersection from.
outPhaser.Geom.RectangleYesA Rectangle to store the intersection results in.

Returns: Phaser.Geom.Rectangle - The intersection result. If the width and height are zero, no intersection occurred.

Source: src/geom/rectangle/Intersection.js#L10
Since: 3.11.0

MarchingAnts

<static> MarchingAnts(rect, [step], [quantity], [out])

Description:

Returns an array of Vector2 points evenly distributed around the perimeter of the Rectangle. This is commonly used to create a "marching ants" selection effect, where the returned points are used to animate a dashed outline that appears to march around the border of the rectangle.

You can control the spacing of the points either by providing a pixel step distance between each point, or by specifying the total quantity of points to distribute evenly around the full perimeter. If both are omitted, an empty array is returned. If step is provided, quantity is derived from the perimeter length divided by the step. If only quantity is provided, the step is derived instead.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to get the perimeter points from.
stepnumberYesThe distance between each point of the perimeter. Set to null if you wish to use the quantity parameter instead.
quantitynumberYesThe total number of points to return. The step is then calculated based on the length of the Rectangle, divided by this value.
outArray.<Phaser.Math.Vector2>YesAn array in which the perimeter points will be stored. If not given, a new array instance is created.

Returns: Array.<Phaser.Math.Vector2> - An array containing the perimeter points from the Rectangle.

Source: src/geom/rectangle/MarchingAnts.js#L10
Since: 3.0.0

MergePoints

<static> MergePoints(target, points)

Description:

Merges a Rectangle with a list of points by repositioning and/or resizing it such that all points are located on or within its bounds.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoThe Rectangle which should be merged.
pointsArray.<Phaser.Math.Vector2>NoAn array of Vector2 objects which should be merged with the Rectangle.

Returns: Phaser.Geom.Rectangle - The modified Rectangle.

Source: src/geom/rectangle/MergePoints.js#L7
Since: 3.0.0

MergeRect

<static> MergeRect(target, source)

Description:

Merges the source rectangle into the target rectangle and returns the target. Neither rectangle should have a negative width or height.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoTarget rectangle. Will be modified to include source rectangle.
sourcePhaser.Geom.RectangleNoRectangle that will be merged into target rectangle.

Returns: Phaser.Geom.Rectangle - Modified target rectangle that contains source rectangle.

Source: src/geom/rectangle/MergeRect.js#L7
Since: 3.0.0

MergeXY

<static> MergeXY(target, x, y)

Description:

Merges a Rectangle with a point by repositioning and/or resizing it so that the point is on or within its bounds.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
targetPhaser.Geom.RectangleNoThe Rectangle which should be merged and modified.
xnumberNoThe X coordinate of the point which should be merged.
ynumberNoThe Y coordinate of the point which should be merged.

Returns: Phaser.Geom.Rectangle - The modified target Rectangle.

Source: src/geom/rectangle/MergeXY.js#L7
Since: 3.0.0

Offset

<static> Offset(rect, x, y)

Description:

Translates a Rectangle by the given horizontal and vertical amounts, moving its position while preserving its size.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to adjust.
xnumberNoThe distance to move the Rectangle horizontally.
ynumberNoThe distance to move the Rectangle vertically.

Returns: Phaser.Geom.Rectangle - The adjusted Rectangle.

Source: src/geom/rectangle/Offset.js#L7
Since: 3.0.0

OffsetPoint

<static> OffsetPoint(rect, vec)

Description:

Translates the top-left corner of a Rectangle by the coordinates of a translation vector.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to adjust.
vecPhaser.Math.Vector2NoThe Vector2 point whose coordinates should be used as an offset.

Returns: Phaser.Geom.Rectangle - The adjusted Rectangle.

Source: src/geom/rectangle/OffsetPoint.js#L7
Since: 3.0.0

Overlaps

<static> Overlaps(rectA, rectB)

Description:

Checks if two Rectangles overlap. If a Rectangle is within another Rectangle, the two will be considered overlapping. Thus, the Rectangles are treated as "solid".

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to check.
rectBPhaser.Geom.RectangleNoThe second Rectangle to check.

Returns: boolean - true if the two Rectangles overlap, false otherwise.

Source: src/geom/rectangle/Overlaps.js#L7
Since: 3.0.0

Perimeter

<static> Perimeter(rect)

Description:

Calculates the perimeter of a Rectangle.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to use.

Returns: number - The perimeter of the Rectangle, equal to (width * 2) + (height * 2).

Source: src/geom/rectangle/Perimeter.js#L7
Since: 3.0.0

PerimeterPoint

<static> PerimeterPoint(rectangle, angle, [out])

Description:

Returns a point from the perimeter of a Rectangle based on the given angle, measured in degrees from the center of the Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectanglePhaser.Geom.RectangleNoThe Rectangle to get the perimeter point from.
anglenumberNoThe angle of the point, in degrees.
outPhaser.Math.Vector2YesThe Vector2 object to store the position in. If not given, a new Vector2 instance is created.

Returns: Phaser.Math.Vector2 - A Vector2 object holding the coordinates of the point on the Rectangle's perimeter.

Source: src/geom/rectangle/PerimeterPoint.js#L10
Since: 3.0.0

Random

<static> Random(rect, out)

Description:

Returns a random point within a Rectangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle to return a point from.
outPhaser.Math.Vector2NoThe object to update with the point's coordinates.

Returns: Phaser.Math.Vector2 - The modified out object, or a new Point if none was provided.

Source: src/geom/rectangle/Random.js#L9
Since: 3.0.0

RandomOutside

<static> RandomOutside(outer, inner, [out])

Description:

Calculates a random point that lies within the outer Rectangle, but outside of the inner Rectangle. The inner Rectangle must be fully contained within the outer rectangle for a point to be generated. If inner is not fully contained within outer, the function returns the out vector unchanged.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
outerPhaser.Geom.RectangleNoThe outer Rectangle to get the random point within.
innerPhaser.Geom.RectangleNoThe inner Rectangle to exclude from the returned point.
outPhaser.Math.Vector2YesA Vector2 object to store the result in. If not specified, a new Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object containing the random values in its x and y properties.

Source: src/geom/rectangle/RandomOutside.js#L11
Since: 3.10.0

SameDimensions

<static> SameDimensions(rect, toCompare)

Description:

Determines if the two objects (either Rectangles or Rectangle-like) have the same width and height values under strict equality.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe first Rectangle object.
toComparePhaser.Geom.RectangleNoThe second Rectangle object.

Returns: boolean - true if the objects have equivalent values for the width and height properties, otherwise false.

Source: src/geom/rectangle/SameDimensions.js#L7
Since: 3.15.0

Scale

<static> Scale(rect, x, y)

Description:

Scales the width and height of the given Rectangle by the given factors.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe Rectangle object that will be scaled by the specified amount(s).
xnumberNoThe factor by which to scale the rectangle horizontally.
ynumberNoThe factor by which to scale the rectangle vertically. If this is not specified, the rectangle will be scaled by the factor x in both directions.

Returns: Phaser.Geom.Rectangle - The rectangle object with updated width and height properties as calculated from the scaling factor(s).

Source: src/geom/rectangle/Scale.js#L7
Since: 3.0.0

Union

<static> Union(rectA, rectB, [out])

Description:

Creates a new Rectangle or repositions and/or resizes an existing Rectangle so that it encompasses the two given Rectangles, i.e. calculates their union.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
rectAPhaser.Geom.RectangleNoThe first Rectangle to use.
rectBPhaser.Geom.RectangleNoThe second Rectangle to use.
outPhaser.Geom.RectangleYesThe Rectangle to store the union in.

Returns: Phaser.Geom.Rectangle - The modified out Rectangle, or a new Rectangle if none was provided.

Source: src/geom/rectangle/Union.js#L9
Since: 3.0.0

Phaser.Geom.Triangle

Area

<static> Area(triangle)

Description:

Returns the area of a Triangle.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to use.

Returns: number - The area of the Triangle, always non-negative.

Source: src/geom/triangle/Area.js#L9
Since: 3.0.0

BuildEquilateral

<static> BuildEquilateral(x, y, length)

Description:

Builds an equilateral triangle. In the equilateral triangle, all the sides are the same length (congruent) and all the angles are the same size (congruent). The x/y specifies the top-middle of the triangle (x1/y1) and length is the length of each side.

Parameters:

nametypeoptionaldescription
xnumberNox coordinate of the top point of the triangle.
ynumberNoy coordinate of the top point of the triangle.
lengthnumberNoLength of each side of the triangle.

Returns: Phaser.Geom.Triangle - A new equilateral Triangle with its apex at (x, y) and all sides of the specified length.

Source: src/geom/triangle/BuildEquilateral.js#L9
Since: 3.0.0

BuildFromPolygon

<static> BuildFromPolygon(data, [holes], [scaleX], [scaleY], [out])

Description:

Takes an array of vertex coordinates, and optionally an array of hole indices, then returns an array of Triangle instances, where the given vertices have been decomposed into a series of triangles.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
dataarrayNoA flat array of vertex coordinates like [x0,y0, x1,y1, x2,y2, ...]
holesarrayYesnullAn array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11).
scaleXnumberYes1Horizontal scale factor to multiply the resulting points by.
scaleYnumberYes1Vertical scale factor to multiply the resulting points by.
outarray | Array.<Phaser.Geom.Triangle>YesAn array to store the resulting Triangle instances in. If not provided, a new array is created.

Returns: array, Array.<Phaser.Geom.Triangle> - An array of Triangle instances, where each triangle is based on the decomposed vertices data.

Source: src/geom/triangle/BuildFromPolygon.js#L10
Since: 3.0.0

BuildRight

<static> BuildRight(x, y, width, height)

Description:

Builds a right triangle, i.e. one which has a 90-degree angle and two acute angles. The x and y coordinates mark the position of the right-angle vertex, which becomes the first point of the Triangle. The width and height values determine the lengths of the two sides adjacent to the right angle and may be positive or negative, which controls the direction in which each side extends from the right-angle vertex.

Parameters:

nametypeoptionaldescription
xnumberNoThe X coordinate of the right angle, which will also be the first X coordinate of the constructed Triangle.
ynumberNoThe Y coordinate of the right angle, which will also be the first Y coordinate of the constructed Triangle.
widthnumberNoThe length of the side which is to the left or to the right of the right angle.
heightnumberNoThe length of the side which is above or below the right angle. If not given, defaults to the value of width.

Returns: Phaser.Geom.Triangle - The constructed right Triangle.

Source: src/geom/triangle/BuildRight.js#L13
Since: 3.0.0

CenterOn

<static> CenterOn(triangle, x, y, [centerFunc])

Description:

Positions the Triangle so that it is centered on the given coordinates.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe triangle to be positioned.
xnumberNoThe horizontal coordinate to center on.
ynumberNoThe vertical coordinate to center on.
centerFuncCenterFunctionYesThe function used to center the triangle. Defaults to Centroid centering.

Returns: Phaser.Geom.Triangle - The Triangle that was centered.

Source: src/geom/triangle/CenterOn.js#L18
Since: 3.0.0

Centroid

<static> Centroid(triangle, [out])

Description:

Calculates the position of a Triangle's centroid, which is also its center of mass (center of gravity).

The centroid is the point in a Triangle at which its three medians (the lines drawn from the vertices to the bisectors of the opposite sides) meet. It divides each one in a 2:1 ratio.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to use.
outPhaser.Math.Vector2YesA Vector2 object to store the coordinates in.

Returns: Phaser.Math.Vector2 - The out object with modified x and y properties, or a new Vector2 if none was provided.

Source: src/geom/triangle/Centroid.js#L9
Since: 3.0.0

CircumCenter

<static> CircumCenter(triangle, [out])

Description:

Computes the circumcenter of a triangle. The circumcenter is the centre of the circumcircle, the unique circle that passes through all three vertices of the triangle. It is also the common intersection point of the perpendicular bisectors of the sides of the triangle, and is the only point which has equal distance to all three vertices of the triangle.

Adapted from http://bjornharrtell.github.io/jsts/doc/api/jsts_geom_Triangle.js.html

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to get the circumcenter of.
outPhaser.Math.Vector2YesThe Vector2 object to store the position in. If not given, a new Vector2 instance is created.

Returns: Phaser.Math.Vector2 - A Vector2 object holding the coordinates of the circumcenter of the Triangle.

Source: src/geom/triangle/CircumCenter.js#L28
Since: 3.0.0

CircumCircle

<static> CircumCircle(triangle, [out])

Description:

Finds the circumscribed circle (circumcircle) of a Triangle object. The circumcircle is the circle which touches all of the triangle's vertices.

Adapted from https://gist.github.com/mutoo/5617691

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to use as input.
outPhaser.Geom.CircleYesAn optional Circle to store the result in.

Returns: Phaser.Geom.Circle - The updated out Circle, or a new Circle if none was provided.

Source: src/geom/triangle/CircumCircle.js#L9
Since: 3.0.0

Clone

<static> Clone(source)

Description:

Clones a Triangle object.

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.TriangleNoThe Triangle to clone.

Returns: Phaser.Geom.Triangle - A new Triangle identical to the given one but separate from it.

Source: src/geom/triangle/Clone.js#L9
Since: 3.0.0

Contains

<static> Contains(triangle, x, y)

Description:

Checks if a point (as a pair of coordinates) is inside a Triangle's bounds.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to check.
xnumberNoThe X coordinate of the point to check.
ynumberNoThe Y coordinate of the point to check.

Returns: boolean - true if the point is inside the Triangle, otherwise false.

Source: src/geom/triangle/Contains.js#L9
Since: 3.0.0

ContainsArray

<static> ContainsArray(triangle, points, [returnFirst], [out])

Description:

Filters an array of point-like objects to only those contained within a triangle.

If returnFirst is true, will return an array containing only the first point in the provided array that is within the triangle (or an empty array if there are no such points).

Parameters:

nametypeoptionaldefaultdescription
trianglePhaser.Geom.TriangleNoThe triangle that the points are being checked in.
pointsArray.<Phaser.Math.Vector2>NoAn array of Vector2 objects to check if they are within the triangle.
returnFirstbooleanYesfalseIf true, return an array containing only the first point found that is within the triangle.
outarrayYesIf provided, the points that are within the triangle will be appended to this array instead of being added to a new array. If returnFirst is true, only the first point found within the triangle will be appended. This array will also be returned by this function.

Returns: Array.<Phaser.Math.Vector2> - An array containing all the points from points that are within the triangle, if an array was provided as out, points will be appended to that array and it will also be returned here.

Source: src/geom/triangle/ContainsArray.js#L7
Since: 3.0.0

ContainsPoint

<static> ContainsPoint(triangle, vec)

Description:

Tests if a triangle contains a point.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe triangle.
vecPhaser.Math.Vector2NoThe Vector2 point to test if it's within the triangle.

Returns: boolean - true if the point is within the triangle, otherwise false.

Source: src/geom/triangle/ContainsPoint.js#L9
Since: 3.0.0

CopyFrom

<static> CopyFrom(source, dest)

Description:

Copy the values of one Triangle to a destination Triangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.TriangleNoThe source Triangle to copy the values from.
destPhaser.Geom.TriangleNoThe destination Triangle to copy the values to.

Returns: Phaser.Geom.Triangle - The destination Triangle.

Source: src/geom/triangle/CopyFrom.js#L7
Since: 3.0.0

Decompose

<static> Decompose(triangle, [out])

Description:

Decomposes a Triangle into an array of its points.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to decompose.
outarrayYesAn array to store the points into.

Returns: array - The provided out array, or a new array if none was provided, with three objects with x and y properties representing each point of the Triangle appended to it.

Source: src/geom/triangle/Decompose.js#L7
Since: 3.0.0

Equals

<static> Equals(triangle, toCompare)

Description:

Returns true if two triangles have the same coordinates.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe first triangle to check.
toComparePhaser.Geom.TriangleNoThe second triangle to check.

Returns: boolean - true if the two given triangles have the exact same coordinates, otherwise false.

Source: src/geom/triangle/Equals.js#L7
Since: 3.0.0

GetPoint

<static> GetPoint(triangle, position, [out])

Description:

Returns a point along the perimeter of a Triangle as a Vector2, based on a normalized position value.

The position parameter is a value between 0 and 1, where 0 and 1 both map to the start of line A (the first vertex). The point is calculated by traversing the triangle's perimeter in order: line A, then line B, then line C.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to get the point on its perimeter from.
positionnumberNoA normalized value between 0 and 1 representing a position along the triangle's perimeter. Both 0 and 1 return the start of line A.
outPhaser.Math.Vector2YesAn optional Vector2 point to store the result in. If not given, a new Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 point containing the coordinates of the position on the triangle's perimeter.

Source: src/geom/triangle/GetPoint.js#L10
Since: 3.0.0

GetPoints

<static> GetPoints(triangle, quantity, stepRate, [out])

Description:

Returns an array of evenly spaced points on the perimeter of a Triangle.

The points are placed along the triangle's three edges in order (A, B, then C), with their positions calculated proportionally based on the total perimeter length.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to get the points from.
quantitynumberNoThe number of evenly spaced points to return. Set to 0 to return an arbitrary number of points based on the stepRate.
stepRatenumberNoIf quantity is 0, the distance in pixels between each returned point along the perimeter.
outArray.<Phaser.Math.Vector2>YesAn array to which the points should be appended.

Returns: Array.<Phaser.Math.Vector2> - The modified out array, or a new array if none was provided.

Source: src/geom/triangle/GetPoints.js#L10
Since: 3.0.0

InCenter

<static> InCenter(triangle, [out])

Description:

Calculates the position of the incenter of a Triangle object. This is the point where its three angle bisectors meet and it's also the center of the incircle, which is the circle inscribed in the triangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to find the incenter of.
outPhaser.Math.Vector2YesAn optional Vector2 point in which to store the coordinates.

Returns: Phaser.Math.Vector2 - The incenter of the triangle in a Vector2.

Source: src/geom/triangle/InCenter.js#L21
Since: 3.0.0

Offset

<static> Offset(triangle, x, y)

Description:

Moves each point (vertex) of a Triangle by a given offset, thus moving the entire Triangle by that offset.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to move.
xnumberNoThe horizontal offset (distance) by which to move each point. Can be positive or negative.
ynumberNoThe vertical offset (distance) by which to move each point. Can be positive or negative.

Returns: Phaser.Geom.Triangle - The modified Triangle.

Source: src/geom/triangle/Offset.js#L7
Since: 3.0.0

Perimeter

<static> Perimeter(triangle)

Description:

Gets the length of the perimeter of the given triangle. Calculated by adding together the length of each of the three sides.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to get the length from.

Returns: number - The length of the Triangle.

Source: src/geom/triangle/Perimeter.js#L9
Since: 3.0.0

Random

<static> Random(triangle, [out])

Description:

Returns a random Point from within the area of the given Triangle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to get a random point from.
outPhaser.Math.Vector2YesThe Vector2 point object to store the position in. If not given, a new Vector2 instance is created.

Returns: Phaser.Math.Vector2 - A Vector2 point object holding the coordinates of a random position within the Triangle.

Source: src/geom/triangle/Random.js#L9
Since: 3.0.0

Rotate

<static> Rotate(triangle, angle)

Description:

Rotates a Triangle about its incenter, which is the point at which its three angle bisectors meet.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to rotate.
anglenumberNoThe angle by which to rotate the Triangle, in radians.

Returns: Phaser.Geom.Triangle - The rotated Triangle.

Source: src/geom/triangle/Rotate.js#L10
Since: 3.0.0

RotateAroundPoint

<static> RotateAroundPoint(triangle, point, angle)

Description:

Rotates a Triangle at a certain angle about a given Vector2 point.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to rotate.
pointPhaser.Math.Vector2NoThe Vector2 point to rotate the Triangle around.
anglenumberNoThe angle by which to rotate the Triangle, in radians.

Returns: Phaser.Geom.Triangle - The rotated Triangle.

Source: src/geom/triangle/RotateAroundPoint.js#L9
Since: 3.0.0

RotateAroundXY

<static> RotateAroundXY(triangle, x, y, angle)

Description:

Rotates an entire Triangle at a given angle about a specific point.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe Triangle to rotate.
xnumberNoThe X coordinate of the point to rotate the Triangle about.
ynumberNoThe Y coordinate of the point to rotate the Triangle about.
anglenumberNoThe angle by which to rotate the Triangle, in radians.

Returns: Phaser.Geom.Triangle - The rotated Triangle.

Source: src/geom/triangle/RotateAroundXY.js#L7
Since: 3.0.0