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

path boolean

Figma Union / Subtract / Intersect / Exclude는 두 채움 영역 (A, B)에 대한 집합 연산입니다. “결과 path의 d”를 바로 주는 API가 아니라, 먼저 점이 결과 안인지를 정의하는 것이 수학적으로 정확합니다.

네 가지 연산 (진리표)

inA, inB = 014 pointInPath (기본 nonzero).

opinside when직관
unioninA ∨ inB합치기
subtractinA ∧ ¬inBA에서 B 빼기
intersectinA ∧ inB겹치는 부분만
excludeinA ⊕ inBXOR — 겹침 제외
import { parsePathD, pointInPathBoolean } from "svg-matrix-core";

const segA = parsePathD("M 20 30 L 80 30 L 80 80 L 20 80 Z");
const segB = parsePathD("M 55 35 L 105 35 L 105 85 L 55 85 Z");

const inside = pointInPathBoolean(pointer, segA, segB, "union", {
  stepsPerCurve: 16
});

core 구현 (packages/svg-matrix-core/src/index.js):

const inA = pointInPath(point, segmentsA, "nonzero", options);
const inB = pointInPath(point, segmentsB, "nonzero", options);
// op에 따라 inA, inB 조합

이 레슨 데모 = 점 샘플링 시각화

mountPathBooleanDemo는 결과 path를 그리지 않습니다.

  • 파란·주황 사각형 = A, B
  • 포인터를 움직이면 초록 틴트 = 현재 op에서 inside === true인 위치
  • toolbar boolean 셀렉트: union / subtract / intersect / exclude

겹치는 영역에서 op를 바꿔 보며 진리표를 몸으로 확인하세요.

readout 예

pointer=(72, 58)
union → inside=true

실무: 결과 d는 어떻게 만드나

접근설명
Polygon clipflatten → Clipper / boolean-op — Figma·Illustrator 계열
GPU rastercoverage mask → contour (느리거나 해상도 의존)
점 샘플링이 데모 — 정의 검증·교육용, 프로덕션 boolean 아님

편집기는 보통 clip 라이브러리로 **새 segment[]**를 만들고, 그다음 024 round-trip으로 d를 씁니다.

fill-rule · compound

  • pointInPathBoolean은 A,B 각각 nonzero (025–026)
  • hole·여러 subpath는 winding 방향이 결과를 바꿉니다 — boolean 전에 026 정리
  • self-intersect (027) — evenodd vs nonzero 선택이 선행

Figma export

import { figmaBooleanPathsToSvg, FIGMA_BOOLEAN_MAP } from "svg-matrix-core";

// UNION | SUBTRACT | INTERSECT | EXCLUDE → compound path + fill-rule

042 — 플러그인은 결과 geometry를 export, 이 강의는 의미를 맞춥니다.

성능 메모

포인터마다 classifyPointInPath × 2 — 괜찮습니다. 전 화면 픽셀 boolean preview는 해상도×면적만큼 비용이 듭니다. 실무 preview는 저해상도 raster 또는 bbox clip 후 polygon.

Core API

  • pointInPathBoolean, pointInPath, classifyPointInPath
  • figmaBooleanPathsToSvg, FIGMA_BOOLEAN_MAP — bridge

관련

  • 026 compound · 027 self-intersect · 042 Figma boolean

오늘의 핵심

boolean = 집합론. pointInPathBoolean은 정의를 코드로 고정한 것이고, “도형 합치기” UI는 polygon clip이 담당합니다. 데모는 op별 inside 영역을 색으로 보여 줍니다.

최근 수정: 26. 5. 17. PM 4:35
Contributors: jinho.park.s3, Cursor
Prev
self-intersection
Next
fill vs stroke hit 우선순위