path simplification
Douglas–Peucker로 flatten polyline 점을 줄여 파일 크기를 낮춥니다. 곡선은 먼저 016 flatten합니다.
데모에서 볼 것
dense wavy d (24×24 좌표):
M 0 12 C 3 2, 9 22, 12 12 C 15 2, 21 22, 24 12 … Z
- 회색 polyline — flatten 원본 점들
- 파란 path —
simplifyPathD결과 - tolerance 슬라이더 0.2–4
readout:
Douglas–Peucker tolerance=1.2
87 flatten points → 12 polyline vertices
M 0 12 L … Z
API
import { simplifyPathD, douglasPeucker, flattenPathSegments, parsePathD } from "svg-matrix-core";
const result = simplifyPathD(densePathD, 1.2, { stepsPerCurve: 12 });
// { d, pointCount, originalCount }
const flat = flattenPathSegments(parsePathD(d), { stepsPerCurve: 12 });
const simplified = douglasPeucker(flat, 1.2);
파이프라인
cubic/arc d
→ flattenPathSegments (stepsPerCurve)
→ douglasPeucker(tolerance)
→ M … L … L … (polyline only export)
고급: simplified polyline → cubic refit (이 코스 범위 밖).
vs SVGO · 050
런타임 simplifyPathD | 빌드 SVGO | |
|---|---|---|
| 시점 | 편집기 export preview | CI minify |
| 제어 | tolerance 슬라이더 | plugin preset |
044 snap 후 simplify — 순서 중요.
Core API
| 함수 | 역할 |
|---|---|
simplifyPathD | d in/out + counts |
douglasPeucker | points[] |
distancePointToSegment | DP 거리 (004) |
관련
오늘의 핵심
simplify = 시각 허용 오차 trade-off. tolerance↑ → 점↓·파일↓·형태 단순화.