SVG Graphics Geometry
Guide
css-matrix
Guide
css-matrix
  • Part 0. SVG 기초

    • SVG란 무엇인가
    • viewBox와 user space
    • transform attribute와 matrix
    • SVG 문서 구조와 기본 도형
  • Part 1. Path grammar

    • path d 명령어 — M, L, Z
    • H, V — 축 정렬 직선
    • C — cubic Bézier
    • Q — quadratic Bézier
    • S, T — smooth continuation
    • A — elliptical arc
    • path bounding box
  • Part 2. Stroke geometry

    • 점에서 stroke까지의 거리
    • join, cap, miter limit
    • stroke align과 outline 개념
    • miter length 공식
  • Part 3. Fill rules

    • nonzero vs evenodd
    • fill hit testing
  • Part 4. Path sampling

    • flatten tolerance
    • path length
    • point at length와 tangent
  • Part 5. Paint servers

    • linearGradient 좌표
    • clipPath와 mask 개념
  • Part 6. Path editor capstone

    • path handle 모델
    • handle hit testing
    • handle drag로 segment 갱신
    • mini path editor — SVG round-trip
  • Part 7. Fill & winding deep dive

    • winding vs ray casting
    • compound path — 여러 subpath
    • self-intersection
    • path boolean
    • fill vs stroke hit 우선순위
    • scanline parity
  • Part 8. Pattern & gradient

    • radialGradient
    • pattern tile
    • gradientUnits와 spreadMethod
  • Part 9. SVG filter & Figma effects

    • Figma DROP_SHADOW → SVG filter
    • filter chain 개요
    • blur · offset · merge
    • inner shadow
    • layer blur vs background blur
    • Figma effect 매핑표 전체
  • Part 10. Figma ↔ SVG bridge

    • vector network vs path d
    • fill · stroke export
    • boolean operations export
    • mask · clip export
  • Part 11. Icon design

    • pixel grid · optical alignment
    • fill vs stroke icons
    • symbol · sprite · currentColor
    • path simplification
  • Appendix A. SVG in CSS

    • currentColor · CSS theming
    • sprite data URI
    • SVG optimization pipeline
  • Appendix B. Engine extras

    • dash offset animation
    • adaptive flatten
    • arc → cubic 변환
    • multi-subpath editing
  • Part 12. Foundations primer

    • capability map
    • coordinate stack
  • Part 13. Figma ↔ SVG (deep)

    • Figma paint gap map
    • radial · angular gradient export
    • image · pattern fill
    • stroke align export
    • blend mode · layer opacity
  • Part 14. SVG spec breadth

    • markers — 화살표와 dash 끝
    • text · textPath
    • paint-order · opacity · filters
    • arc flatten 통합
  • Part 15. Curve calculus

    • de Casteljau subdivision
    • flatness와 chord error
    • 곡률 κ와 법선
    • arc center parameterization
    • G¹ smooth — S와 T
    • shoelace signed area
  • Part 16. Intersection & proximity

    • segment intersection
    • line ∩ cubic · curve ∩ curve
    • closest point on curve
  • Part 17. Offset curves

    • normal offset sampling
    • offset cusps
  • Part 18. Transform algebra

    • affine inverse & decompose
    • transform path vs group
  • Part 19. Rational curves

    • circle as cubic — κ constant
    • rational curves & exact arcs
  • Part 20. Tessellation & pixels

    • convex triangulation · ear clipping
    • evenodd parity → pixels
  • Part 21. Compositing math

    • Gaussian blur kernel
    • Porter–Duff & premultiplied α
  • Part 22. Math topic map

    • SVG 수학 주제 지도
  • Part 23. SVG animation

    • SMIL — animate 속성
    • SMIL — animateTransform
    • SMIL — animateMotion
    • stroke dash draw-on
    • CSS offset-path motion
    • path morph
    • JS motion along path
  • Part 24. Motion precision

    • uniform speed along path
    • cubic–cubic intersection
    • SVGPathElement length API
    • SMIL keyTimes & keySplines
    • degree elevation Q→C
  • Part 25. GPU mesh & WAAPI

    • triangulation with holes
    • WAAPI + SVG attributes
    • evenodd fill + triangle mesh

fill hit testing

포인터가 path 내부(fill 영역) 인지 판정하는 것이 fill hit입니다. 014의 fill-rule을 그대로 쓰고, 곡선·arc segment는 flatten polygon으로 바꾼 뒤 winding/parity를 계산합니다.

데모에서 볼 것

014 fill-rule 데모와 동일 UI (mountFillHitDemo = compound rect + 구멍).

  • fill-rule 선택: nonzero / evenodd
  • 포인터 이동 — inside 초록 / outside 빨강
  • readout에 fill hit = pointInPath(flattened polygon) 추가

구멍 안·밖을 evenodd와 nonzero로 번갈아 가며 클릭해 보면 014 표와 일치합니다.

한 줄 API

import { pointInPath, parsePathD } from "svg-matrix-core";

const segments = parsePathD(pathD);
const inside = pointInPath(pointer, segments, "evenodd", {
  stepsPerCurve: 16,
  stepsPerArc: 24
});

pointInPath = classifyPointInPath(...).inside 만 반환.

상세: classifyPointInPath

import { classifyPointInPath } from "svg-matrix-core";

const c = classifyPointInPath(pointer, segments, "nonzero", {
  stepsPerCurve: 24,
  stepsPerArc: 24
});

c.inside;           // 최종 판정
c.winding;          // nonzero — subpath 합
c.crossings;        // evenodd — subpath 합
c.insideNonZero;    // rule 무관 참고값
c.insideEvenOdd;
c.subpathCount;     // M으로 나뉜 개수

compound path(구멍)는 subpath마다 polygon을 만든 뒤 winding/crossing을 합산합니다 (014).

편집기 pick 파이프라인

screen (clientX,Y)
  → inverse view / element transform  ([001](./lesson-001.md))
  → world point
  → (optional) bboxOfPath broad-phase ([012](./lesson-012.md))
  → pointInPath(point, segments, fillRule, flatten opts)
function pickFill(world, segments, style) {
  if (!bboxContains(padBBox(bboxOfPath(segments), style.strokeWidth), world)) {
    return false;
  }
  return pointInPath(world, segments, style.fillRule ?? "nonzero", {
    stepsPerCurve: style.hitSteps ?? 16
  });
}

handle·anchor hit은 별도 경로입니다 (022 hitTestPathHandles — segments가 아니라 handle 배열).

정확도 · 성능

옵션영향
stepsPerCurve ↑cubic/quadratic 근처 fill hit 정확
stepsPerArc ↑011 A 호 근처 정확
052 adaptiveflatten-only 파이프라인에 적용 가능 — pointInPath 기본은 uniform

흔한 패턴:

  • pointermove — coarse step (8–12)
  • click / commit — fine step (24–32) 또는 adaptive

bbox·selection은 해석 bboxOfPath(012) — fill hit만 flatten에 의존합니다.

stroke hit과 분리

fill hitstroke hit
질문영역 안/밖?중심선까지 거리 ≤ sw/2?
corepointInPathdistancePointToSegment / closestPointOnCubic (004)
규칙nonzero / evenoddstroke width · align (006)
근사flatten polygon곡선 최근접 (076)

029 — 둘 다 true일 때 stroke 우선이 일반적 UX. fill·stroke 코드를 한 함수에 섞지 마세요.

const fillHit = pointInPath(p, segments, fillRule, opts);
const strokeHit = minDistanceToPath(p, segments) <= strokeWidth / 2;
const target = strokeHit ? "stroke" : fillHit ? "fill" : null;

Canvas · DOM

// Canvas 2D
ctx.isPointInPath(path2d, x, y, "evenodd");

// SVG (Chromium 등)
pathEl.isPointInFill(new DOMPoint(x, y));  // fill-rule 반영

편집 중 segment graph는 DOM과 매 프레임 동기화되지 않으므로 **core pointInPath**가 기본입니다 (097 length API와 같은 이유).

boolean · compound

  • 한 path, 구멍 — fill-rule + compound subpath (014)
  • 두 path set op — pointInPathBoolean (A/B 각각 nonzero 후 union/subtract/…)
  • 편집기 레이어 — z-order + 위 pick 파이프라인 반복

028 path boolean geometry는 별도; hit은 often “결과 path 하나”에 pointInPath.

Core API

함수역할
pointInPathfill hit boolean
classifyPointInPathinside + winding/crossings 디버그
flattenPathSegments, segmentsToSubpaths전처리
pointInPathBoolean두 region set op
windingNumber, rayCrossingCountpolygon 단위 (014)

관련

  • 014 rules · 004 stroke · 029 priority · 024 editor

오늘의 핵심

fill hit = world 좌표 + flatten + fill-rule. stroke·handle pick과 분리하고, stepsPerCurve/stepsPerArc를 move/click에 맞게 나누면 편집기가 브라우저 fill과 같은 체감에 가깝습니다.

최근 수정: 26. 5. 17. PM 4:35
Contributors: jinho.park.s3, Cursor
Prev
nonzero vs evenodd