# Math Related Objects

Summary
 Math Related Objects Vector2 The Vector2 object. Local Variables x The x coordinate. y The y coordinate. Initialization Vector2 Vector2(Vector2) Vector2(x,y) Member Functions Length Normalize Dot Cross Operators Assignment Operator =Vector2 Addition Operator +Vector2 Subtraction Operator -Vector2 Multiply Operator *number Division Operator *number Equality Operator ==Vector2 Inequality Operator !=Vector2 Rect The Rect object. Local Variables left The left coordinate. top The top coordinate. right The right coordinate. bottom The bottom coordinate. Initialization Rect Rect(Rect) Rect(left,top,right,bottom) Member Functions GetWidth GetHeight IsOverlapped IsInside CalculateUnion CalculateCombined Operators Addition Operator +Rect Subtraction Operator -Rect Rectf The Rectf object. Local Variables left The left coordinate. top The top coordinate. right The right coordinate. bottom The bottom coordinate. Initialization Rectf Rectf(Rectf) Rectf(left,top,right,bottom) Member Functions GetWidth GetHeight IsOverlapped IsInside CalculateUnion CalculateCombined Operators Addition Operator +Rectf Subtraction Operator -Rectf

## Vector2

The Vector2 object.

Most functions in Novashell take a Vector2 instead of an x and y separately.

#### Usage

`vPos = Vector2(5,5);vPos = vPos + (vPos*2);LogMsg("Hey, vPos is " .. tostring(vPos) .. " and the length is " .. vPos:Length());//Output is "Hey, vPos is X:15.00 Y: 15.00 and the length is 21.21320343076"vPos.x = vPos.x/1.54; //let's only modify the x coordinateLogMsg("My god, vPos.x is " .. vPos.x);//Output is "My god, vPos.x is 9.7402601242065"//Let's turn it into a unit vectorvPos.Normalize();`

#### Note

If you use tostring() to show a Vector2, it is formatted and truncated to two decimal points for display.  Internally it’s still double accuracy, like all all Lua numbers.

Summary
 Local Variables x The x coordinate. y The y coordinate. Initialization Vector2 Vector2(Vector2) Vector2(x,y) Member Functions Length Normalize Dot Cross Operators Assignment Operator =Vector2 Addition Operator +Vector2 Subtraction Operator -Vector2 Multiply Operator *number Division Operator *number Equality Operator ==Vector2 Inequality Operator !=Vector2

### x

The x coordinate.

### y

The y coordinate.

### Vector2

`Vector2()`

Defaults to 0,0 if initialized with no parameters.

### Vector2(Vector2)

`Vector2(Vector2 vSomeVec)`

A Vector2 can be initialized with the values from another Vector2 object.

### Vector2(x,y)

`Vector2(number x, number, y)`

A Vector2 can be initialized with a standard x and y passed in separately.

So anytime a function asks for a Vector2 and you don’t have one, keep in mind you can always just type Vector2(x,y).  (Replacing x and y with the numbers you want.)

### Length

`number Length()`

#### Returns

The length of the vector.

### Normalize

`number Normalize()`

Turns the vector into a unit vector.

### Dot

`number Dot(Vector2 vVec)`

#### Returns

The dot product of the operation.

### Cross

`Vector2 Cross()`

#### Returns

The cross product of the vector.

### Assignment Operator

=Vector2

#### Example of assignment

`newVec = oldVec`

+Vector2

`vPos = vPos + Vector2(1,1); //add 1 to x and y in the vPos vector`

### Subtraction Operator

-Vector2

#### Example of subtraction

`vPos = vPos - Vector2(1,0); //remove 1 from vPos's x coordinate`

### Multiply Operator

*number

#### Example of scaler multiplication

`vPos = Vector(1,2);vPos = vPos * 10;  //vPos.x is now 10, vPos.y is now 20.`

### Division Operator

*number

#### Example of scaler division

`vPos = Vector(1,0);vPos = vPos /2;  //vPos.x is now 0.5, vPos.y is still 0 of course.`

### Equality Operator

==Vector2

#### Example of using the equality operator

`if (vPos == vYourPos) then LogMsg("They are the same"); end;`

### Inequality Operator

!=Vector2

#### Example of using the inequality operator

`if (vPos != vYourPos) then LogMsg("By jove, these are different"); end;`

## Rect

The Rect object.  Holds only whole integer numbers, no decimal points allowed.

Summary
 Local Variables left The left coordinate. top The top coordinate. right The right coordinate. bottom The bottom coordinate. Initialization Rect Rect(Rect) Rect(left,top,right,bottom) Member Functions GetWidth GetHeight IsOverlapped IsInside CalculateUnion CalculateCombined Operators Addition Operator +Rect Subtraction Operator -Rect

### left

The left coordinate.

### top

The top coordinate.

### right

The right coordinate.

### bottom

The bottom coordinate.

### Rect

`Rect()`

Defaults to all zeroes if initialized with no parameters.

### Rect(Rect)

`Rect(Rect vSomeRect)`

A Rect can be initialized with the values from another Rect object.

### Rect(left,top,right,bottom)

`Rect(number left, number top, number right, number bottom)`

A Rect can be initialized with four numbers.

### GetWidth

`number GetWidth()`

#### Returns

The actual width of the rect.

### GetHeight

`number GetHeight()`

#### Returns

The actual height of the rect.

### IsOverlapped

`boolean IsOverlapped(Rect rectB)`

#### Returns

True if the two rectangles overlap at all.

### IsInside

`boolean IsInside(Vector2 v)`

#### Returns

True if the vector is located inside the rectangle.

### CalculateUnion

`Rect CalculateUnion(Rect rectB)`

#### Returns

A Rect of the exact size of the union.

### CalculateCombined

`Rect CalculateCombined(Rect rectB)`

#### Returns

A Rect of the area required to enclose both the original and passed in rectangle.

### Operators

+Rect

#### Usage

`rectArea = rectHouse + Rect(100,0,0,0); //we added 100 to rectArea.left`

### Subtraction Operator

-Rect

#### Usage

`rectArea = rectHouse - rectAreaToRemove;`

## Rectf

The Rectf object.  This version supports fractions and decimal points.

Summary
 Local Variables left The left coordinate. top The top coordinate. right The right coordinate. bottom The bottom coordinate. Initialization Rectf Rectf(Rectf) Rectf(left,top,right,bottom) Member Functions GetWidth GetHeight IsOverlapped IsInside CalculateUnion CalculateCombined Operators Addition Operator +Rectf Subtraction Operator -Rectf

### left

The left coordinate.

### top

The top coordinate.

### right

The right coordinate.

### bottom

The bottom coordinate.

### Rectf

`Rectf()`

Defaults to all zeroes if initialized with no parameters.

### Rectf(Rectf)

`Rectf(Rectf vSomeRectf)`

A Rectf can be initialized with the values from another Rectf object.

### Rectf(left,top,right,bottom)

`Rectf(number left, number top, number right, number bottom)`

A Rectf can be initialized with four numbers.

### GetWidth

`number GetWidth()`

#### Returns

The actual width of the Rectf.

### GetHeight

`number GetHeight()`

#### Returns

The actual height of the Rectf.

### IsOverlapped

`boolean IsOverlapped(Rectf RectfB)`

#### Returns

True if the two Rectfangles overlap at all.

### IsInside

`boolean IsInside(Vector2 v)`

#### Returns

True if the vector is located inside the rectangle.

### CalculateUnion

`Rectf CalculateUnion(Rectf RectfB)`

#### Returns

A Rectf the exact size of the union.

### CalculateCombined

`Rectf CalculateCombined(Rectf rectB)`

#### Returns

A Rectf of the area required to enclose both the original and passed in rectangle.

### Operators

+Rectf

#### Usage

`RectfArea = RectfHouse + Rectf(100,0,0,0); //we added 100 to RectfArea.left`

### Subtraction Operator

-Rectf

#### Usage

`RectfArea = RectfHouse - RectfAreaToRemove;`