Since the sign of the homography is ambiguous a point is required to make sure the correct
one was selected.

@param p test point, used to determine the sign of the matrix.
3051
protected void adjustHomographSign( AssociatedPair p , DMatrixRMaj H ) {
		double val = GeometryMath_F64.innerProd(p.p2, H, p.p1);

		if( val < 0 )
			CommonOps_DDRM.scale(-1, H);
	}
731834
public boolean computeRectifyingHomography( DMatrixRMaj H ) {
		H.reshape(4,4);

		// insert the results into H
		// H = [K 0;-p'*K 1 ]
		H.zero();
		for (int i = 0; i < 3; i++) {
			for (int j = i; j < 3; j++) {
				H.set(i,j,k.get(i,j));
			}
		}
		// p and k have different scales, fix that
		H.set(3,0, -(p.a1*k.a11 + p.a2*k.a21 + p.a3*k.a31));
		H.set(3,1, -(p.a1*k.a12 + p.a2*k.a22 + p.a3*k.a32));
		H.set(3,2, -(p.a1*k.a13 + p.a2*k.a23 + p.a3*k.a33));
		H.set(3,3,1);

		return true;
	}
346405
private static boolean multiPointIntersectsMultiPoint_(
			MultiPoint _multipointA, MultiPoint _multipointB, double tolerance,
			ProgressTracker progress_tracker) {
		MultiPoint multipoint_a;
		MultiPoint multipoint_b;

		if (_multipointA.getPointCount() > _multipointB.getPointCount()) {
			multipoint_a = _multipointB;
			multipoint_b = _multipointA;
		} else {
			multipoint_a = _multipointA;
			multipoint_b = _multipointB;
		}

		Envelope2D env_a = new Envelope2D();
		Envelope2D env_b = new Envelope2D();
		Envelope2D envInter = new Envelope2D();
		multipoint_a.queryEnvelope2D(env_a);
		multipoint_b.queryEnvelope2D(env_b);
		env_a.inflate(tolerance, tolerance);
		env_b.inflate(tolerance, tolerance);
		envInter.setCoords(env_a);
		envInter.intersect(env_b);

		Point2D ptA = new Point2D();
		Point2D ptB = new Point2D();
		double tolerance_sq = tolerance * tolerance;

		QuadTreeImpl quadTreeB = InternalUtils.buildQuadTree(
				(MultiPointImpl) (multipoint_b._getImpl()), envInter);
		QuadTreeImpl.QuadTreeIteratorImpl qtIterB = quadTreeB.getIterator();

		for (int vertex_a = 0; vertex_a < multipoint_a.getPointCount(); vertex_a++) {
			multipoint_a.getXY(vertex_a, ptA);

			if (!envInter.contains(ptA))
				continue;

			env_a.setCoords(ptA.x, ptA.y, ptA.x, ptA.y);
			qtIterB.resetIterator(env_a, tolerance);

			for (int elementHandleB = qtIterB.next(); elementHandleB != -1; elementHandleB = qtIterB
					.next()) {
				int vertex_b = quadTreeB.getElement(elementHandleB);
				multipoint_b.getXY(vertex_b, ptB);

				if (Point2D.sqrDistance(ptA, ptB) <= tolerance_sq)
					return true;
			}
		}

		return false;
	}
1313994
boolean computeRectifyH( double f1 , double f2 , DMatrixRMaj P2, DMatrixRMaj H ) {

		estimatePlaneInf.setCamera1(f1,f1,0,0,0);
		estimatePlaneInf.setCamera2(f2,f2,0,0,0);

		if( !estimatePlaneInf.estimatePlaneAtInfinity(P2,planeInf) )
			return false;

		// TODO add a cost for distance from nominal and scale other cost by focal length fx for each view
//		RefineDualQuadraticConstraint refine = new RefineDualQuadraticConstraint();
//		refine.setZeroSkew(true);
//		refine.setAspectRatio(true);
//		refine.setZeroPrinciplePoint(true);
//		refine.setKnownIntrinsic1(true);
//		refine.setFixedCamera(false);
//
//		CameraPinhole intrinsic = new CameraPinhole(f1,f1,0,0,0,0,0);
//		if( !refine.refine(normalizedP.toList(),intrinsic,planeInf))
//			return false;

		K1.zero();
		K1.set(0,0,f1);
		K1.set(1,1,f1);
		K1.set(2,2,1);
		MultiViewOps.createProjectiveToMetric(K1,planeInf.x,planeInf.y,planeInf.z,1,H);

		return true;
	}
647153
public void setPos(Object p) {
        Object[] a = (Object[]) p;
        buf = (char[]) a[0];
        int[] v = (int[]) a[1];
        pos.setIndex(v[0]);
        bufPos = v[1];
    }
218184
function(p) {
        var v = this.b.sub(this.a);
        var t = p.sub(this.a).dot(v) / v.magSquared();
        // Check to see if t is beyond the extents of the line segment
        if (t < 0.0) {
            return this.a.copy();
        } else if (t > 1.0) {
            return this.b.copy();
        }
        // Return the point between 'a' and 'b'
        return this.a.add(v.scaleSelf(t));
    }
754331
public void updateLocation(Point p, Symbol symbol) {
        int row = p.y;
        int column = p.x;
        this.maze[row][column] = symbol.value();
    }
1177252
public static boolean isOpaqueTransparentExclusive(int colorA, int colorB)
    {
        return colorA == ColorRgba.TRANSPARENT.getRgba() && colorB == ColorRgba.OPAQUE.getRgba()
               || colorA == ColorRgba.OPAQUE.getRgba() && colorB == ColorRgba.TRANSPARENT.getRgba();
    }
695171
static boolean pointInPolygon(float[] pt, float[] verts, int nverts) {
        // TODO: Replace pnpoly with triArea2D tests?
        int i, j;
        boolean c = false;
        for (i = 0, j = nverts - 1; i < nverts; j = i++) {
            int vi = i * 3;
            int vj = j * 3;
            if (((verts[vi + 2] > pt[2]) != (verts[vj + 2] > pt[2])) && (pt[0] < (verts[vj + 0] - verts[vi + 0])
                    * (pt[2] - verts[vi + 2]) / (verts[vj + 2] - verts[vi + 2]) + verts[vi + 0])) {
                c = !c;
            }
        }
        return c;
    }
987864
void addPoint(GraphicPoint offPt, int i_src) {
		if (m_offsetPtCount == 0) // TODO: can we have this outside of this
									// method?
		{
			addPoint(offPt);
			return;
		}

		int n_src = m_srcPtCount;
		GraphicPoint pt1, pt;
		pt1 = m_srcPts.get(i_src == 0 ? n_src - 1 : i_src - 1);
		pt = m_srcPts.get(i_src);

		// calculate scalar product to determine if the offset segment goes in
		// the same/opposite direction compared to the original one
		double s = scal(pt1, pt, m_offsetPts.get(m_offsetPtCount - 1), offPt);
		if (s > 0)
		// original segment and offset segment go in the same direction. Just
		// add the point
		{
			addPoint(offPt);
			return;
		}

		if (s < 0) {
			// we will add a loop. We need to make sure the points we introduce
			// don't generate a "reversed" segment
			// let's project the first point of the reversed segment
			// (m_offsetPts + m_offsetPtCount - 1) to check
			// if it falls on the good side of the original segment (scalar
			// product sign again)
			if (scal(pt1, pt, pt, m_offsetPts.get(m_offsetPtCount - 1)) > 0) {
				GraphicPoint p;

				// change value of m_offsetPts + m_offsetPtCount - 1
				int k;
				if (i_src == 0)
					k = n_src - 2;
				else if (i_src == 1)
					k = n_src - 1;
				else
					k = i_src - 2;
				GraphicPoint pt0 = m_srcPts.get(k);

				double a = Math.atan2(pt1.y - pt0.y, pt1.x - pt0.x);
				p = new GraphicPoint(pt1, m_distance, a - half_pi);
				m_offsetPts.set(m_offsetPtCount - 1, p);

				if (m_joins == OperatorOffset.JoinType.Bevel
						|| m_joins == OperatorOffset.JoinType.Miter) {
					// this block is added as well as the commented BAD_SEG in
					// the next block
					p = new GraphicPoint(p, pt1);
					addPoint(p);

					// "bad" segment
					p = new GraphicPoint(pt1, m_distance, m_a1 + half_pi);

					GraphicPoint p_ = new GraphicPoint(p, pt1);
					p_.type |= BAD_SEG;
					addPoint(p_);

					addPoint(p);
				} else {
					// the working stuff for round and square

					// "bad" segment
					p = new GraphicPoint(pt1, m_distance, m_a1 + half_pi);
					p.type |= BAD_SEG;
					addPoint(p);
				}

				// add offPt
				addPoint(offPt, i_src);
			} else {
				GraphicPoint p;

				// we don't add offPt but the loop containing the "bad" segment
				p = new GraphicPoint(pt, m_distance, m_a1 + half_pi);
				addPoint(p);

				if (m_joins == OperatorOffset.JoinType.Bevel
						|| m_joins == OperatorOffset.JoinType.Miter) {
					// this block is added as well as the commented BAD_SEG in
					// the next block
					p = new GraphicPoint(p, pt);
					addPoint(p);

					p = new GraphicPoint(pt, m_distance, m_a2 - half_pi);
					GraphicPoint p_ = new GraphicPoint(p, pt);
					p_.type |= BAD_SEG;
					addPoint(p_);

					addPoint(p);
				} else {
					// the working stuff for round and square
					p = new GraphicPoint(pt, m_distance, m_a2 - half_pi);
					p.type |= BAD_SEG;
					addPoint(p);
				}
			}
		}
	}
312386
private ResultPoint[] detectSolid2(ResultPoint[] points) {
    // A..D
    // :  :
    // B--C
    ResultPoint pointA = points[0];
    ResultPoint pointB = points[1];
    ResultPoint pointC = points[2];
    ResultPoint pointD = points[3];

    // Transition detection on the edge is not stable.
    // To safely detect, shift the points to the module center.
    int tr = transitionsBetween(pointA, pointD);
    ResultPoint pointBs = shiftPoint(pointB, pointC, (tr + 1) * 4);
    ResultPoint pointCs = shiftPoint(pointC, pointB, (tr + 1) * 4);
    int trBA = transitionsBetween(pointBs, pointA);
    int trCD = transitionsBetween(pointCs, pointD);

    // 0..3
    // |  :
    // 1--2
    if (trBA < trCD) {
      // solid sides: A-B-C
      points[0] = pointA;
      points[1] = pointB;
      points[2] = pointC;
      points[3] = pointD;
    } else {
      // solid sides: B-C-D
      points[0] = pointB;
      points[1] = pointC;
      points[2] = pointD;
      points[3] = pointA;
    }

    return points;
  }
927465
private static Triangle findnext1(Vector3 p, Triangle v) {
		if (!v.abnext.halfplane && PointLineTest.pointLineTest(v.a, v.b, p) == PointLinePosition.RIGHT)
			return v.abnext;
		if (!v.bcnext.halfplane && PointLineTest.pointLineTest(v.b, v.c, p) == PointLinePosition.RIGHT)
			return v.bcnext;
		if (!v.canext.halfplane && PointLineTest.pointLineTest(v.c, v.a, p) == PointLinePosition.RIGHT)
			return v.canext;
		if (PointLineTest.pointLineTest(v.a, v.b, p) == PointLinePosition.RIGHT)
			return v.abnext;
		if (PointLineTest.pointLineTest(v.b, v.c, p) == PointLinePosition.RIGHT)
			return v.bcnext;
		if (PointLineTest.pointLineTest(v.c, v.a, p) == PointLinePosition.RIGHT)
			return v.canext;
		return null;
	}
1103685
public final void set(Point p1, Point p2)
    {
        set(p1.getX(), p1.getY(), p2.getX(), p2.getY());
    }
762066
private static boolean multiPointWithinPoint_(MultiPoint multipoint_a,
			Point point_b, double tolerance, ProgressTracker progress_tracker) {
		return multiPointEqualsPoint_(multipoint_a, point_b, tolerance,
				progress_tracker);
	}
841629
function(pos, pointer) {
    var mode = this.options.selection.mode,
        selection = this.selection.selection;

    if(mode.indexOf('x') == -1) {
      pos.x = (pos == selection.first) ? 0 : this.plotWidth;         
    }else{
      pos.x = boundX(pointer.relX, this);
    }

    if (mode.indexOf('y') == -1) {
      pos.y = (pos == selection.first) ? 0 : this.plotHeight - 1;
    }else{
      pos.y = boundY(pointer.relY, this);
    }
  }
278906
public void markConstrainedEdge( TriangulationPoint p, TriangulationPoint q )
    {
        if( ( q == points[0] && p == points[1] ) || ( q == points[1] && p == points[0] ) )
        {
            cEdge[2] = true;
        }
        else if( ( q == points[0] && p == points[2] ) || ( q == points[2] && p == points[0] ) )
        {
            cEdge[1] = true;
        }
        else if( ( q == points[1] && p == points[2] ) || ( q == points[2] && p == points[1] ) )
        {
            cEdge[0] = true;
        }
    }
459264
@Override
	public double calculatePhase1InitialFeasiblePoint(double[] originalNotFeasiblePoint, double tolerance){
		RealMatrix F = this.buildS(originalNotFeasiblePoint).scalarMultiply(-1);
		RealMatrix S = F.scalarMultiply(-1);
		try{
			new CholeskyDecomposition(S);
			//already feasible
			return -1;
		}catch(NonPositiveDefiniteMatrixException ee){
			//it does NOT mean that F is negative, it can be not definite
			EigenDecomposition eFact = new EigenDecomposition(F);
			double[] eValues = eFact.getRealEigenvalues();
			double minEigenValue = eValues[Utils.getMinIndex(DoubleFactory1D.dense.make(eValues))];
			return  -Math.min(minEigenValue * Math.pow(tolerance, -0.5), 0.);
		}
	}