CSS Graphics Geometry
Guide
Reference
GitHub
Guide
Reference
GitHub
  • Part 0. Math foundations

    • 좌표계와 CSS pixel
    • 점, 벡터, 거리와 기본 용어
    • 각도, 라디안, atan2
  • Part 1. Transform linear algebra

    • translate, scale, rotate
    • CSS matrix(a,b,c,d,e,f)
    • 변환 순서와 transform-origin
    • local, world, screen 좌표계
    • inverse matrix와 포인터 입력
    • 좌표와 transform 디버깅
  • Part 2. Infinite canvas math and architecture

    • viewport와 camera 모델
    • cursor anchored zoom
    • ruler와 tick 계산
    • 주기 함수와 grid step
    • content, overlay, controls layer
    • scene graph와 nested transform
  • Part 3. Editor tool math

    • Pointer Events와 드래그
    • DOMRect와 getBoundingClientRect
    • hit testing과 bounding box
    • selection rectangle과 marquee
    • selection bounds와 handles
    • resize와 rotation handle
    • snapping과 smart guides
    • group, frame, clipping
  • Part 4. CSS graphics properties as math

    • CSS box로 도형 만들기
    • clip-path, radius, shadow
    • 선형보간과 linear-gradient
    • 거리 함수와 radial/conic-gradient
    • stacking context와 합성
    • layout, paint, composite
  • Part 5. Editor state and persistence

    • 레이어 모델과 z-index
    • 이동, 복제, 삭제, 잠금
    • undo/redo command model
    • JSON export/import
  • Part 6. SVG overlay and vector editing

    • SVG viewBox와 좌표계
    • getScreenCTM과 inverse
    • SVG pointer-events와 stroke hit testing
    • cubic bezier path editing
    • mask, clipPath, marker
  • Part 7. Figma to CSS translation

    • Figma node와 CSS DOM 모델
    • Frame constraints와 Auto Layout
    • Fills, strokes, effects를 CSS로
    • Vector와 text 변환
    • gradient 밖의 CSS 수학
    • Figma gradient를 CSS gradient로 변환하기
    • 수학이 필요한 Figma to CSS 속성들
    • Figma VectorNetwork 정리
  • Appendix A. Canvas renderer transition

    • Canvas로 넘어가는 기준
  • Appendix B. Motion and timing

    • 모션 수학과 timing 함수
    • Keyframe timeline 엔진
    • Motion path 수학
    • Bezier curve 길이 구하기

좌표와 transform 디버깅

이번에는 디버깅입니다.

그래픽 툴의 수학 버그는 숫자만 쳐다보면 잘 안 보입니다. x = 231.42라고 쓰여 있어도 그게 맞는지 틀린지 감이 잘 안 옵니다. 그런데 좌표축과 bounds를 화면에 그려보면 바로 보입니다.

“아, x축이 저기로 누웠구나.”

이 순간 디버깅 시간이 확 줄어듭니다.

transform debug overlay diagramAABB + transformed corners + basis vectorsdebug readoutbasisX = M*(1,0)-M*(0,0)basisY = M*(0,1)-M*(0,0)AABB = min/max(corners)computed matrix vs model matrix
디버그 overlay는 변환된 basis vector, transformed corners, AABB를 같이 보여줘서 좌표계 오류를 빨리 드러냅니다.

좌표축을 그리자

matrix가 있다면 변환된 x축과 y축을 그릴 수 있습니다.

basisX = M * (1, 0) - M * (0, 0)
basisY = M * (0, 1) - M * (0, 0)

basisX는 local x축이 화면에서 어디를 향하는지, basisY는 local y축이 어디를 향하는지 보여줍니다. 회전, scale, skew가 섞여도 축을 보면 감이 옵니다. 숫자보다 그림이 빠를 때가 많습니다.

bounds도 같이 보자

오브젝트의 네 corner를 변환한 뒤 min/max를 잡으면 화면 기준 AABB가 나옵니다.

AABB = min/max(transformed corners)

selection이 어긋날 때 content matrix가 틀린 건지, viewport matrix가 틀린 건지, object matrix가 틀린 건지 나눠서 봐야 합니다. 한꺼번에 보면 다 수상해 보입니다. 범인을 좁혀야 합니다.

computed transform과 모델 transform 비교

브라우저가 실제로 적용한 transform은 computed style에서 읽을 수 있습니다.

getComputedStyle(element).transform

에디터 모델의 matrix와 computed matrix를 나란히 표시하면 직렬화 과정에서 생긴 오류를 빨리 찾을 수 있습니다. 예를 들어 모델은 center origin을 가정했는데 CSS는 top-left origin으로 적용했다면 축이 바로 어긋납니다.

디버그 overlay는 보통 pointer-events: none으로 둡니다. 디버그 UI가 편집 입력을 가로막으면, 디버깅하다가 다시 디버깅할 일이 생깁니다. 이건 좀 억울합니다.

데모에서 볼 것

데모에서는 debug 값을 보며 basis vector가 회전과 scale을 어떻게 포함하는지 읽습니다.

오늘의 핵심은 좋은 그래픽 에디터에는 좋은 디버그 레이어가 필요하다는 것입니다. 좌표축, bounds, matrix readout은 화려한 기능은 아니지만, 개발자를 꽤 오래 살려줍니다.

Edit this page
최근 수정: 26. 5. 14. PM 5:45
Contributors: easylogic
Prev
inverse matrix와 포인터 입력