CommonAlgorithmsFromCartAGen { public static IDirectPosition projectionOrtho(IDirectPosition point, ILineString line, Vector2D direction) { if (direction.isNull()) return null; Vector2D ortho1 = direction.rotate(-Math.PI / 2); Vector2D ortho2 = direction.rotate(Math.PI / 2); IDirectPosition proj1 = projection(point, line, ortho1); IDirectPosition proj2 = projection(point, line, ortho2); if (proj1 == null) return proj2; if (proj2 == null) return proj1; if (proj1.distance2D(point) < proj2.distance2D(point)) return proj1; else return proj2; }  static IDirectPosition getNearestVertexFromPoint(IGeometry geom,
      IDirectPosition point); static int getNearestVertexPositionFromPoint(IGeometry geom,
      IDirectPosition point); static int getNearestVertexPositionBeforePoint(IGeometry geom,
      IDirectPosition point); static ILineString insertVertex(ILineString line,
      IDirectPosition newVertex); static ILineString insertVertex(ILineString line,
      IDirectPosition newVertex, double tolerance); static IPolygon insertVertex(IPolygon polygon,
      IDirectPosition newVertex); static IPolygon insertVertex(IPolygon polygon,
      IDirectPosition newVertex, double tolerance); static ILineString[] splitLine(ILineString line,
      IDirectPosition splitVertex, double tolerance); static IDirectPosition getNearestOtherVertexFromPoint(IGeometry geom,
      IDirectPosition point); static ILineSegment getNearestSegmentFromPoint(IGeometry geom,
      IDirectPosition point); static Vector2D rotateVector(Vector2D v, double angle); static double getOverlappingLength(IPolygon poly1, IPolygon poly2); static double getOverlappingLength(ILineString line, IPolygon poly); static double angleBetween2Lines(ILineString line1,
      ILineString line2); static Angle lineAbsoluteOrientation(ILineString line,
      IDirectPosition point); static int getNbCommonVertices(IGeometry geom1, IGeometry geom2); static LineConnectionInfo getLineConnectionInfo(ILineString line1,
      ILineString line2); static boolean isLineCrossingPolygon(ILineString line, IPolygon poly); static IGeometry geomColnUnion(Collection<IGeometry> geomColn); static IGeometry geomColnIntersection(Collection<IGeometry> geomColn); static double getSidelongMaxDist(IPolygon poly, double orientation); static IDirectPosition projection(IDirectPosition point,
      ILineString line, Vector2D direction); static IDirectPosition projectionOrtho(IDirectPosition point,
      ILineString line, Vector2D direction); static IPolygon getBiggerFromMultiSurface(
      IMultiSurface<IOrientableSurface> multi); static ILineString getLongestFromMultiCurve(
      IMultiCurve<IOrientableCurve> multi); static IPolygon getBiggerFromAggregate(IAggregate<IGeometry> aggr); static IDirectPosition getCommonVertexBetween2Lines(ILineString line1,
      ILineString line2); static Set<IRing> getIntersectingInnerRings(IPolygon multiRing,
      IGeometry geom); static IRing getContainingInnerRing(IPolygon multiRing,
      IGeometry geom); static ILineString displaceOneSide(ILineString line, boolean start,
      Vector2D displacementVector); static double getLineDistanceToIndex(ILineString line, int index); static double getLineDistanceBetweenIndexes(ILineString line,
      int index1, int index2); static ILineString getSubLine(ILineString line, IDirectPosition pt1,
      IDirectPosition pt2); static double getShortestEdgeLength(IGeometry geom); static double getEdgeLengthMedian(IGeometry geom); static Vector<Object> getPtMaxXFromLine(ILineString line); static Vector<Object> getPtMaxXFromPolygon(IPolygon line); static IDirectPosition getPtMaxDirFromLine(ILineString line,
      Angle theta); static IPolygon removeHoles(IPolygon polygon); static IPolygon removeSmallHoles(IPolygon polygon, double area); static ILineString getLongestInsideSegment(IPolygon polygon,
      double orientation); static ILineString getPolygonDiameter(IPolygon polygon); static boolean areLinesSameDirection(ILineString line,
      ILineString subLine); static ILineString openRingAtIndex(IRing ring, int index); static List<IDirectPosition> getSharpAngleVertices(IPolygon polygon,
      double maxAngle); static ILineString getMeanLine(ILineString line1, ILineString line2); static List<IDirectPosition> getSelfIntersections(ILineString line); static ILineString removeDuplicates(ILineString line);  }
@Test public void testProjectionOrtho() { IDirectPosition point = new DirectPosition(1.0, 1.0); Vector2D direction = new Vector2D(0.0, 1.0); IDirectPositionList list = new DirectPositionList(); IDirectPositionList list2 = new DirectPositionList(); IDirectPosition p1 = new DirectPosition(2.0, 0.0); IDirectPosition p2 = new DirectPosition(2.0, 1.0); IDirectPosition p3 = new DirectPosition(2.0, 4.0); list.add(p1); list.add(p2); list.add(p3); list2.add(p1); list2.add(p3); ILineString line = new GM_LineString(list); ILineString line2 = new GM_LineString(list2); IDirectPosition proj = CommonAlgorithmsFromCartAGen.projectionOrtho(point, line, direction); Assert.assertTrue(proj.equals(new DirectPosition(2.0, 1.0))); Assert.assertTrue(CommonAlgorithmsFromCartAGen.projectionOrtho(point, line2, direction).equals(new DirectPosition(2.0, 1.0))); }