Floats to Rect
Build a Rectangle From Any Two Corners
- tinyrect
Rectangle math is a whole sub-ecosystem inside ComfyUI these days - region prompts, inpaint boxes, detection results - and every rectangle family has its own wire type. TinyBee's is TINYRECT, a simple (x, y, width, height) tuple, and Floats to Rect is the node that constructs one from raw numbers. It's the entry point to the pack's whole Rectangles category, and it's more flexible than the "just type x, y, w, h" first impression suggests.
How it works
The inputs are x, y, w, h (top-left plus size) and x2, y2 (bottom-right corner). You don't have to fill all of them - the node only uses what you actually set. That's what nanValue is for: any input equal to nanValue (default -1) counts as "not set." So leaving x2 and y2 at -1 means "I only gave you the top-left and size," and the node computes the rect straight from those.
The resolution rules, in priority order:
- If you supplied
xandw, it uses(x, y, w, h)as-is. - If you supplied
xandx2instead, width is derived:x2 - x. - If you supplied
wandx2, it back-computesx = x2 - w.
Same logic applies to the vertical axis. So you can define a rect by top-left + size, by two corners, or by right-edge + width - whatever your upstream node happens to hand you. That's genuinely handy when one detector gives you bounding boxes as corners and another gives them as origin + dimensions.
The output is a single tinyrect in (x, y, w, h) form, ready to feed Intersect Rects, Draw TinyRect, Rect To Mask, or the aspect-math nodes in the same pack.
Where you'd actually use it
- Inpaint/region setup: build a box from coordinates, then use TinyBee's Rect To Mask to turn it into a mask for an inpaint pass.
- Bridging detector output: convert two-corner boxes (common from object detectors) into the x/y/w/h form the rest of the pack expects.
- Manual layout: type four numbers instead of fiddling with a mask editor.
Installing it
Standard TinyBee install - this sits in 🐝TinyBee/Casting of ComfyUI-TinyBee:
- ComfyUI Manager → Install Custom Nodes → search "ComfyUI-TinyBee" → Install, then restart ComfyUI.
cd ComfyUI/custom_nodes
git clone https://github.com/TinyBeeman/ComfyUI-TinyBee
Restart. No models, no dependencies - pure arithmetic. (The pack's requirements.txt lists pillow and jsonata; neither is involved here.)
Gotchas
Two things. First, nanValue is the sentinel, and the default is -1 - so a legitimately negative coordinate (say x = -2 to extend past the left edge) would be treated as "unset" and silently dropped to 0. Change nanValue if your coordinates can be negative. Second, if you set nothing useful on an axis - only x and y, say - the width and height come out as 0, which downstream rect nodes may or may not handle gracefully. And remember this node takes floats; if your coordinates are integers (and especially if they came from a string), cast them first - TinyBee's Ints to Rect and String to Float exist for exactly that.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| nanValue | FLOAT | -9999.00-99999–99999 | — |
| xopt | FLOAT | -9999.00-99999–99999 | — |
| yopt | FLOAT | -9999.00-99999–99999 | — |
| wopt | FLOAT | -9999.00-99999–99999 | — |
| hopt | FLOAT | -9999.00-99999–99999 | — |
| x2opt | FLOAT | -9999.00-99999–99999 | — |
| y2opt | FLOAT | -9999.00-99999–99999 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| tinyrect | TINYRECT | — |