52 lines
1.0 KiB
Haskell
52 lines
1.0 KiB
Haskell
module Geometry.LHS (
|
|
isLHS,
|
|
isRHS,
|
|
) where
|
|
|
|
import Geometry.Data
|
|
|
|
{- | Test whether a point is stricly on the LHS of a line.
|
|
Returns False if the line is of zero length.
|
|
-}
|
|
isLHS ::
|
|
-- | First line point.
|
|
Point2 ->
|
|
-- | Second line point.
|
|
Point2 ->
|
|
-- | Point not on line.
|
|
Point2 ->
|
|
Bool
|
|
{-# INLINE isLHS #-}
|
|
isLHS (V2 x y) (V2 x' y') (V2 x'' y'')
|
|
| (x, y) == (x', y') = False
|
|
| otherwise = a1 * b2 - a2 * b1 > 0
|
|
where
|
|
a1 = x' - x
|
|
a2 = y' - y
|
|
b1 = x'' - x
|
|
b2 = y'' - y
|
|
|
|
{- | Test whether a point is on the RHS of a line.
|
|
Returns False if the line is of zero length.
|
|
-}
|
|
isRHS ::
|
|
-- | First line point.
|
|
Point2 ->
|
|
-- | Second line point.
|
|
Point2 ->
|
|
-- | Point not on line.
|
|
Point2 ->
|
|
Bool
|
|
{-# INLINE isRHS #-}
|
|
isRHS
|
|
(V2 x y)
|
|
(V2 x' y')
|
|
(V2 x'' y'')
|
|
| (x, y) == (x', y') = False
|
|
| otherwise = a1 * b2 - a2 * b1 < 0
|
|
where
|
|
a1 = x' - x
|
|
a2 = y' - y
|
|
b1 = x'' - x
|
|
b2 = y'' - y
|