const E = 0.0001; fcn rayHitsSeg([(Px,Py)],[(Ax,Ay)],[(Bx,By)]){ // --> Bool if(Py==Ay or Py==By) Py+=E; if(PyBy or Px>Ax.max(Bx)) False else if(Px=( (By - Ay)/(Bx - Ax) ) } //blue>=red catch(MathError){ Px==Ax } // divide by zero == ∞, only blue? } fcn pointInPoly(point, polygon){ // --> Bool, polygon is ( (a,b),(c,d).. ) polygon.filter('wrap([(ab,cd)]){ a,b:=ab; c,d:=cd; if(b<=d) rayHitsSeg(point,ab,cd); // left point has smallest y coordinate else rayHitsSeg(point,cd,ab); }) .len().isOdd; // True if crossed an odd number of borders ie inside polygon }