10,000 Shapes, 12 Hit Tests β Implementing a Quadtree
π 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