diff --git a/cage/decoration/Decoration.java b/cage/decoration/Decoration.java new file mode 100644 index 0000000..52c996f --- /dev/null +++ b/cage/decoration/Decoration.java @@ -0,0 +1,58 @@ +package cage.decoration; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** + * Class to represent a decoration. + * + * @author nvcleemp + */ +public class Decoration { + + private final List border = new ArrayList<>(); + private final List vertices = new ArrayList<>(); + private final Map> neighbours = new HashMap<>(); + + public Decoration(List vertices, List border, Map> neighbours) { + this.vertices.addAll(vertices); + this.border.addAll(border); + for (DecorationVertex v : vertices) { + this.neighbours.put(v, new ArrayList<>(neighbours.get(v))); + } + } + + public Iterable getBorder(){ + return () -> new Iterator() { + + private int pos = -1; + + @Override + public boolean hasNext() { + return true; + } + + @Override + public DecorationVertex next() { + pos = (pos+1)%border.size(); + return border.get(pos); + } + }; + } + + public int getVertexCount(){ + return vertices.size(); + } + + public Stream getVerticesAsStream(){ + return vertices.stream(); + } + + public Stream getNeighboursAsStream(DecorationVertex v){ + return neighbours.get(v).stream(); + } +} diff --git a/cage/decoration/DecorationVertex.java b/cage/decoration/DecorationVertex.java new file mode 100644 index 0000000..57fdfa9 --- /dev/null +++ b/cage/decoration/DecorationVertex.java @@ -0,0 +1,33 @@ +package cage.decoration; + +/** + * Class to represent a vertex in a decoration. Each vertex has an id, a position + * in the decoration, and a type. For INTERNAL vertices only those of type VERTEX + * need to be specified. + * + * @author nvcleemp + */ +public class DecorationVertex { + + private final int id; + private final VertexPosition position; + private final FacetType type; + + public DecorationVertex(int id, VertexPosition position, FacetType type) { + this.id = id; + this.position = position; + this.type = type; + } + + public int getId() { + return id; + } + + public VertexPosition getPosition() { + return position; + } + + public FacetType getType() { + return type; + } +} diff --git a/cage/decoration/VertexPosition.java b/cage/decoration/VertexPosition.java new file mode 100644 index 0000000..20b6d14 --- /dev/null +++ b/cage/decoration/VertexPosition.java @@ -0,0 +1,69 @@ +package cage.decoration; + +/** + * Enum to represent the different positions of a vertex in a decoration. + * @author nvcleemp + */ +public enum VertexPosition { + INTERNAL, + EDGE_VERTEX(FacetType.VERTEX), EDGE_EDGE(FacetType.EDGE), EDGE_FACE(FacetType.FACE), + CORNER_VERTEX{ + + @Override + public boolean isCorner() { + return true; + } + + }, + CORNER_EDGE{ + + @Override + public FacetType getReflectingEdge(VertexPosition source) { + switch(source){ + case CORNER_FACE: + case EDGE_VERTEX: + return FacetType.FACE; + case CORNER_VERTEX: + case EDGE_FACE: + return FacetType.VERTEX; + default: + throw new UnsupportedOperationException(); + } + } + + @Override + public boolean isCorner() { + return true; + } + + }, + CORNER_FACE{ + + @Override + public boolean isCorner() { + return true; + } + + }; + + private final FacetType reflectingEdge; + + private VertexPosition() { + this(null); + } + + private VertexPosition(FacetType reflectingEdge) { + this.reflectingEdge = reflectingEdge; + } + + public FacetType getReflectingEdge(VertexPosition source){ + if(reflectingEdge==null) + throw new UnsupportedOperationException(); + else + return reflectingEdge; + } + + public boolean isCorner(){ + return false; + } +}