private boolean insideQuadrilateral()

in commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java [294:333]


        private boolean insideQuadrilateral(final Vector2D point) {

            Vector2D v1 = quadrilateral.get(quadrilateral.size() - 1);
            Vector2D v2 = quadrilateral.get(0);

            if (point.equals(v1) || point.equals(v2)) {
                return true;
            }

            // get the location of the point relative to the first two vertices
            final double last = signedAreaPoints(v1, v2, point);

            // If the area is zero then this means the given point is on a boundary line.
            // and must be included as collinear point.
            if (precision.eq(last, 0.0) && includeCollinearPoints) {
                return false;
            }

            final int size = quadrilateral.size();
            // loop through the rest of the vertices
            for (int i = 1; i < size; i++) {
                v1 = v2;
                v2 = quadrilateral.get(i);

                if (point.equals(v2)) {
                    return true;
                }

                // do side of line test: multiply the last location with this location
                // if they are the same sign then the operation will yield a positive result
                // -x * -y = +xy, x * y = +xy, -x * y = -xy, x * -y = -xy
                double signedArea = signedAreaPoints(v1, v2, point);
                // three collinear points have an area of zero. If we include collinear points
                // we have to consider this case.
                if (last * signedArea < 0 || precision.eq(signedArea, 0.0) && includeCollinearPoints) {
                    return false;
                }
            }
            return true;
        }