Skip to content

Rectangular and elliptical marquee

Rectangular marquee

Fact Value
Status Implemented and tested
Group Marquee
Engine Browser
Code web/src/core/mask/raster.ts, rectMask

Elliptical marquee

Fact Value
Status Implemented and tested
Group Marquee
Engine Browser
Code web/src/core/mask/raster.ts, ellipseMask

Overview

The marquee tools select a rectangle or an ellipse that you drag. Press M for the rectangle and Shift+M for the ellipse.

How to use them

  1. Press where one corner should be and drag to the opposite corner.
  2. Hold Shift while you drag for a square or circle. Hold Alt to draw from the center.
  3. To add to the selection, hold Shift when you start the drag. Alt at the start subtracts, both intersect.
  4. A click without a drag removes the selection.

The options bar sets the style. Fixed ratio keeps the width and height in a ratio. Fixed size places a box of an exact size where you click.

How it works

The rectangle:

  1. Snap the two corners of the drag to whole pixels.
  2. With Shift, make the sides equal. With Alt, use the start point as the center.
  3. With a fixed ratio or size, set the width and height from the settings.
  4. Fill the rectangle with 255 in a new mask. Pixels outside stay 0.
  5. Feather the shape when the feather setting is above 0.
  6. Combine it with the current selection by the mode.

The ellipse:

  1. Snap the two corners of the drag to whole pixels. They bound the ellipse.
  2. With Shift, make a circle. With Alt, use the start point as the center.
  3. Give each pixel the part of it that lies inside the ellipse, from 4 rows of samples per pixel.
  4. Feather the shape when the feather setting is above 0.
  5. Combine it with the current selection by the mode.

Mathematical foundation

The corners snap to whole pixel edges, so the rectangle covers whole pixels. Its mask is 255 inside and 0 outside.

The ellipse with center \((c_x, c_y)\) and half-axes \(a\) and \(b\) is the set of points with

\[ \frac{(x - c_x)^2}{a^2} + \frac{(y - c_y)^2}{b^2} \le 1 \]

where \(x\) and \(y\) are positions in pixels. This is a mathematical definition. With anti-aliasing, each pixel gets the part of its area inside the ellipse. PixelNexus measures that part on 4 rows of samples per pixel, with the exact horizontal coverage on each row. So the value of an edge pixel is right to within 1/4 of a pixel row.

Parameters

Rectangular marquee:

Parameter Default Values Meaning
Style style Normal Normal, Fixed ratio, Fixed size How dragging sets the shape.
Ratio width ratioWidth 1 0.01 to 1000 Width part of the fixed ratio.
Ratio height ratioHeight 1 0.01 to 1000 Height part of the fixed ratio.
Width sizeWidth 64 1 to 16384 px Width of the fixed size.
Height sizeHeight 64 1 to 16384 px Height of the fixed size.
Feather feather 0 0 to 250 px Softens the edge of the new selection.

Elliptical marquee:

Parameter Default Values Meaning
Style style Normal Normal, Fixed ratio, Fixed size How dragging sets the shape.
Ratio width ratioWidth 1 0.01 to 1000 Width part of the fixed ratio.
Ratio height ratioHeight 1 0.01 to 1000 Height part of the fixed ratio.
Width sizeWidth 64 1 to 16384 px Width of the fixed size.
Height sizeHeight 64 1 to 16384 px Height of the fixed size.
Feather feather 0 0 to 250 px Softens the edge of the new selection.
Anti-alias antiAlias on On or off Gives edge pixels a value for the part of them that the shape covers.

Limitations

  • The rectangle always has whole-pixel edges. Feather it to soften them.
  • Fixed size uses image pixels, so the box looks smaller on screen when you zoom out.

Tests