/** * Takes in two ranges each of which are of size at most two and returns the two points on each respective polygon which are closest to one another */ private static Point2d[] getClosestPointsFromRemainingEdgesAndVertices(ConvexPolygon2d polygon1, ConvexPolygon2d polygon2, int v1Start, int v1End, int v2Start, int v2End) { if ((v1Start == v1End) && (v2Start == v2End)) { return new Point2d[] {polygon1.getVertex(v1Start), polygon2.getVertex(v2Start)}; } else if (v1Start == v1End) { return finalPhasePointAndEdge(polygon2.getVertex(v2Start), polygon2.getVertex(v2End), polygon1.getVertex(v1Start)); } else if (v2Start == v2End) { Point2d[] reverseOutput = finalPhasePointAndEdge(polygon1.getVertex(v1Start), polygon1.getVertex(v1End), polygon2.getVertex(v2Start)); return new Point2d[] {reverseOutput[1], reverseOutput[0]}; // switch order of output so that points are returned in the order that their polygons were inputed } return finalPhaseTwoEdges(polygon1.getVertex(v1Start), polygon1.getVertex(v1End), polygon2.getVertex(v2Start), polygon2.getVertex(v2End)); }
/** * Takes in two ranges each of which are of size at most two and returns the two points on each * respective polygon which are closest to one another */ private void getClosestPointsFromRemainingEdgesAndVertices(ConvexPolygon2DReadOnly polygon1, ConvexPolygon2DReadOnly polygon2, int v1Start, int v1End, int v2Start, int v2End, Point2DBasics point1ToPack, Point2DBasics point2ToPack) { if ((v1Start == v1End) && (v2Start == v2End)) { point1ToPack.set(polygon1.getVertex(v1Start)); point2ToPack.set(polygon2.getVertex(v2Start)); } else if (v1Start == v1End) { finalPhasePointAndEdge(polygon2.getVertex(v2Start), polygon2.getVertex(v2End), polygon1.getVertex(v1Start), point1ToPack, point2ToPack); } else if (v2Start == v2End) { finalPhasePointAndEdge(polygon1.getVertex(v1Start), polygon1.getVertex(v1End), polygon2.getVertex(v2Start), point2ToPack, point1ToPack); } else { finalPhaseTwoEdges(polygon1.getVertex(v1Start), polygon1.getVertex(v1End), polygon2.getVertex(v2Start), polygon2.getVertex(v2End), point1ToPack, point2ToPack); } }