Phaser.Geom.Intersects

Scope: static

Source: src/geom/intersects/index.js#L7

Methods:

Public Members

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.
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/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 a Point object 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 Point object array.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line segment to check.
circlePhaser.Geom.CircleNoThe circle to check against the line.
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/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 intersection distance, which can be used 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 containing the intersection results, or null.

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 pair of points are converted to line segments for the intersection tests.

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.Geom.Point>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 Point object array.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe Line to check for intersection.
rectPhaser.Geom.Rectangle | objectNoThe 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/GetLineToRectangle.js#L12
Since: 3.0.0


GetRaysFromPointToPolygon

<static> GetRaysFromPointToPolygon(x, y, polygons)

Description:

Projects rays out from the given point to each line segment 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 intersection. 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 wil 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.
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/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.Geom.Point | anyYesAn optional Point-like 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.

The 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 the 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.Geom.Point | 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.Geom.PointNoThe 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 Rectangle shape and Triangle shape.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoRectangle object to test.
trianglePhaser.Geom.TriangleNoTriangle object 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:

Check if rectangle intersects with values.

Parameters:

nametypeoptionaldefaultdescription
rectPhaser.Geom.RectangleNoThe rectangle object
leftnumberNoThe x coordinate of the left of the Rectangle.
rightnumberNoThe x coordinate of the right of the Rectangle.
topnumberNoThe y coordinate of the top of the Rectangle.
bottomnumberNoThe y coordinate of the bottom of the Rectangle.
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


Private Members

Updated on