Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Point in Polygon

โญโญโญ advancedโณ 30 min read๐Ÿ“ Lesson 178 of 281

Ray casting counts edge crossings; doing the arithmetic in integers makes the test exact even at 1e18 numerators.

Counting crossings without floats

A point is inside iff a ray from it crosses the boundary an odd number of times. The classic trap: computing the intersection x with double division โ€” precision dies at 1e15 numerators. The integer form compares signs of cross products; no division anywhere. Degenerate edges still need care: define the crossing condition as (yi > py) != (yj > py).