[feat/MAT-362] Catmull-Rom + frozen prefix 증분 path 빌드#304
Open
b0nsu wants to merge 1 commit intorefactor/mat-361-native-stylusfrom
Open
[feat/MAT-362] Catmull-Rom + frozen prefix 증분 path 빌드#304b0nsu wants to merge 1 commit intorefactor/mat-361-native-stylusfrom
b0nsu wants to merge 1 commit intorefactor/mat-361-native-stylusfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
네이티브 드로잉의 path smoothing을 기존 quadratic Bézier 기반에서 centripetal Catmull‑Rom(→ cubic Bézier) 기반으로 교체하고, 라이브 드로잉 중에는 frozen prefix를 재사용하는 증분 path 빌더를 도입해 매 포인트 입력 시 전체 재빌드 비용을 줄이려는 PR입니다.
Changes:
buildSmoothPath를 centripetal Catmull‑Rom 기반 cubic Bézier path 생성으로 변경IncrementalPathBuilder를 추가해 라이브 스트로크에서 frozen prefix 증분 빌드 적용- 패키지 public export에
IncrementalPathBuilder,centripetalControlPointsMut노출 및DrawingCanvas에서 증분 빌더 사용
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/pointer-native-drawing/src/smoothing.ts | centripetal Catmull‑Rom 제어점 계산 + full rebuild + frozen prefix 증분 빌더 추가 |
| packages/pointer-native-drawing/src/DrawingCanvas.tsx | 라이브 드로잉 시 IncrementalPathBuilder.update()로 path 갱신 및 cancel/start 시 reset 연동 |
| packages/pointer-native-drawing/src/index.ts | smoothing 관련 신규 export 추가 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+10
to
+23
| // --------------------------------------------------------------------------- | ||
| // Catmull-Rom control points (centripetal parameterization) | ||
| // Mutable singleton to avoid per-call allocation. Safe in single-threaded JS. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| const _cpOut = { cp1x: 0, cp1y: 0, cp2x: 0, cp2y: 0 }; | ||
|
|
||
| export function centripetalControlPointsMut( | ||
| p0: Point, | ||
| p1: Point, | ||
| p2: Point, | ||
| p3: Point | ||
| ): typeof _cpOut { | ||
| const d01 = Math.sqrt(Math.sqrt((p1.x - p0.x) * (p1.x - p0.x) + (p1.y - p0.y) * (p1.y - p0.y))); |
Comment on lines
+148
to
+149
| // points[i+2]가 아직 없는 마지막 ~2 segments는 확정 불가. | ||
| const canFreezeUpTo = Math.max(0, points.length - 3); |
Comment on lines
89
to
93
|
|
||
| const livePath = useRef<SkPath>(Skia.Path.Make()); | ||
| const pathBuilder = useRef(new IncrementalPathBuilder()); | ||
| const currentPoints = useRef<Point[]>([]); | ||
| const strokesRef = useRef<Stroke[]>([]); |
| DocumentSnapshot, | ||
| } from './model/drawingTypes'; | ||
| export { buildSmoothPath } from './smoothing'; | ||
| export { buildSmoothPath, IncrementalPathBuilder, centripetalControlPointsMut } from './smoothing'; |
4e9555a to
255d565
Compare
…path 빌드 - smoothing.ts: quadratic bezier → Catmull-Rom (centripetal parameterization, cubic Bézier) - centripetalControlPointsMut: mutable singleton internal-only (외부 export 안 함) - canFreezeUpTo = N-2 (segment i=N-3까지 freeze 가능, off-by-one 정정) - IncrementalPathBuilder: frozen prefix 증분 빌더 — 마지막 1 segment만 live 재계산 O(1) - DrawingCanvas.tsx: - pathBuilder lazy init (useRef + nullish-coalescing assign) - addPoint/startStroke: pathBuilder.update 호출 (full rebuild 회피) - finalizeStroke/cancelStroke/clear: pathBuilder.reset() Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
de5ed6a to
610c63f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
quadratic Bezier를 centripetal Catmull-Rom으로 교체하고, IncrementalPathBuilder로 frozen prefix 증분 빌드를 도입합니다.
시나리오: 200 points 획 → 전체 재계산 O(n) → 마지막 segment만 O(1).
Linear
Changes
smoothing.ts— centripetal Catmull-Rom 알고리즘, IncrementalPathBuilder, centripetalControlPointsMutTesting
pnpm typecheck통과pnpm lint통과Risk / Impact