10,000 Shapes, 12 Hit Tests β€” Implementing a Quadtree

I Code It
1,642 views β€’

πŸ‘‰ Frontend System Design Essentials β€” Course: https://icodeit.thinkific.com/courses/frontend-system-design-essentials πŸ‘‰ Frontend System Design Essentials β€” Book: https://leanpub.com/frontend-system-design-essentials/ In Part 1, a spatial index made a ten-thousand-shape canvas feel responsive. We used it as a black box: instead of asking every shape whether the pointer hit it, we asked which shapes were close enough to be worth checking. This video opens that box. We implement a Quadtree in TypeScript for the same whiteboard β€” not a generic textbook tree, but one that answers the two questions the drawing tool actually asks: hit testing when the pointer moves, and viewport culling when we paint a frame. You'll learn: Why scanning 10,000 shapes on every pointermove becomes hundreds of thousands of tests per second How a Quadtree splits space so empty regions stay cheap Why the index only stores bounds β€” precise hit testing stays outside How insert, split, and straddling shapes actually work Why one tree can serve both picking (one path) and painting (several paths) Final takeaway: A Quadtree does not replace hit testing or rendering. It decides which work can be skipped β€” and that is why one structure can make both picking and painting fast. πŸ“˜ MY BOOKS & COURSES πŸ‘‰ Frontend System Design Essentials (Course): https://icodeit.thinkific.com/courses/frontend-system-design-essentials πŸ‘‰ Frontend System Design Essentials (Book): https://leanpub.com/frontend-system-design-essentials/ πŸ‘‰ React Anti-Patterns (Amazon): https://www.amazon.com/dp/1805123971 πŸ‘‰ More Tutorials on Advanced Patterns: https://icodeit.com.au/tutorials/advanced-network-patterns-react πŸ“© STAY CONNECTED 🧠 Newsletter (system design & clean code): https://juntao.substack.com 🌐 Website & Blog: https://icodeit.com.au 🐦 Twitter / X: http://twitter.com/JuntaoQiu πŸ“Ί YouTube (subscribe): https://www.youtube.com/@icodeit.juntao #frontend #systemdesign #quadtree #canvas #performance #javascript #typescript #webdevelopment

Keyboard shortcuts

On. Switch them off if they collide with your assistive tools; ? still opens this sheet.

Go to

Press g then the letter.

  • gh Latest
  • gs Sources
  • gm Media
  • gv Videos
  • gp Podcasts
  • gc Calendar
  • gd Decoder
  • gz Dataviz
  • ga Datasets
  • gb Blog
  • gk Markets
  • gj Careers
  • gn Prompt Notebook

On this page

  • / Focus search, where there is one
  • t Back to top
  • ? This list
  • Esc Close