Skip to content

Main content

Rectangle Point Clamp

Clamp a finite planar point to a closed axis-aligned rectangle, allowing degenerate rectangle axes; no polygon or geographic containment.

Loading tool…

Description

Clamp a finite planar point to a closed axis-aligned rectangle, allowing degenerate rectangle axes; no polygon or geographic containment.

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.

Clamp a finite planar point to a closed axis-aligned rectangle, allowing degenerate rectangle axes; no polygon or geographic containment.

When to use this tool

Use this tool to clamp a finite planar point to a closed axis-aligned rectangle, allowing degenerate rectangle axes; no polygon or geographic containment.

How to use the tool and how it works

  1. Enter point, rectangle using the input definitions below.
  2. Run the operation. Resolve malformed-input errors before interpreting the result.
  3. Read result.point. Interpret signs, units, ordering and null values using the rules below.

Clamp x independently to [minX,maxX] and y to [minY,maxY]. Closed boundaries and zero-width or zero-height rectangles are accepted.1

Input fieldMeaning and unitsAccepted input
pointPlanar point [x,y] in the shape’s coordinate units.Dense list of at most 128 finite numbers, subject to the stated integer/shape rules.
rectangleClosed rectangle [minX,minY,maxX,maxY]; equal bounds are allowed.Dense list of at most 128 finite numbers, subject to the stated integer/shape rules.
Output fieldInterpretation
resultObject containing the fields below.
result.pointResulting planar [x,y] point in coordinate units.
json
{
  "input": {
    "point": [
      3,
      -1
    ],
    "rectangle": [
      0,
      0,
      2,
      2
    ]
  },
  "output": {
    "result": {
      "point": [
        2,
        0
      ]
    }
  }
}

Limitations and assumptions

  • The method is specific to an axis-aligned rectangle in a Cartesian plane.
  • 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

  1. Tool behavior and example: Rectangle Point Clamp — tool.io

Similar or alternative tools