Namespace: Intersects

Phaser.Geom. Intersects

Methods


<static> CircleToCircle(circleA, circleB)

Checks if two Circles intersect.

Parameters:
Name Type Description
circleA Phaser.Geom.Circle

The first Circle to check for intersection.

circleB Phaser.Geom.Circle

The second Circle to check for intersection.

Since: 3.0.0
Source: src/geom/intersects/CircleToCircle.js (Line 9)
Returns:

true if the two Circles intersect, otherwise false.

Type
boolean

<static> CircleToRectangle(circle, rect)

Checks for intersection between a circle and a rectangle.

Parameters:
Name Type Description
circle Phaser.Geom.Circle

The circle to be checked.

rect Phaser.Geom.Rectangle

The rectangle to be checked.

Since: 3.0.0
Source: src/geom/intersects/CircleToRectangle.js (Line 7)
Returns:

true if the two objects intersect, otherwise false.

Type
boolean

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

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

Parameters:
Name Type Argument Description
circleA Phaser.Geom.Circle

The first Circle to check for intersection.

circleB Phaser.Geom.Circle

The second Circle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetCircleToCircle.js (Line 11)
Returns:

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

Type
array

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

Checks for intersection between a circle and a rectangle, and returns the intersection points as a Point object array.

Parameters:
Name Type Argument Description
circle Phaser.Geom.Circle

The circle to be checked.

rect Phaser.Geom.Rectangle

The rectangle to be checked.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetCircleToRectangle.js (Line 11)
Returns:

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

Type
array

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

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

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line segment to check.

circle Phaser.Geom.Circle

The circle to check against the line.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetLineToCircle.js (Line 11)
Returns:

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

Type
array

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

Checks for intersection between the two line segments 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:
Name Type Argument Description
line1 Phaser.Geom.Line

The first line segment to check.

line2 Phaser.Geom.Line

The second line segment to check.

out Phaser.Math.Vector3 <optional>

A Vector3 to store the intersection results in.

Since: 3.50.0
Source: src/geom/intersects/GetLineToLine.js (Line 9)
Returns:

A Vector3 containing the intersection results, or null.

Type
Phaser.Math.Vector3

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

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:
Name Type Argument Description
line Phaser.Geom.Line

The line segment to check.

points Array.<Phaser.Math.Vector2> | Array.<Phaser.Geom.Point>

An array of points to check.

out Phaser.Math.Vector3 <optional>

A Vector3 to store the intersection results in.

Since: 3.50.0
Source: src/geom/intersects/GetLineToPoints.js (Line 17)
Returns:

A Vector3 containing the intersection results, or null.

Type
Phaser.Math.Vector3

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

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 Argument Description
line Phaser.Geom.Line

The line segment to check.

polygons Phaser.Geom.Polygon | Array.<Phaser.Geom.Polygon>

A single polygon, or array of polygons, to check.

out Phaser.Math.Vector4 <optional>

A Vector4 to store the intersection results in.

Since: 3.50.0
Source: src/geom/intersects/GetLineToPolygon.js (Line 14)
Returns:

A Vector4 containing the intersection results, or null.

Type
Phaser.Math.Vector4

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

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

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The Line to check for intersection.

rect Phaser.Geom.Rectangle | object

The Rectangle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetLineToRectangle.js (Line 12)
Returns:

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

Type
array

<static> GetRaysFromPointToPolygon(x, y, polygons)

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:
Name Type Description
x number

The x coordinate to project the rays from.

y number

The y coordinate to project the rays from.

polygons Phaser.Geom.Polygon | Array.<Phaser.Geom.Polygon>

A single polygon, or array of polygons, to check against the rays.

Since: 3.50.0
Source: src/geom/intersects/GetRaysFromPointToPolygon.js (Line 40)
Returns:

An array containing all intersections in Vector4s.

Type
Array.<Phaser.Math.Vector4>

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

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.

Parameters:
Name Type Argument Description
rectA Phaser.Geom.Rectangle

The first Rectangle object.

rectB Phaser.Geom.Rectangle

The second Rectangle object.

output Phaser.Geom.Rectangle <optional>

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.

Since: 3.0.0
Source: src/geom/intersects/GetRectangleIntersection.js (Line 10)
Returns:

A rectangle object with intersection data.

Type
Phaser.Geom.Rectangle

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

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 Argument Description
rectA Phaser.Geom.Rectangle

The first Rectangle to check for intersection.

rectB Phaser.Geom.Rectangle

The second Rectangle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetRectangleToRectangle.js (Line 11)
Returns:

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

Type
array

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

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

Parameters:
Name Type Argument Description
rect Phaser.Geom.Rectangle

Rectangle object to test.

triangle Phaser.Geom.Triangle

Triangle object to test.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetRectangleToTriangle.js (Line 11)
Returns:

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

Type
array

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

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 Argument Description
triangle Phaser.Geom.Triangle

The Triangle to check for intersection.

circle Phaser.Geom.Circle

The Circle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetTriangleToCircle.js (Line 11)
Returns:

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

Type
array

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

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 Argument Description
triangle Phaser.Geom.Triangle

The Triangle to check with.

line Phaser.Geom.Line

The Line to check with.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetTriangleToLine.js (Line 12)
Returns:

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

Type
array

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

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 Argument Description
triangleA Phaser.Geom.Triangle

The first Triangle to check for intersection.

triangleB Phaser.Geom.Triangle

The second Triangle to check for intersection.

out array <optional>

An optional array in which to store the points of intersection.

Since: 3.0.0
Source: src/geom/intersects/GetTriangleToTriangle.js (Line 11)
Returns:

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

Type
array

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

Checks for intersection between the line segment and circle.

Based on code by Matt DesLauriers.

Parameters:
Name Type Argument Description
line Phaser.Geom.Line

The line segment to check.

circle Phaser.Geom.Circle

The circle to check against the line.

nearest Phaser.Geom.Point | any <optional>

An optional Point-like object. If given the closest point on the Line where the circle intersects will be stored in this object.

Since: 3.0.0
Source: src/geom/intersects/LineToCircle.js (Line 12)
Returns:

true if the two objects intersect, otherwise false.

Type
boolean

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

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

Parameters:
Name Type Argument Description
line1 Phaser.Geom.Line

The first Line to check.

line2 Phaser.Geom.Line

The second Line to check.

out Phaser.Geom.Point <optional>

A Point in which to optionally store the point of intersection.

Since: 3.0.0
Source: src/geom/intersects/LineToLine.js (Line 12)
Returns:

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

Type
boolean

<static> LineToRectangle(line, rect)

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:
Name Type Description
line Phaser.Geom.Line

The Line to check for intersection.

rect Phaser.Geom.Rectangle | object

The Rectangle to check for intersection.

Since: 3.0.0
Source: src/geom/intersects/LineToRectangle.js (Line 7)
Returns:

true if the Line and the Rectangle intersect, false otherwise.

Type
boolean

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

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:
Name Type Argument Default Description
point Phaser.Geom.Point | any

The point, or point-like object to check.

line Phaser.Geom.Line

The line segment to test for intersection on.

lineThickness number <optional>
1

The line thickness. Assumes that the line end points are circular.

Since: 3.0.0
Source: src/geom/intersects/PointToLine.js (Line 8)
Returns:

true if the Point falls on the Line, otherwise false.

Type
boolean

<static> PointToLineSegment(point, line)

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

Parameters:
Name Type Description
point Phaser.Geom.Point

The Point to check for intersection.

line Phaser.Geom.Line

The line segment to check for intersection.

Since: 3.0.0
Source: src/geom/intersects/PointToLineSegment.js (Line 9)
Returns:

true if the Point is on the given line segment, otherwise false.

Type
boolean

<static> RectangleToRectangle(rectA, rectB)

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 Description
rectA Phaser.Geom.Rectangle

The first Rectangle to check for intersection.

rectB Phaser.Geom.Rectangle

The second Rectangle to check for intersection.

Since: 3.0.0
Source: src/geom/intersects/RectangleToRectangle.js (Line 7)
Returns:

true if the two Rectangles intersect, otherwise false.

Type
boolean

<static> RectangleToTriangle(rect, triangle)

Checks for intersection between Rectangle shape and Triangle shape.

Parameters:
Name Type Description
rect Phaser.Geom.Rectangle

Rectangle object to test.

triangle Phaser.Geom.Triangle

Triangle object to test.

Since: 3.0.0
Source: src/geom/intersects/RectangleToTriangle.js (Line 12)
Returns:

A value of true if objects intersect; otherwise false.

Type
boolean

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

Check if rectangle intersects with values.

Parameters:
Name Type Argument Default Description
rect Phaser.Geom.Rectangle

The rectangle object

left number

The x coordinate of the left of the Rectangle.

right number

The x coordinate of the right of the Rectangle.

top number

The y coordinate of the top of the Rectangle.

bottom number

The y coordinate of the bottom of the Rectangle.

tolerance number <optional>
0

Tolerance allowed in the calculation, expressed in pixels.

Since: 3.0.0
Source: src/geom/intersects/RectangleToValues.js (Line 7)
Returns:

Returns true if there is an intersection.

Type
boolean

<static> TriangleToCircle(triangle, circle)

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 Description
triangle Phaser.Geom.Triangle

The Triangle to check for intersection.

circle Phaser.Geom.Circle

The Circle to check for intersection.

Since: 3.0.0
Source: src/geom/intersects/TriangleToCircle.js (Line 10)
Returns:

true if the Triangle and the Circle intersect, otherwise false.

Type
boolean

<static> TriangleToLine(triangle, line)

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 Description
triangle Phaser.Geom.Triangle

The Triangle to check with.

line Phaser.Geom.Line

The Line to check with.

Since: 3.0.0
Source: src/geom/intersects/TriangleToLine.js (Line 9)
Returns:

true if the Triangle and the Line intersect, otherwise false.

Type
boolean

<static> TriangleToTriangle(triangleA, triangleB)

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 Description
triangleA Phaser.Geom.Triangle

The first Triangle to check for intersection.

triangleB Phaser.Geom.Triangle

The second Triangle to check for intersection.

Since: 3.0.0
Source: src/geom/intersects/TriangleToTriangle.js (Line 11)
Returns:

true if the Triangles intersect, otherwise false.

Type
boolean