Skip to content

Commit

Permalink
Classes to represent a decoration.
Browse files Browse the repository at this point in the history
See #49
  • Loading branch information
nvcleemp committed Feb 21, 2018
1 parent 224a47f commit 9b62a52
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cage/decoration/Decoration.java
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();
}
}
33 changes: 33 additions & 0 deletions cage/decoration/DecorationVertex.java
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;
}
}
69 changes: 69 additions & 0 deletions cage/decoration/VertexPosition.java
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;
}
}

0 comments on commit 9b62a52

Please sign in to comment.