private Pair<Point2D, Point2D> getAPointInReachblePartEdges(Area area, Edge relatedEdge) { Point2D point = null; Edge rEdge = null; if (area instanceof Road) { Road road = (Road) area; FOR: for (SOSArea reachablePart : road.getReachableParts()) { for (Edge edge : reachablePart.getEdges()) { if (edge.getReachablityIndex() >= 0 && area.getEdges().get(edge.getReachablityIndex()).equals(relatedEdge)) { point = edge.getMidPoint(); rEdge = edge; break FOR; } } } } if (point == null) { point = relatedEdge.getMidPoint(); rEdge = relatedEdge; } ArrayList<Point2D> twoPointForCheckContain = Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 10); ArrayList<Point2D> twoPoint = Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 3000); if (area.getShape().contains(twoPointForCheckContain.get(0).toGeomPoint())) return new Pair<Point2D, Point2D>(twoPoint.get(0), twoPoint.get(1)); else return new Pair<Point2D, Point2D>(twoPoint.get(1), twoPoint.get(0)); }
// Morteza2011***************************************************************** public void setExpandedBlock(boolean isNewBlockade) { SOSArea area = new SOSArea(getEdges()); ArrayList<Blockade> b = new ArrayList<Blockade>(); b.add(this); area.setReachablityBlockades(b); if (isNewBlockade) expandedBlock = ExpandBlockade.expandBlock( area, ReachablityConstants.BLOCK_EXPAND_WIDTH + getPosition().getExtraDistanceForNewExpand()); else expandedBlock = ExpandBlockade.expandBlock(area, ReachablityConstants.BLOCK_EXPAND_WIDTH); }
// Morteza2011***************************************************************** public static SOSArea reMerge(SOSArea blockade1, SOSArea blockade2) { java.awt.geom.Area a1 = new Area(blockade1.getShape()); java.awt.geom.Area a2 = new Area(blockade2.getShape()); a1.add(a2); int[] apexes = AliGeometryTools.getApexes(a1); ArrayList<Edge> edges = new ArrayList<Edge>(); for (int i = 0; i < apexes.length / 2 - 1; i++) { edges.add(new Edge(apexes[i * 2], apexes[i * 2 + 1], apexes[i * 2 + 2], apexes[i * 2 + 3])); } SOSArea finalArea = new SOSArea(edges); finalArea.addReachablityBlockades(blockade1.getReachablityBlockades()); finalArea.addReachablityBlockades(blockade2.getReachablityBlockades()); return finalArea; }
// Morteza2011***************************************************************** public static ArrayList<SOSArea> mergeBlockades(Road road, ArrayList<SOSArea> blockades) { // log(road).logln("RoadID:" + road.getID()); // for (SOSArea b : blockades) { // log(road).logln(b.getReachablityBlockades()); // } for (short i = 0; i < blockades.size(); i++) { for (short j = (short) (i + 1); j < blockades.size(); j++) { if (Utility.hasIntersect(blockades.get(i), blockades.get(j))) { SOSArea a1 = blockades.get(i); SOSArea a2 = blockades.get(j); SOSArea a3; try { a3 = merge(road, a1, a2, (short) (0)); } catch (Exception e) { a3 = reMerge(a1, a2); e.printStackTrace(); } blockades.remove(j--); if (!a3.getEdges().isEmpty()) { blockades.set(i, a3); } i--; break; } else { try { if (blockades .get(i) .getShape() .contains( blockades.get(j).getEdges().get(0).getStart().getX(), blockades.get(j).getEdges().get(0).getStart().getY())) { // log(road).logln(blockades.get(j)+" has included in "+blockades.get(i)); blockades.get(i).addReachablityBlockades(blockades.get(j).getReachablityBlockades()); blockades.remove(j--); } else { if (blockades .get(j) .getShape() .contains( blockades.get(i).getEdges().get(0).getStart().getX(), blockades.get(i).getEdges().get(0).getStart().getY())) { // log(road).logln(blockades.get(i)+" has included in "+blockades.get(j)); blockades .get(j) .addReachablityBlockades(blockades.get(i).getReachablityBlockades()); blockades.remove(i--); break; } // else // log(road).logln("intersect:no and included:no!"); } } catch (Exception e) { try { e.printStackTrace(); SOSArea a1 = blockades.get(i); SOSArea a2 = blockades.get(j); SOSArea a3; a3 = reMerge(a1, a2); blockades.remove(j--); if (!a3.getEdges().isEmpty()) { blockades.set(i, a3); } i--; break; } catch (Exception e1) { } } } } } return blockades; }
// Morteza2011***************************************************************** public static SOSArea merge( StandardEntity a, SOSArea blockade1, SOSArea blockade2, short mergedNumber) { ArrayList<Edge> edgeList1 = new ArrayList<Edge>(blockade1.getEdges()); ArrayList<Edge> edgeList2 = new ArrayList<Edge>(blockade2.getEdges()); Pair<ArrayList<Edge>, ArrayList<Edge>> newEdges = splitEdges(edgeList1, edgeList2); removeExtraEdges(newEdges.first(), blockade2.getShape()); removeExtraEdges(newEdges.second(), blockade1.getShape()); try { ArrayList<SOSArea> sortedEdges = sortEdges(a, newEdges.first(), newEdges.second(), false); SOSArea finalMergedArea; if (sortedEdges.size() > 1) finalMergedArea = removeHoles(sortedEdges); else if (sortedEdges.size() == 1) finalMergedArea = sortedEdges.get(0); else { return reMerge(blockade1, blockade2); } finalMergedArea.setEdges(verifyEdgesAfterMerge(finalMergedArea.getEdges())); finalMergedArea.setReachablityBlockades(blockade1.getReachablityBlockades()); finalMergedArea.addReachablityBlockades(blockade2.getReachablityBlockades()); return finalMergedArea; } catch (ReachablityException e) { } return reMerge(blockade1, blockade2); }