Class

# Rect

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

A way to represent an axis-aligned rectangular area. <span class="title-ref">Rect</span> can be used for window size/position, control size/position and drawing of controls.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                      | Type                             | Read-Only | Shared |
|-------------------------------------------|----------------------------------|-----------|--------|
| `Bottom<rect.bottom>`                     | `Double</api/data_types/double>` |           |        |
| `Center<rect.center>`                     | `Point</api/graphics/point>`     |           |        |
| `Height<rect.height>`                     | `Double</api/data_types/double>` |           |        |
| `HorizontalCenter<rect.horizontalcenter>` | `Double</api/data_types/double>` |           |        |
| `Left<rect.left>`                         | `Double</api/data_types/double>` |           |        |
| `Origin<rect.origin>`                     | `Point</api/graphics/point>`     |           |        |
| `Right<rect.right>`                       | `Double</api/data_types/double>` |           |        |
| `Size<rect.size>`                         | `Size</api/graphics/size>`       |           |        |
| `Top<rect.top>`                           | `Double</api/data_types/double>` |           |        |
| `VerticalCenter<rect.verticalcenter>`     | `Double</api/data_types/double>` |           |        |
| `Width<rect.width>`                       | `Double</api/data_types/double>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                    | Parameters                                                                                                                                                          | Returns                            | Shared |
|-----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `Clone<rect.clone>`                     |                                                                                                                                                                     | Rect                               |        |
| `Constructor<rect.constructor0>`        | X As `Double</api/data_types/double>`, Y As `Double</api/data_types/double>`, Width As `Double</api/data_types/double>`, Height As `Double</api/data_types/double>` |                                    |        |
| `Constructor<rect.constructor1>`        | origin As `Point</api/graphics/point>`, size As `Size</api/graphics/size>`                                                                                          |                                    |        |
| `Contains<rect.contains>`               | x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`                                                                                        | `Boolean</api/data_types/boolean>` |        |
|                                         | p As `Point</api/graphics/point>`                                                                                                                                   | `Boolean</api/data_types/boolean>` |        |
|                                         | other As <span class="title-ref">Rect</span>                                                                                                                        | `Boolean</api/data_types/boolean>` |        |
| `Intersection<rect.intersection>`       | Other As Rect                                                                                                                                                       | Rect                               |        |
| `Intersects<rect.intersects>`           | Other As Rect                                                                                                                                                       | `Boolean</api/data_types/boolean>` |        |
| `LocalPoint<rect.localpoint>`           | P As `Point</api/graphics/point>`                                                                                                                                   | `Point</api/graphics/point>`       |        |
| `LocalRect<rect.localrect>`             | other As Rect                                                                                                                                                       | Rect                               |        |
| `Offset<rect.offset>`                   | DeltaX As `Double</api/data_types/double>`, DeltaY As `Double</api/data_types/double>`                                                                              |                                    |        |
| `SplitHorizontal<rect.splithorizontal>` | X As `Double</api/data_types/double>`                                                                                                                               | Rect                               |        |
| `SplitVertical<rect.splitvertical>`     | Y As `Double</api/data_types/double>`                                                                                                                               | Rect                               |        |
| `Union<rect.union>`                     | Other As Rect                                                                                                                                                       | Rect                               |        |

## Property descriptions

<div id="rect.bottom">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Bottom

**Bottom** As `Double</api/data_types/double>`

> The bottom edge of the <span class="title-ref">Rect</span> on the Y axis. Changing this value will resize the <span class="title-ref">Rect</span>.
>
> This example enlarges the <span class="title-ref">Rect</span> by 50 points:
>
> ``` xojo
> myRect.Bottom = myRect.Bottom + 50
> ```
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> The value of Bottom is one point beyond the bounds of the <span class="title-ref">Rect</span>.
>
> </div>

<div id="rect.center">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Center

**Center** As `Point</api/graphics/point>`

> The center of the <span class="title-ref">Rect</span>. Changing this value will move the <span class="title-ref">Rect</span>.
>
> This sample works in a Canvas.Paint event. It computes the center of a <span class="title-ref">Rect</span> that represents the union of two rects.
>
> ``` xojo
> Var i, j As Integer
> ' To demonstrate the Union feature, draw a Cyan rectangle
> ' around both the draggable rects.
> Var u As Rect = rectone.Union(recttwo)
> buffer.Graphics.DrawingColor = CyanColor
> buffer.Graphics.DrawRectangle(u.Left, u.Top, u.Width, u.Height)
> theSize = u.Size
> Var theCenter As Point = u.Center
> i = theCenter.X
> j = theCenter.Y
> ```

<div id="rect.height">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Height

**Height** As `Double</api/data_types/double>`

> The height of the <span class="title-ref">Rect</span>.
>
> This example increases the height of rectone by 50 points.
>
> ``` xojo
> myRect.Height = myRect.Height + 50
> ```

<div id="rect.horizontalcenter">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.HorizontalCenter

**HorizontalCenter** As `Double</api/data_types/double>`

> The center of the <span class="title-ref">Rect</span> on the X axis. Changing this value will move the <span class="title-ref">Rect</span>.
>
> This example is in the MouseDrag event. It gets the horizontal and vertical centers of the <span class="title-ref">Rect</span> being dragged.
>
> ``` xojo
> Var i, j As Double
> i = DraggingRect.HorizontalCenter
> j = DraggingRect.VerticalCenter
> ```

<div id="rect.left">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Left

**Left** As `Double</api/data_types/double>`

> The left edge of the <span class="title-ref">Rect</span> on the X axis.
>
> This example moves the <span class="title-ref">Rect</span> to the left by 50 points, keeping its height and width intact.
>
> ``` xojo
> myRect.Left = myRect.Left + 50
> ```

<div id="rect.origin">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Origin

**Origin** As `Point</api/graphics/point>`

> The upper left coordinate of the <span class="title-ref">Rect</span>.
>
> This example is in the MouseDrag event. The position of the <span class="title-ref">Rect</span> being dragged is updated via by reseting the value of the Origin property.
>
> ``` xojo
> ' Update our mouse position.
> mouseposition = New Point(x, y)
>
> ' If we're actually dragging something, move the rect.
> ' We update the rect's origin with a CLONE of the mouse position,
> ' because MousePosition is an instance of the Point class.
> ' Without the clone, when we call the offset function, we'll also update
> ' the MousePosition property, since both DraggingRect.Origin and MousePosition
> ' would point to the same variable.
>
> ' The offset function shifts the rect. Positive for right/down,
> ' negative for left/up.
>
> If draggingrect <> Nil Then
> draggingrect.Origin = mouseposition.Clone
> draggingrect.Offset(mouseoffset.x, mouseoffset.y)
> End If
>
> ' refresh, without erasing the background
> Me.Refresh(False)
> ```

<div id="rect.right">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Right

**Right** As `Double</api/data_types/double>`

> The right edge of the <span class="title-ref">Rect</span> on the X axis. Changing this value will resize the <span class="title-ref">Rect</span>.
>
> This example moves the <span class="title-ref">Rect</span> to the right by 50 points, keeping its height and width intact:
>
> ``` xojo
> myRect.Left = myRect.Left + 50
> ```
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> The value of Right is one point beyond the bounds of the <span class="title-ref">Rect</span>.
>
> </div>

<div id="rect.size">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Size

**Size** As `Size</api/graphics/size>`

> The dimensions of the <span class="title-ref">Rect</span>.
>
> This example is in the Paint event of a project. It computes the Size of the union of two rects.
>
> ``` xojo
> ' To demonstrate the Union feature, we'll draw a Cyan rectangle
> ' around both the draggable rects.
> Var theSize As New Size
> Var u As Rect = rectone.Union(recttwo)
> buffer.Graphics.DrawingColor = CyanColor
> buffer.Graphics.DrawRectangle(u.Left, u.Top, u.Width, u.Height)
> theSize = u.Size
> ```

<div id="rect.top">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Top

**Top** As `Double</api/data_types/double>`

> The top edge of the <span class="title-ref">Rect</span> on the Y axis.
>
> This example is in the Paint event. It computes the top of a <span class="title-ref">Rect</span> that represents the union of two rects.
>
> ``` xojo
> Var i, j As Integer
> ' To demonstrate the Union feature, we'll draw a Cyan rectangle
> ' around both the draggable rects.
> Var u As Rect = rectone.Union(recttwo)
> buffer.Graphics.DrawingColor = CyanColor
> buffer.Graphics.DrawRectangle(u.Left, u.Top, u.Width, u.Height)
> theSize = u.Size
> Var theTop As Point = u.Top
> i = theTop.x
> j = theTop.y
> ```

<div id="rect.verticalcenter">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.VerticalCenter

**VerticalCenter** As `Double</api/data_types/double>`

> The center of the <span class="title-ref">Rect</span> on the Y axis. Changing this value will move the <span class="title-ref">Rect</span>.
>
> This example is in the MouseDrag event. It gets the horizontal and vertical centers of the <span class="title-ref">Rect</span> being dragged.
>
> ``` xojo
> Var i, j As Double
> i = DraggingRect.HorizontalCenter
> j = DraggingRect.VerticalCenter
> ```

<div id="rect.width">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Width

**Width** As `Double</api/data_types/double>`

> The width of the <span class="title-ref">Rect</span>.
>
> This example increases the width by 50 points:
>
> ``` xojo
> myRect.Width = myWidth.Width + 50
> ```

## Method descriptions

<div id="rect.clone">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Clone

**Clone** As Rect

> Creates a duplicate of the <span class="title-ref">Rect</span>.

<div id="rect.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Constructor

**Constructor**(X As `Double</api/data_types/double>`, Y As `Double</api/data_types/double>`, Width As `Double</api/data_types/double>`, Height As `Double</api/data_types/double>`)

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates a <span class="title-ref">Rect</span> object at X,Y and the passed width and height.

<div id="rect.constructor1">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Constructor

**Constructor**(origin As `Point</api/graphics/point>`, size As `Size</api/graphics/size>`)

> Creates a <span class="title-ref">Rect</span> object given the origin and size passed.
>
> Create a <span class="title-ref">Rect</span> at 100, 100 that is 50 tall and 50 wide.
>
> ``` xojo
> Var p As New Point(100, 100)
> Var s As New Size(50, 50)
> Var myRect As New Rect(p, s)
> ```

<div id="rect.contains">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Contains

**Contains**(x As `Double</api/data_types/double>`, y As `Double</api/data_types/double>`) As `Boolean</api/data_types/boolean>`

> `True</api/language/true>` if the <span class="title-ref">Rect</span> contains the point at the x/y coordinates passed.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> If you want to use Contains, make sure to set the *X* and *Y* properties and **do not** pass the these to the `Graphics.DrawObject<graphics.drawobject>` method. `Graphics.DrawObject<graphics.drawobject>` parameters are the offset where the object will be drawn.
>
> </div>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

Rect.Contains

**Contains**(p As `Point</api/graphics/point>`) As `Boolean</api/data_types/boolean>`

> `True</api/language/true>` if the <span class="title-ref">Rect</span> completely contains the `Point</api/graphics/point>` passed.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

Rect.Contains

**Contains**(other As Rect) As `Boolean</api/data_types/boolean>`

> `True</api/language/true>` if the <span class="title-ref">Rect</span> completely contains the *other* <span class="title-ref">Rect</span>.
>
> This Paint event contains code that handles all the cases in which the two rectangles interact. The code uses the Union, Contains, and Intersect methods to detect these conditions and applies a color to the picture, buffer. This code is in the Paint event of the `Canvas</api/user_interface/desktop/desktopcanvas>`.
>
> ``` xojo
> Const RedColor = &cFF0000
> Const GreenColor = &c00FF00
> Const BlueColor = &c0000FF
> Const CyanColor = &c00FFFF
> Const WhiteColor = &cFFFFFF
>
> ' Create a pure white picture, to prevent flicker on Windows.
> Var buffer As New Picture(g.Width, g.Height, 32)
> buffer.Graphics.DrawingColor = WhiteColor
>
> ' To demonstrate the Union feature, we'll draw a Cyan rectangle
> ' around both the draggable rects.
> Var u As Rect = rectOne.Union(rectTwo)
> buffer.Graphics.DrawingColor = CyanColor
> buffer.Graphics.DrawRectangle(u.Left, u.Top, u.Width, u.Height)
>
> ' If the cursor is inside RectOne, and we're not dragging
> ' RectTwo, then we'll use blue. Otherwise, the rect will be red.
> If rectOne.Contains(MousePosition) And DraggingRect <> rectTwo Then
> buffer.Graphics.DrawingColor = BlueColor
> Else
> buffer.Graphics.DrawingColor = RedColor
> End If
> buffer.Graphics.FillRectangle(rectOne.Left, rectOne.Top, rectOne.Width, rectOne.Height)
>
> ' Same as above, but for RectTwo
> If rectTwo.Contains(MousePosition) And DraggingRect <> rectOne Then
> buffer.Graphics.DrawingColor = BlueColor
> Else
> buffer.Graphics.DrawingColor = RedColor
> End If
> buffer.Graphics.FillRectangle(rectTwo.Left, rectTwo.Top, rectTwo.Width, rectTwo.Height)
>
> ' To demonstrate the Intersection feature, we'll draw a green rectangle
> ' where the two draggable rects overlap. The Intersection function will
> ' always return a rect, even if the two provided do not actually intersect.
> ' That's why we use the Intersects function first. Remove the "If" block to
> ' see a neat trick.
> If rectOne.Intersects(rectTwo) Then
> Var r As Rect = rectOne.Intersection(rectTwo)
> buffer.Graphics.DrawingColor = GreenColor
> buffer.Graphics.FillRectangle(r.Left, r.Top, r.Width, r.Height)
> End If
>
> g.DrawPicture(buffer, 0, 0)
> ```

<div id="rect.intersection">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Intersection

**Intersection**(Other As Rect) As Rect

> Returns a new <span class="title-ref">Rect</span> representing the area the two Rects overlap.

<div id="rect.intersects">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Intersects

**Intersects**(Other As Rect) As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the <span class="title-ref">Rect</span> overlaps the passed <span class="title-ref">Rect</span>.

<div id="rect.localpoint">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.LocalPoint

**LocalPoint**(p As `Point</api/graphics/point>`) As `Point</api/graphics/point>`

> Returns a new Point whose coordinates are local to the calling <span class="title-ref">Rect</span>.
>
> ``` xojo
> Var r As New Rect(100, 100, 200, 200)
> Var p As New point(100, 100)
> Var p1 As point = r.LocalPoint(p)
> ```
>
> p1 is 0, 0.

<div id="rect.localrect">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.LocalRect

**LocalRect**(other As Rect) As Rect

> Returns a new <span class="title-ref">Rect</span> whose coordinates are local to the calling <span class="title-ref">Rect</span>.

<div id="rect.offset">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Offset

**Offset**(DeltaX As `Double</api/data_types/double>`, DeltaY As `Double</api/data_types/double>`)

> Moves the point the passed number of points. Positive numbers move the point down or to the right, negative move it up or to the left.
>
> ``` xojo
> Var r As New Rect(100, 100, 200, 200)
> r.OffSet(100, 100)
> ```
>
> r is now at 200, 200. The width and height have not changed.

<div id="rect.splithorizontal">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.SplitHorizontal

**SplitHorizontal**(X As `Double</api/data_types/double>`) As Rect

> Divides the <span class="title-ref">Rect</span> into two rects at the given point on the X axis.
>
> For example, imagine a <span class="title-ref">Rect</span> that is 200 points wide by 100 points tall. With a call to SplitHorizontal(50), the <span class="title-ref">Rect</span> will become 50 points wide, and a new <span class="title-ref">Rect</span> will be returned that is 150x100, positioned exactly to the right of the original <span class="title-ref">Rect</span>.
>
> This example is taken from the Paint event of a `Canvas</api/user_interface/desktop/desktopcanvas>`. It takes a <span class="title-ref">Rect</span> and splits it horizontally at the midpoint of the width.
>
> ``` xojo
> Var uright As Rect = u.SplitHorizontal(theSize.Width / 2)
> ```

<div id="rect.splitvertical">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.SplitVertical

**SplitVertical**(Y As `Double</api/data_types/double>`) As Rect

> Divides the <span class="title-ref">Rect</span> into two rects at the given point on the Y axis.
>
> For example, imagine a <span class="title-ref">Rect</span> that is 200 points wide by 100 points tall. A call to SplitVertical (50) on this <span class="title-ref">Rect</span>, the <span class="title-ref">Rect</span> will become 50 points wide, and a new <span class="title-ref">Rect</span> will be returned that is 150x100, positioned exactly to the top of the original <span class="title-ref">Rect</span>.
>
> This example is taken from the Paint event of a `Canvas</api/user_interface/desktop/desktopcanvas>`. It takes a <span class="title-ref">Rect</span> and splits it horizontally at the midpoint of the height.
>
> ``` xojo
> Var utop As Rect = u.SplitVertical(theSize.Height / 2)
> ```

<div id="rect.union">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Rect.Union

**Union**(Other As Rect) As Rect

> Creates a new <span class="title-ref">Rect</span> containing both rects.

## Notes

If you subclass <span class="title-ref">Rect</span>, there's a comparison operation you should be aware of. Comparing instances of two different subclasses of <span class="title-ref">Rect</span> would seem invalid because they are two different classes. However, this is a valid comparison because the <span class="title-ref">Rect</span> class has an `Operator_Convert</api/language/operators/operator_overloads/operator_convert>` which returns a new instance of the <span class="title-ref">Rect</span> class. Thus despite the fact that two different classes are being compared, both instances being compared are from the same class. The downside to this of course is that what is returned is not an instance of your subclass. To resolve this there are two options. You can use your own class that is not a subclass of <span class="title-ref">Rect</span> or you can override the `Operator_Convert</api/language/operators/operator_overloads/operator_convert>` in your subclasses to return an instance of themselves.

## Sample code

``` xojo
Var myRect As New Rect(10, 10, 100, 50)
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

Object parent class; `DesktopCanvas</api/user_interface/desktop/desktopcanvas>` control; `DesktopWindow</api/user_interface/desktop/desktopwindow>`, `DesktopContainer</api/user_interface/desktop/desktopcontainer>`, `Point</api/graphics/point>`, `Size</api/graphics/size>` classes.

</div>
