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
- Enter center, strokeWidth, deviceScale. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- 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 field | Meaning and units | Accepted input |
|---|---|---|
| center | Center | Required. Finite number. |
| strokeWidth | Stroke Width | Required. Finite number; minimum 0. |
| deviceScale | Positive device pixels per input length unit. | Required. Finite number; strictly above 0. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| deviceWidth | Stroke width multiplied by deviceScale. | Required. Finite number. |
| snappedCenter | Center after snapping the lower edge only; upper-edge alignment is not guaranteed. | Required. Finite number. |
| offset | Signed displacement or phase under the convention above. | Required. Finite number. |
{
"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
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.