Summary: Ctors | Methods | Inherited Methods | [Expand All]
public class

# Rect

extends Object
implements AutoCloseable

java.lang.Object
↳ | com.pdftron.pdf.Rect

## Class Overview

Rect is a utility class used to manipulate PDF rectangle objects (refer to section 3.8.3 of the PDF Reference Manual). Rect can be associated with a SDF/Cos rectangle array using Rect(Obj*) constructor or later using Rect::Attach(Obj*) or Rect::Update(Obj*) methods. Rect keeps a local cache for rectangle points so it is necessary to call Rect::Update() method if the changes to the Rect should be saved in the attached Cos/SDF array.

Note: - Although rectangles are conventionally specified by their lower-left and upperright corners, it is acceptable to specify any two diagonally opposite corners.

## Summary

Public Constructors
| Rect() Instantiate Rect with size 0.
| Rect(Obj rect) Create a Rect and initialize it using given Cos/SDF rectangle Array object.
| Rect(double x1, double y1, double x2, double y2) Create a Rect and initialize it using specified parameters.
| Rect(Rectangle2D.Double r) Instantiates a new rect from java Rectangle object

Public Methods
static Rect | __Create(long impl)
long | __GetHandle()
void | attach(Obj rect) Attach the Cos/SDF object to the Rect.
void | close() Frees the native memory of the object.
boolean | contains(double x, double y) Determines if the specified point is contained within the rectangular region defined by this Rectangle.
void | destroy() Frees the native memory of the object.
boolean | equals(Object other)
double[] | get() Get the rectangle coordinates
double | getHeight() Get the height of rectangle
Rectangle2D.Double | getRectangle() Converts the rectangle to java.awt.geom.Rectangle2D
double | getWidth() Get the width of rectangle
double | getX1() Get the x coordinate of the lower-left point
double | getX2() Get the x coordinate of the upper-right point
double | getY1() Get the y coordinate of the lower-left point
double | getY2() Get the y coordinate of the upper-right point
int | hashCode()
void | inflate(double amount) Expands the rectangle by the specified amount, in all directions.
void | inflate(double x, double y) Expands the rectangle by the specified amount in specifed direction
boolean | intersectRect(Rect rect1, Rect rect2) check if two rectangles intersect Note: The intersection is the largest rectangle contained in both existing rectangles.
void | normalize() Normalizes the rectagle to the one with lower-left and upper-right corners.
void | set(Rectangle2D.Double r) Set the coordinates of the rectangle from jave Rectangle2D object
void | set(double x1, double y1, double x2, double y2) Set the coordinates of the rectangle.
void | setX1(double x1) Set the x coordinate of the lower-left point
void | setX2(double x2) Set the x coordinate of the upper-right point
void | setY1(double y1) Set the y coordinate of the lower-left point
void | setY2(double y2) Set the y coordinate of the upper-right point`
boolean | update(Obj rect) Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.
boolean | update() Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.

[Expand] Inherited Methods
From class java.lang.Object
boolean | equals(Object arg0)
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()
From interface java.lang.AutoCloseable
abstract void | close()

## Public Constructors

#### public Rect ()

Instantiate Rect with size 0.

##### Throws

PDFNetException |

#### public Rect (Obj rect)

Create a Rect and initialize it using given Cos/SDF rectangle Array object. The rect is attached to this object.

##### Parameters

rect | the rect

##### Throws

PDFNetException |

#### public Rect (double x1, double y1, double x2, double y2)

Create a Rect and initialize it using specified parameters. The rect is not attached to any Cos/SDF object.

##### Parameters

x1 | x coordinate of the lower-left point
y1 | y coordinate of the lower-left point
x2 | x coordinate of the upper-right point
y2 | y coordinate of the upper-right point

##### Throws

PDFNetException |

#### public Rect (Rectangle2D.Double r)

Instantiates a new rect from java Rectangle object

##### Parameters

r | the rectangle object

##### Throws

PDFNetException |

## Public Methods

#### public static Rect __Create (long impl)

#### public long __GetHandle ()

#### public void attach (Obj rect)

Attach the Cos/SDF object to the Rect.

##### Parameters

rect | - underlying Cos/SDF object. Must be an SDF::Array with four SDF::Number elements.

##### Throws

PDFNetException |

#### public void close ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

##### Throws

PDFNetException |

#### public boolean contains (double x, double y)

Determines if the specified point is contained within the rectangular region defined by this Rectangle.

##### Parameters

x | x coordinate of the point
y | y coordinate of the point

##### Returns

- true is the point is in the rectangle, false otherwise.

##### Throws

PDFNetException |

#### public void destroy ()

Frees the native memory of the object. This can be explicitly called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

#### public boolean equals (Object other)

#### public double[] get ()

Get the rectangle coordinates

##### Returns

- Rectangle coordinates in an array of doubles.

##### Throws

PDFNetException |

#### public double getHeight ()

Get the height of rectangle

##### Returns

- rectangle's height

##### Throws

PDFNetException |

#### public Rectangle2D.Double getRectangle ()

Converts the rectangle to java.awt.geom.Rectangle2D

##### Returns

- the rectangle from this object.

##### Throws

PDFNetException |

#### public double getWidth ()

Get the width of rectangle

##### Returns

- rectangle's width

##### Throws

PDFNetException |

#### public double getX1 ()

Get the x coordinate of the lower-left point

##### Returns

- x coordinate of the lower-left point

##### Throws

PDFNetException |

#### public double getX2 ()

Get the x coordinate of the upper-right point

##### Returns

- x coordinate of the upper-right point

##### Throws

PDFNetException |

#### public double getY1 ()

Get the y coordinate of the lower-left point

##### Returns

- y coordinate of the lower-left point

##### Throws

PDFNetException |

#### public double getY2 ()

Get the y coordinate of the upper-right point

##### Returns

- y coordinate of the upper-right point

##### Throws

PDFNetException |

#### public int hashCode ()

#### public void inflate (double amount)

Expands the rectangle by the specified amount, in all directions.

##### Parameters

amount | the amount to expand

#### public void inflate (double x, double y)

Expands the rectangle by the specified amount in specifed direction

##### Parameters

x | Specifies the amount to increase the rectangle's Left (x1) and Right (x2) properties.
y | Specifies the amount to increase the rectangle's Top (y1) and Bottom (y1) properties.

#### public boolean intersectRect (Rect rect1, Rect rect2)

check if two rectangles intersect

Note: The intersection is the largest rectangle contained in both existing rectangles.

##### Parameters

rect1 | - A Rect object that contains a source rectangle.
rect2 | - A Rect object that contains a source rectangle.

##### Returns

- true if the intersection is not empty; false if the intersection is empty.

##### Throws

PDFNetException |

#### public void normalize ()

Normalizes the rectagle to the one with lower-left and upper-right corners.

Note: Although rectangles are conventionally specified by their lower-left and upper-right corners, it is acceptable to specify any two diagonally opposite corners.

##### Throws

PDFNetException |

#### public void set (Rectangle2D.Double r)

Set the coordinates of the rectangle from jave Rectangle2D object

##### Parameters

r | the rectangle object

##### Throws

PDFNetException |

#### public void set (double x1, double y1, double x2, double y2)

Set the coordinates of the rectangle.

##### Parameters

x1 | x coordinate of the lower-left point
y1 | y coordinate of the lower-left point
x2 | x coordinate of the upper-right point
y2 | y coordinate of the upper-right point

##### Throws

PDFNetException |

#### public void setX1 (double x1)

Set the x coordinate of the lower-left point

##### Parameters

x1 | x coordinate of the lower-left point

##### Throws

PDFNetException |

#### public void setX2 (double x2)

Set the x coordinate of the upper-right point

##### Parameters

x2 | x coordinate of the upper-right point

##### Throws

PDFNetException |

#### public void setY1 (double y1)

Set the y coordinate of the lower-left point

##### Parameters

y1 | y coordinate of the lower-left point

##### Throws

PDFNetException |

#### public void setY2 (double y2)

Set the y coordinate of the upper-right point`

##### Parameters

y2 | y coordinate of the upper-right point`

##### Throws

PDFNetException |

#### public boolean update (Obj rect)

Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.

##### Parameters

rect | - an SDF array that should be updated and attached to this Rect. If parameter rect is NULL or is omitted, update is performed on previously attached Cos/SDF rectangle.

##### Returns

- true if the attached Cos/SDF rectangle array was successfully updated, false otherwise.

##### Throws

PDFNetException |

#### public boolean update ()

Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.

##### Returns

- true if the attached Cos/SDF rectangle array was successfully updated, false otherwise.

##### Throws

PDFNetException |