Ray-casting algorithm: Difference between revisions

→‎{{header|Racket}}: Added missing implementation details from algorithm.
m (→‎{{header|REXX}}: used a better over/under statement construct.)
(→‎{{header|Racket}}: Added missing implementation details from algorithm.)
Line 2,993:
(module pip racket
(require racket/contract)
 
(provide point)
(provide seg)
Line 3,002:
 
(struct point (x y) #:transparent)
(struct seg (Ax Ay Bx By) #:transparent)
(define ε 0.000001)
(define (neq? x y) (not (eq? x y)))
Line 3,013:
(eq? Pyo By))
ε 0))])
 
(conddefine Ax2 [(orif (< PyAy AyBy) (>Ax Py ByBx)) #f]
(define Ay2 (if (< Ay By) Ay By))
(define Bx2 (if (< Ay By) Bx Ax))
(define By2 (if (< Ay By) By Ay))
 
(cond [(or (> Py (max Ay By)) (< Py (min Ay By))) #f]
[(> Px (max Ax Bx)) #f]
[(< Pxelse (min Ax Bx))cond #t]
[else(< Px (min Ax Bx)) #t]
(let ([red (if (neq? Ax Px)[else
(let (/[red (- By Ay)if (-neq? BxAx2 Ax)Bx2)
+inf.0 (/ (- By2 Ay2) (- Bx2 Ax2))]
[blue (if (neq? Ax Px +inf.0)]
[blue (/if (-neq? Py Ax) (-Ax2 Px Ax))
+inf.0 (/ (- Py Ay2) (- Px Ax2)])
(if (>= blue red) #t #f) +inf.0)])))
(if (>= blue red) #t #f))])])))
 
(define (point-in-polygon? point polygon)
Anonymous user