Phaser.Geom.Intersects
Scope: static
Source: src/geom/intersects/index.js#L7
Static functions
CircleToCircle
<static> CircleToCircle(circleA, circleB)
Description:
Checks if two Circles intersect.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| circleA | Phaser.Geom.Circle | No | The first Circle to check for intersection. |
| circleB | Phaser.Geom.Circle | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| circle | Phaser.Geom.Circle | No | The circle to be checked. |
| rect | Phaser.Geom.Rectangle | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| circleA | Phaser.Geom.Circle | No | The first Circle to check for intersection. |
| circleB | Phaser.Geom.Circle | No | The second Circle to check for intersection. |
| out | Array.<Phaser.Math.Vector2> | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| circle | Phaser.Geom.Circle | No | The circle to be checked. |
| rect | Phaser.Geom.Rectangle | No | The rectangle to be checked. |
| out | array | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| line | Phaser.Geom.Line | No | The line segment to check. |
| circle | Phaser.Geom.Circle | No | The circle to check against the line. |
| out | Array.<Phaser.Math.Vector2> | Yes | An 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:
| name | type | optional | default | description |
|---|---|---|---|---|
| line1 | Phaser.Geom.Line | No | The first line segment, or a ray, to check. | |
| line2 | Phaser.Geom.Line | No | The second line segment to check. | |
| isRay | boolean | Yes | false | Is line1 a ray or a line segment? |
| out | Phaser.Math.Vector3 | Yes | A 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:
| name | type | optional | default | description |
|---|---|---|---|---|
| line | Phaser.Geom.Line | No | The line segment, or ray, to check. If a ray, set the isRay parameter to true. | |
| points | Array.<Phaser.Math.Vector2> | Array.<Phaser.Math.Vector2> | No | An array of points to check. | |
| isRay | boolean | Yes | false | Is line a ray or a line segment? |
| out | Phaser.Math.Vector3 | Yes | A 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:
| name | type | optional | default | description |
|---|---|---|---|---|
| line | Phaser.Geom.Line | No | The line segment, or ray, to check. If a ray, set the isRay parameter to true. | |
| polygons | Phaser.Geom.Polygon | Array.<Phaser.Geom.Polygon> | No | A single polygon, or array of polygons, to check. | |
| isRay | boolean | Yes | false | Is line a ray or a line segment? |
| out | Phaser.Math.Vector4 | Yes | A 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:
| name | type | optional | description |
|---|---|---|---|
| line | Phaser.Geom.Line | No | The Line to check for intersection. |
| rect | Phaser.Geom.Rectangle | No | The Rectangle to check for intersection. |
| out | Array.<Phaser.Math.Vector2> | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| x | number | No | The x coordinate to project the rays from. |
| y | number | No | The y coordinate to project the rays from. |
| polygons | Phaser.Geom.Polygon | Array.<Phaser.Geom.Polygon> | No | A 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:
| name | type | optional | description |
|---|---|---|---|
| rectA | Phaser.Geom.Rectangle | No | The first Rectangle object. |
| rectB | Phaser.Geom.Rectangle | No | The second Rectangle object. |
| output | Phaser.Geom.Rectangle | Yes | Optional 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:
| name | type | optional | description |
|---|---|---|---|
| rectA | Phaser.Geom.Rectangle | No | The first Rectangle to check for intersection. |
| rectB | Phaser.Geom.Rectangle | No | The second Rectangle to check for intersection. |
| out | array | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| rect | Phaser.Geom.Rectangle | No | Rectangle object to test. |
| triangle | Phaser.Geom.Triangle | No | Triangle object to test. |
| out | array | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| triangle | Phaser.Geom.Triangle | No | The Triangle to check for intersection. |
| circle | Phaser.Geom.Circle | No | The Circle to check for intersection. |
| out | array | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| triangle | Phaser.Geom.Triangle | No | The Triangle to check with. |
| line | Phaser.Geom.Line | No | The Line to check with. |
| out | Array.<Phaser.Math.Vector2> | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| triangleA | Phaser.Geom.Triangle | No | The first Triangle to check for intersection. |
| triangleB | Phaser.Geom.Triangle | No | The second Triangle to check for intersection. |
| out | array | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| line | Phaser.Geom.Line | No | The line segment to check. |
| circle | Phaser.Geom.Circle | No | The circle to check against the line. |
| nearest | Phaser.Math.Vector2 | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| line1 | Phaser.Geom.Line | No | The first Line to check. |
| line2 | Phaser.Geom.Line | No | The second Line to check. |
| out | Phaser.Types.Math.Vector2Like | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| line | Phaser.Geom.Line | No | The Line to check for intersection. |
| rect | Phaser.Geom.Rectangle | object | No | The 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:
| name | type | optional | default | description |
|---|---|---|---|---|
| point | Phaser.Math.Vector2 | any | No | The point, or point-like object to check. | |
| line | Phaser.Geom.Line | No | The line segment to test for intersection on. | |
| lineThickness | number | Yes | 1 | The 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:
| name | type | optional | description |
|---|---|---|---|
| point | Phaser.Math.Vector2 | No | The Point to check for intersection. |
| line | Phaser.Geom.Line | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| rectA | Phaser.Geom.Rectangle | No | The first Rectangle to check for intersection. |
| rectB | Phaser.Geom.Rectangle | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| rect | Phaser.Geom.Rectangle | No | The Rectangle to test. |
| triangle | Phaser.Geom.Triangle | No | The 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:
| name | type | optional | default | description |
|---|---|---|---|---|
| rect | Phaser.Geom.Rectangle | No | The Rectangle to check for intersection. | |
| left | number | No | The x coordinate of the left edge of the region to check against. | |
| right | number | No | The x coordinate of the right edge of the region to check against. | |
| top | number | No | The y coordinate of the top edge of the region to check against. | |
| bottom | number | No | The y coordinate of the bottom edge of the region to check against. | |
| tolerance | number | Yes | 0 | Tolerance 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:
| name | type | optional | description |
|---|---|---|---|
| triangle | Phaser.Geom.Triangle | No | The Triangle to check for intersection. |
| circle | Phaser.Geom.Circle | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| triangle | Phaser.Geom.Triangle | No | The Triangle to check with. |
| line | Phaser.Geom.Line | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| triangleA | Phaser.Geom.Triangle | No | The first Triangle to check for intersection. |
| triangleB | Phaser.Geom.Triangle | No | The 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