Skip to content

Main content

Pixel Grid Half Stroke Snap Offset Tool

Snap the leading stroke edge to a nearest device-pixel boundary; ties follow JavaScript positive-infinity rounding.

Loading tool…

Description

Convert to device pixels, round the lower stroke edge using Math.round, then add half the device width and convert back for snappedCenter and offset.

A vector stroke has width as well as a centerline, and a dashed stroke alternates painted lengths and gaps. Pattern phase and visible clearance depend on these dimensions even before a path is rendered.

Convert to device pixels, round the lower stroke edge using Math.round, then add half the device width and convert back for snappedCenter and offset.

When to use this tool

Use Pixel Grid Half Stroke Snap Offset when you need a numerical stroke allowance or repeating-pattern calculation before rendering.

How to use the tool and how it works

  1. Enter center, strokeWidth, deviceScale. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read deviceWidth, snappedCenter, offset. Use the output convention below.

Require nonnegative strokeWidth and positive deviceScale. Convert to device pixels, round the lower stroke edge using Math.round, then add half the device width and convert back for snappedCenter and offset.1

Input fieldMeaning and unitsAccepted input
centerCenterRequired. Finite number.
strokeWidthStroke WidthRequired. Finite number; minimum 0.
deviceScalePositive device pixels per input length unit.Required. Finite number; strictly above 0.
Output fieldInterpretationReturned shape
deviceWidthStroke width multiplied by deviceScale.Required. Finite number.
snappedCenterCenter after snapping the lower edge only; upper-edge alignment is not guaranteed.Required. Finite number.
offsetSigned displacement or phase under the convention above.Required. Finite number.
json
{
  "input": {
    "center": 10,
    "strokeWidth": 1,
    "deviceScale": 1
  },
  "output": {
    "deviceWidth": 1,
    "snappedCenter": 10.5,
    "offset": 0.5
  }
}

Limitations and assumptions

  • This snaps one edge under the supplied width rather than guaranteeing both edges align; rounding ties follow JavaScript and no antialiasing, transforms, or actual renderer is evaluated.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
  • Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.

Alternative or Complementary methods

Inspect the result in the target vector renderer at final size. Curved paths, joins, caps, and rasterization may require geometry or visual checks beyond a local length calculation.

References

  1. Calculation and input contract: graphic-design/pixel-grid-half-stroke-snap-offset — tool.io

Similar or alternative tools

  • Baseline Grid Half Step Rule

    Normalize coordinate around origin, round to the nearest grid index, resolve exact half steps by the selected policy, and return index and snapped coordinate.

  • Icon Stroke Clearance Gap

    Subtract half each nonnegative stroke width from nonnegative centerlineGap for visibleGap, then subtract requiredVisibleGap for margin.