Rect
Rect
ui_object.Rect
Axis-aligned rectangle in screen / view coordinates: left, top, right, bottom. Used for widget bounds, hit testing, OCR boxes, etc.
Table of contents
Constructors
Properties
Accessors
Methods
Constructors
constructor
• new Rect(left, top, right, bottom): Rect
Create a rectangle from edge coordinates (not width/height).
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`width: ${rect.width}, height: ${rect.height}`);
console.log(`center: (${rect.centerX}, ${rect.centerY})`);Parameters
| Name | Type | Description |
|---|---|---|
left | number | X of the left edge. |
top | number | Y of the top edge. |
right | number | X of the right edge (exclusive in some APIs—here stored as given). |
bottom | number | Y of the bottom edge. |
Returns
Properties
left
• left: number
Left edge X.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`left: ${rect.left}`);top
• top: number
Top edge Y.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`top: ${rect.top}`);right
• right: number
Right edge X.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`right: ${rect.right}`);bottom
• bottom: number
Bottom edge Y.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`bottom: ${rect.bottom}`);Accessors
width
• get width(): number
right - left.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`width: ${rect.width}`);Returns
number
Width in pixels.
height
• get height(): number
bottom - top.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`height: ${rect.height}`);Returns
number
Height in pixels.
centerX
• get centerX(): number
(left + right) / 2.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`centerX: ${rect.centerX}`);Returns
number
centerY
• get centerY(): number
(top + bottom) / 2.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(10, 20, 100, 200);
console.log(`centerY: ${rect.centerY}`);Returns
number
Methods
sort
▸ sort(): Rect
Normalize edges so left ≤ right and top ≤ bottom by swapping when needed.
Example
"nodejs";
const { Rect } = require("ui_object");
const rect = new Rect(100, 200, 10, 20);
console.log(`before: left=${rect.left}, right=${rect.right}`);
const sortedRect = rect.sort();
console.log(`after: left=${sortedRect.left}, right=${sortedRect.right}`);Returns
A rect with sorted edges (implementation may return this or a new instance).
fromJava
▸ Static fromJava(javaRect): Rect
Wrap an Android android.graphics.Rect (or compatible JNI object).
Example
"nodejs";
const { Rect } = require("ui_object");
const javaRect = /* ... */;
const rect = Rect.fromJava(javaRect);
console.log(`rect: (${rect.left}, ${rect.top}) - (${rect.right}, ${rect.bottom})`);Parameters
| Name | Type | Description |
|---|---|---|
javaRect | any | Java Rect instance. |
