PokéRogue
    Preparing search index...

    A Triangle is a closed polygon defined by three vertices in 2D space, useful for hit testing, defining spawn or trigger regions, and geometric calculations. It is a geometry object only — not a Game Object — and cannot be rendered directly. To draw a Triangle to the screen, pass it to a Graphics Game Object's strokeTriangleShape or fillTriangleShape method.

    The three vertices are stored as coordinate pairs (x1,y1), (x2,y2), and (x3,y3). All coordinates default to 0 if not provided.

    Index
    • Parameters

      • Optionalx1: number

        x coordinate of the first point. Default 0.

      • Optionaly1: number

        y coordinate of the first point. Default 0.

      • Optionalx2: number

        x coordinate of the second point. Default 0.

      • Optionaly2: number

        y coordinate of the second point. Default 0.

      • Optionalx3: number

        x coordinate of the third point. Default 0.

      • Optionaly3: number

        y coordinate of the third point. Default 0.

      Returns Triangle

    bottom: number

    Bottom most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly.

    left: number

    Left most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly.

    right: number

    Right most X coordinate of the triangle. Setting it moves the triangle on the X axis accordingly.

    top: number

    Top most Y coordinate of the triangle. Setting it moves the triangle on the Y axis accordingly.

    type: number

    The geometry constant type of this object: GEOM_CONST.TRIANGLE. Used for fast type comparisons.

    x1: number

    x coordinate of the first point.

    x2: number

    x coordinate of the second point.

    x3: number

    x coordinate of the third point.

    y1: number

    y coordinate of the first point.

    y2: number

    y coordinate of the second point.

    y3: number

    y coordinate of the third point.

    • Checks whether a given point lies within the triangle.

      Parameters

      • x: number

        The x coordinate of the point to check.

      • y: number

        The y coordinate of the point to check.

      Returns boolean

      true if the coordinate pair is within the triangle, otherwise false.

    • Returns a Line object that corresponds to Line A of this Triangle, running from vertex 1 (x1, y1) to vertex 2 (x2, y2).

      Type Parameters

      Parameters

      • Optionalline: O

        A Line object to set the results in. If undefined a new Line will be created.

      Returns O

      A Line object that corresponds to line A of this Triangle.

    • Returns a Line object that corresponds to Line B of this Triangle, running from vertex 2 (x2, y2) to vertex 3 (x3, y3).

      Type Parameters

      Parameters

      • Optionalline: O

        A Line object to set the results in. If undefined a new Line will be created.

      Returns O

      A Line object that corresponds to line B of this Triangle.

    • Returns a Line object that corresponds to Line C of this Triangle, running from vertex 3 (x3, y3) back to vertex 1 (x1, y1), closing the shape.

      Type Parameters

      Parameters

      • Optionalline: O

        A Line object to set the results in. If undefined a new Line will be created.

      Returns O

      A Line object that corresponds to line C of this Triangle.

    • Returns a point at a given normalized position along the perimeter of the triangle.

      Type Parameters

      Parameters

      • position: number

        Position as float within 0 and 1. 0 equals the first point.

      • Optionaloutput: O

        Optional Vector2 point that the calculated point will be written to.

      Returns O

      Calculated Vector2 that represents the requested position. It is the same as output when this parameter has been given.

    • Calculates a list of evenly distributed points along the perimeter of the triangle. Either pass the number of points to generate (quantity) or the distance between consecutive points (stepRate).

      Type Parameters

      Parameters

      • quantity: number

        Number of points to be generated. Can be falsey when stepRate should be used. All points have the same distance along the triangle.

      • OptionalstepRate: number

        Distance between two points. Will only be used when quantity is falsey.

      • Optionaloutput: O

        Optional array of Vector2 points for writing the calculated points into. Otherwise a new array will be created.

      Returns O

      Returns a list of calculated Vector2 instances or the filled array passed as parameter output.

    • Returns a random point from within the area of the triangle.

      Type Parameters

      Parameters

      • Optionalvec: Vector2

        Optional Vector2 point that will be modified. Otherwise a new one will be created.

      Returns O

      Random Vector2. When parameter vec has been provided it will be returned.

    • Sets all three points of the triangle. Leaving out any coordinate sets it to be 0.

      Parameters

      • Optionalx1: number

        x coordinate of the first point. Default 0.

      • Optionaly1: number

        y coordinate of the first point. Default 0.

      • Optionalx2: number

        x coordinate of the second point. Default 0.

      • Optionaly2: number

        y coordinate of the second point. Default 0.

      • Optionalx3: number

        x coordinate of the third point. Default 0.

      • Optionaly3: number

        y coordinate of the third point. Default 0.

      Returns this

      This Triangle object.

    • Returns the area of a Triangle.

      Parameters

      • triangle: Triangle

        The Triangle to use.

      Returns number

      The area of the Triangle, always non-negative.

    • 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

      • x: number

        x coordinate of the top point of the triangle.

      • y: number

        y coordinate of the top point of the triangle.

      • length: number

        Length of each side of the triangle.

      Returns Triangle

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

    • 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.

      Type Parameters

      Parameters

      • data: any[]

        A flat array of vertex coordinates like [x0,y0, x1,y1, x2,y2, ...]

      • Optionalholes: any[]

        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). Default null.

      • OptionalscaleX: number

        Horizontal scale factor to multiply the resulting points by. Default 1.

      • OptionalscaleY: number

        Vertical scale factor to multiply the resulting points by. Default 1.

      • Optionalout: O

        An array to store the resulting Triangle instances in. If not provided, a new array is created.

      Returns O

      An array of Triangle instances, where each triangle is based on the decomposed vertices data.

    • 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

      • x: number

        The X coordinate of the right angle, which will also be the first X coordinate of the constructed Triangle.

      • y: number

        The Y coordinate of the right angle, which will also be the first Y coordinate of the constructed Triangle.

      • width: number

        The length of the side which is to the left or to the right of the right angle.

      • height: number

        The length of the side which is above or below the right angle. If not given, defaults to the value of width.

      Returns Triangle

      The constructed right Triangle.

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

      Type Parameters

      Parameters

      • triangle: O

        The triangle to be positioned.

      • x: number

        The horizontal coordinate to center on.

      • y: number

        The vertical coordinate to center on.

      • OptionalcenterFunc: CenterFunction

        The function used to center the triangle. Defaults to Centroid centering.

      Returns O

      The Triangle that was centered.

    • 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.

      Type Parameters

      Parameters

      • triangle: Triangle

        The Triangle to use.

      • Optionalout: O

        A Vector2 object to store the coordinates in.

      Returns O

      The out object with modified x and y properties, or a new Vector2 if none was provided.

    • 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

      Type Parameters

      Parameters

      • triangle: Triangle

        The Triangle to get the circumcenter of.

      • Optionalout: O

        The Vector2 object to store the position in. If not given, a new Vector2 instance is created.

      Returns O

      A Vector2 object holding the coordinates of the circumcenter of the Triangle.

    • 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

      Type Parameters

      Parameters

      • triangle: Triangle

        The Triangle to use as input.

      • Optionalout: O

        An optional Circle to store the result in.

      Returns O

      The updated out Circle, or a new Circle if none was provided.

    • Clones a Triangle object.

      Parameters

      • source: Triangle

        The Triangle to clone.

      Returns Triangle

      A new Triangle identical to the given one but separate from it.

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

      Parameters

      • triangle: Triangle

        The Triangle to check.

      • x: number

        The X coordinate of the point to check.

      • y: number

        The Y coordinate of the point to check.

      Returns boolean

      true if the point is inside the Triangle, otherwise false.

    • 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

      • triangle: Triangle

        The triangle that the points are being checked in.

      • points: Vector2[]

        An array of Vector2 objects to check if they are within the triangle.

      • OptionalreturnFirst: boolean

        If true, return an array containing only the first point found that is within the triangle. Default false.

      • Optionalout: any[]

        If 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 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.

    • Tests if a triangle contains a point.

      Parameters

      • triangle: Triangle

        The triangle.

      • vec: Vector2

        The Vector2 point to test if it's within the triangle.

      Returns boolean

      true if the point is within the triangle, otherwise false.

    • Copy the values of one Triangle to a destination Triangle.

      Type Parameters

      Parameters

      • source: Triangle

        The source Triangle to copy the values from.

      • dest: O

        The destination Triangle to copy the values to.

      Returns O

      The destination Triangle.

    • Decomposes a Triangle into an array of its points.

      Parameters

      • triangle: Triangle

        The Triangle to decompose.

      • Optionalout: any[]

        An array to store the points into.

      Returns any[]

      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.

    • Returns true if two triangles have the same coordinates.

      Parameters

      • triangle: Triangle

        The first triangle to check.

      • toCompare: Triangle

        The second triangle to check.

      Returns boolean

      true if the two given triangles have the exact same coordinates, otherwise false.

    • 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.

      Type Parameters

      Parameters

      • triangle: Triangle

        The Triangle to get the point on its perimeter from.

      • position: number

        A normalized value between 0 and 1 representing a position along the triangle's perimeter. Both 0 and 1 return the start of line A.

      • Optionalout: O

        An optional Vector2 point to store the result in. If not given, a new Vector2 will be created.

      Returns O

      A Vector2 point containing the coordinates of the position on the triangle's perimeter.

    • 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.

      Type Parameters

      Parameters

      • triangle: Triangle

        The Triangle to get the points from.

      • quantity: number

        The number of evenly spaced points to return. Set to 0 to return an arbitrary number of points based on the stepRate.

      • stepRate: number

        If quantity is 0, the distance in pixels between each returned point along the perimeter.

      • Optionalout: O

        An array to which the points should be appended.

      Returns O

      The modified out array, or a new array if none was provided.

    • 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.

      Type Parameters

      Parameters

      • triangle: Triangle

        The Triangle to find the incenter of.

      • Optionalout: O

        An optional Vector2 point in which to store the coordinates.

      Returns O

      The incenter of the triangle in a Vector2.

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

      Type Parameters

      Parameters

      • triangle: O

        The Triangle to move.

      • x: number

        The horizontal offset (distance) by which to move each point. Can be positive or negative.

      • y: number

        The vertical offset (distance) by which to move each point. Can be positive or negative.

      Returns O

      The modified Triangle.

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

      Parameters

      • triangle: Triangle

        The Triangle to get the length from.

      Returns number

      The length of the Triangle.

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

      Type Parameters

      Parameters

      • triangle: Triangle

        The Triangle to get a random point from.

      • Optionalout: O

        The Vector2 point object to store the position in. If not given, a new Vector2 instance is created.

      Returns O

      A Vector2 point object holding the coordinates of a random position within the Triangle.

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

      Type Parameters

      Parameters

      • triangle: O

        The Triangle to rotate.

      • angle: number

        The angle by which to rotate the Triangle, in radians.

      Returns O

      The rotated Triangle.

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

      Type Parameters

      Parameters

      • triangle: O

        The Triangle to rotate.

      • point: Vector2

        The Vector2 point to rotate the Triangle around.

      • angle: number

        The angle by which to rotate the Triangle, in radians.

      Returns O

      The rotated Triangle.

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

      Type Parameters

      Parameters

      • triangle: O

        The Triangle to rotate.

      • x: number

        The X coordinate of the point to rotate the Triangle about.

      • y: number

        The Y coordinate of the point to rotate the Triangle about.

      • angle: number

        The angle by which to rotate the Triangle, in radians.

      Returns O

      The rotated Triangle.