示例#1
0
  private FigureMovableImpl createFigure(InputStream is) throws Exception {
    FigureType figureType = unmarshall(is);

    Map<String, Vertex> vertices = new HashMap<String, Vertex>();
    for (VertexType vertexType : figureType.getVertices()) {
      vertices.put(vertexType.getName(), createVertexFrom(vertexType));
    }

    Map<String, Edge> edges = new HashMap<String, Edge>();
    Map<Vertex, Set<Edge>> verticesEdges = new HashMap<Vertex, Set<Edge>>();
    for (EdgeType edgeType : figureType.getEdges()) {
      Edge edge = createEdgeFrom(edgeType, vertices);

      putEdgeIntoVerticesEdgesMap(verticesEdges, edge.getA(), edge);
      putEdgeIntoVerticesEdgesMap(verticesEdges, edge.getB(), edge);
      edges.put(edgeType.getName(), edge);
    }

    Map<String, Face> faces = new HashMap<String, Face>();
    for (FaceType faceType : figureType.getFaces()) {
      faces.put(faceType.getName(), createFaceFrom(faceType, edges, vertices, verticesEdges));
    }

    Double givenPrecision = figureType.getPrecision();
    double precision = (givenPrecision != null) ? givenPrecision : Pointable.PRECISION;

    return new FigureMovableImpl(
        new HashSet<Face>(faces.values()), new HashSet<Edge>(edges.values()), precision);
  }
示例#2
0
 private Vertex createVertexFrom(VertexType vertexType) {
   double[] coords = {0, 0, 0, 0};
   String[] arrCoords = vertexType.getCoords().split(",");
   for (int i = 0; i < arrCoords.length; i++) {
     coords[i] = Double.parseDouble(arrCoords[i].trim());
   }
   return new Vertex(coords);
 }