-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #49
- Loading branch information
Showing
3 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DecorationVertex> border = new ArrayList<>(); | ||
private final List<DecorationVertex> vertices = new ArrayList<>(); | ||
private final Map<DecorationVertex, List<DecorationVertex>> neighbours = new HashMap<>(); | ||
|
||
public Decoration(List<DecorationVertex> vertices, List<DecorationVertex> border, Map<DecorationVertex, List<DecorationVertex>> neighbours) { | ||
this.vertices.addAll(vertices); | ||
this.border.addAll(border); | ||
for (DecorationVertex v : vertices) { | ||
this.neighbours.put(v, new ArrayList<>(neighbours.get(v))); | ||
} | ||
} | ||
|
||
public Iterable<DecorationVertex> getBorder(){ | ||
return () -> new Iterator<DecorationVertex>() { | ||
|
||
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<DecorationVertex> getVerticesAsStream(){ | ||
return vertices.stream(); | ||
} | ||
|
||
public Stream<DecorationVertex> getNeighboursAsStream(DecorationVertex v){ | ||
return neighbours.get(v).stream(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |