Description
For disjoint rectangles return the shortest translation closing both axis gaps; for overlapping rectangles return a minimum axis escape translation, ties left/right/down/up in that order.
Planar geometry operates on two-coordinate Cartesian points and explicit shape boundaries. A closed rectangle includes its edges, while a segment parameter locates a point along a supporting line. Signed cross products, areas and axis gaps preserve orientation or direction information that a magnitude alone would lose.
For disjoint rectangles return the shortest translation closing both axis gaps; for overlapping rectangles return a minimum axis escape translation, ties left/right/down/up in that order.
When to use this tool
Use this tool to compare two axis-aligned rectangles using the translation-to-contact rule below.
How to use the tool and how it works
- Enter left, right using the input definitions below.
- Run the operation. Resolve malformed-input errors before interpreting the result.
- Read result.vector, result.overlap. Interpret signs, units, ordering and null values using the rules below.
When rectangles lack positive overlap on either axis, return the signed x/y translation bringing the left rectangle into contact with the right. With positive overlap on both axes, choose the shortest of four axis-only translations to contact, testing left, right, down and up in that tie order.1
| Input field | Meaning and units | Accepted input |
|---|---|---|
| left | Left rectangle [minX,minY,maxX,maxY] with ordered bounds. | Dense list of at most 128 finite numbers, subject to the stated integer/shape rules. |
| right | Right rectangle [minX,minY,maxX,maxY] with ordered bounds. | Dense list of at most 128 finite numbers, subject to the stated integer/shape rules. |
| Output field | Interpretation |
|---|---|
| result | Object containing the fields below. |
| result.vector | Translation of the left rectangle to contact under the rule stated above. |
| result.overlap | Whether the rectangles have strictly positive interval intersection on both axes. |
{
"input": {
"left": [
0,
0,
2,
2
],
"right": [
1,
1,
3,
3
]
},
"output": {
"result": {
"vector": [
-1,
0
],
"overlap": true
}
}
} Limitations and assumptions
- Touching or degenerate rectangles have overlap = false. The result closes a gap or reaches contact; it does not model velocity or collision response.
- Point components and rectangle bounds are finite within ±1,000,000,000. Rectangles use [minX,minY,maxX,maxY] with ordered inclusive bounds. Floating arithmetic is used without an implicit robustness tolerance.
- Every declared top-level input is required and unknown fields are rejected. Ordinary strings are limited to 8,192 UTF-16 code units and lists to 128 entries, with tighter operation-specific bounds where stated. JSON text has bounded nesting and node counts.
- Numeric outputs must be finite and within the absolute safe-integer magnitude; exact larger integers use decimal text. Source positions are zero-based UTF-16 offsets and span ends are exclusive unless a different convention is explicitly stated.
Alternative or Complementary methods
Choose the boundary and coordinate convention explicitly. Use robust geometric predicates or a topology-aware library when near-coincidence, holes, invalid polygons or geographic coordinates matter.
References
Similar or alternative tools
- Polygon Rectangle Clip
Clip an ordered planar polygon against four rectangle half-planes, preserving algorithm order; floating boundary arithmetic, no polygon topology repair.
- Polyline Rectangle Clip
Clip each polyline segment independently, retaining source-segment indexes and boundary point intersections instead of inventing path continuity.