## Libraries.Game.Collision.Shapes.CollisionShape2D Documentation

This class includes the features for all of the 2D shapes that could be used to determine collision with other 2D shapes. Please see the Circle and the Polygon class for the implementation of the blueprints in this class.

*Inherits from: *Libraries.Language.Object

## Summary

### Variable Summary Table

Variables | Description |
---|---|

integer POLYGON | |

integer CHAIN | the default type is POLYGON |

integer EDGE | |

integer CIRCLE |

### Actions Summary Table

Actions | Description |
---|---|

Compare(Libraries.Language.Object object) | This action compares two object hash codes and returns an integer. |

ComputeArea() | This action finds the area of a CollisionShape2D. |

ComputeBoundingBox(Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Game.Collision.PhysicsPosition2D transform, integer childIndex) | When you pass in the location of the 2D object (PhysicsPosition2D transform), this action will help you return what the bounding box "BoundingBox2D boundingBox" will look like for the shape's child #"integer childIndex". |

ComputeDistance(Libraries.Game.Collision.PhysicsPosition2D transform, Libraries.Compute.Vector2 point, integer childIndex, Libraries.Compute.Vector2 normalOut) | This action finds the distance of a point relative to the edge of the shape. |

ComputeMass(Libraries.Game.Physics.Mass2D mass, number density) | This action finds the mass of a 2D object based on the shape of the object and the design of the object. |

Copy() | This action returns a copy of this CollisionShape2D. |

Equals(Libraries.Language.Object object) | This action determines if two objects are equal based on their hash code values. |

GetChildCount() | Child Shape: a more primitive shape (circle, rectangle, edge) that makes up this shape. |

GetHashCode() | This action gets the hash code for an object. |

GetRadius() | This action returns the radius of the shape. |

GetType() | This action gets the type of the shape that is used to collide with another 2D shape. |

Scale(number scaleX, number scaleY) | This action scales the CollisionShape2D in both x and y directions for polygons and scales the a circle uniformly. |

SetRadius(number radius) | This action sets the radius of the shape. |

SetType(integer type) | This action sets the type of the shape that will be used to collide with another 2D shape. |

TestPoint(Libraries.Game.Collision.PhysicsPosition2D transform, Libraries.Compute.Vector2 point) | For convex shapes, this will see if the "Vector2 point," in global coordiantes, that you passed in is a point inside that convex shape. |

## Actions Documentation

### Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

**Example Code**

```
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
```

#### Parameters

- Libraries.Language.Object: The object to compare to.

#### Return

integer: The Compare result, Smaller, Equal, or Larger.

### ComputeArea()

This action finds the area of a CollisionShape2D.

#### Return

number:

### ComputeBoundingBox(Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Game.Collision.PhysicsPosition2D transform, integer childIndex)

When you pass in the location of the 2D object (PhysicsPosition2D transform), this action will help you return what the bounding box "BoundingBox2D boundingBox" will look like for the shape's child #"integer childIndex".

#### Parameters

- Libraries.Game.Collision.BoundingBox2D: The bounding box for the child shape will be returned through this parameter.
- Libraries.Game.Collision.PhysicsPosition2D: The position and tilt of the 2D shape relative to the global coordinates.
- integer childIndex: The child shape number.

### ComputeDistance(Libraries.Game.Collision.PhysicsPosition2D transform, Libraries.Compute.Vector2 point, integer childIndex, Libraries.Compute.Vector2 normalOut)

This action finds the distance of a point relative to the edge of the shape.

#### Parameters

- Libraries.Game.Collision.PhysicsPosition2D: The tilt and the position of the shape.
- Libraries.Compute.Vector2: The point of interest.
- integer childIndex: This parameter is not relevant for the Circle and Polygon class.
- Libraries.Compute.Vector2: The normal vector pointing from the center of the shape to the point of interest.

#### Return

number:

### ComputeMass(Libraries.Game.Physics.Mass2D mass, number density)

This action finds the mass of a 2D object based on the shape of the object and the design of the object.

#### Parameters

- Libraries.Game.Physics.Mass2D: The mass data computed for this object will be returned through this parameter.

### Copy()

This action returns a copy of this CollisionShape2D.

#### Return

Libraries.Game.Collision.Shapes.CollisionShape2D:

### Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

**Example Code**

```
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
```

#### Parameters

- Libraries.Language.Object: The to be compared.

#### Return

boolean: True if the hash codes are equal and false if they are not equal.

### GetChildCount()

Child Shape: a more primitive shape (circle, rectangle, edge) that makes up this shape.

#### Return

integer:

### GetHashCode()

This action gets the hash code for an object.

**Example Code**

```
Object o
integer hash = o:GetHashCode()
```

#### Return

integer: The integer hash code of the object.

### GetRadius()

This action returns the radius of the shape.

#### Return

number:

### GetType()

This action gets the type of the shape that is used to collide with another 2D shape.

#### Return

integer:

### Scale(number scaleX, number scaleY)

This action scales the CollisionShape2D in both x and y directions for polygons and scales the a circle uniformly.

#### Parameters

- number scaleX: How much you want to squeeze the circle or polygon in x direction.
- number scaleY: How much you want to squeeze the polygon in the y direction.

### SetRadius(number radius)

This action sets the radius of the shape.

#### Parameters

### SetType(integer type)

This action sets the type of the shape that will be used to collide with another 2D shape.

#### Parameters

### TestPoint(Libraries.Game.Collision.PhysicsPosition2D transform, Libraries.Compute.Vector2 point)

For convex shapes, this will see if the "Vector2 point," in global coordiantes, that you passed in is a point inside that convex shape.

#### Parameters

- Libraries.Game.Collision.PhysicsPosition2D: The position and tilt of the 2D shape relative to the global coodinates.
- Libraries.Compute.Vector2: The point of interest in global coordinates.

#### Return

boolean: