Skip to content
Browse files

Refactoring: encapsulate field 2/3

git-svn-id: https://svn.sosy-lab.org/software/ccvisu/branches/use-common@1132 fc36ee94-785d-4715-976b-05dfc5071072
  • Loading branch information...
1 parent e381f1f commit e505c11808b01118ec742eda5145ef46dba0345e kaeufl committed
View
4 src/org/sosy_lab/ccvisu/CCVisuController.java
@@ -425,9 +425,9 @@ private void applyInitialLayout(GraphData graph) {
newPosition.x = 2 * (float) Math.random() - 1;
if (dimension >= 2) {
- newPosition.y = 2 * (float) Math.random() - 1;
+ newPosition.setY(2 * (float) Math.random() - 1);
} else {
- newPosition.y = 0;
+ newPosition.setY(0);
}
if (dimension == 3) {
View
4 src/org/sosy_lab/ccvisu/clustering/BuggyMinDistClusterer.java
@@ -106,11 +106,11 @@ public BuggyMinDistClusterer(GraphData graph, LogManager logger,
clusters.add(vertexCluster);
maxX = Math.max(maxX, v.getPosition().x);
- maxY = Math.max(maxY, v.getPosition().y);
+ maxY = Math.max(maxY, v.getPosition().getY());
maxZ = Math.max(maxZ, v.getPosition().getZ());
minX = Math.min(maxX, v.getPosition().x);
- minY = Math.min(maxY, v.getPosition().y);
+ minY = Math.min(maxY, v.getPosition().getY());
minZ = Math.min(maxZ, v.getPosition().getZ());
}
View
4 src/org/sosy_lab/ccvisu/clustering/ClustererMinDistPerc.java
@@ -108,11 +108,11 @@ public ClustererMinDistPerc(GraphData graph, LogManager logger, int numberOfClus
clusters.add(vertexCluster);
maxX = Math.max(maxX, vertex.getPosition().x);
- maxY = Math.max(maxY, vertex.getPosition().y);
+ maxY = Math.max(maxY, vertex.getPosition().getY());
maxZ = Math.max(maxZ, vertex.getPosition().getZ());
minX = Math.min(minX, vertex.getPosition().x);
- minY = Math.min(minY, vertex.getPosition().y);
+ minY = Math.min(minY, vertex.getPosition().getY());
minZ = Math.min(minZ, vertex.getPosition().getZ());
}
View
4 src/org/sosy_lab/ccvisu/graph/GraphicLayoutInfo.java
@@ -74,7 +74,7 @@ public Position mapToOriginal(Position position) {
resultPos.add(offset);
resultPos.mult(getScale());
// Flip y-coordinate.
- resultPos.y += sizeY;
+ resultPos.setY(resultPos.getY() + sizeY);
return resultPos;
}
@@ -82,7 +82,7 @@ public Position mapToOriginal(Position position) {
public Position mapToLayout(Position position) {
Position resultPos = new Position(position);
- resultPos.y -= sizeY;
+ resultPos.setY(resultPos.getY() - sizeY);
resultPos.div(getScale());
resultPos.subtract(offset);
View
50 src/org/sosy_lab/ccvisu/graph/Position.java
@@ -31,7 +31,7 @@
public class Position {
public float x = 0.0f;
- public float y = 0.0f;
+ private float y = 0.0f;
private float z = 0.0f;
public Position() {
@@ -39,12 +39,12 @@ public Position() {
public Position(float x, float y, float z) {
this.x = x;
- this.y = y;
+ this.setY(y);
this.setZ(z);
}
public Position(Position position) {
- this(position.x, position.y, position.getZ());
+ this(position.x, position.getY(), position.getZ());
}
public float getX() {
@@ -55,6 +55,10 @@ public float getY() {
return y;
}
+ public void setY(float y) {
+ this.y = y;
+ }
+
public float getZ() {
return z;
}
@@ -64,46 +68,46 @@ public void setZ(float z) {
}
public boolean equals(Position position) {
- return (x == position.x && y == position.y && getZ() == position.getZ());
+ return (x == position.x && getY() == position.getY() && getZ() == position.getZ());
}
public boolean lessEq(Position position) {
- return (x <= position.x && y <= position.y && getZ() <= position.getZ());
+ return (x <= position.x && getY() <= position.getY() && getZ() <= position.getZ());
}
public void add(Position position) {
x += position.x;
- y += position.y;
+ setY(getY() + position.getY());
setZ(getZ() + position.getZ());
}
public void subtract(Position position) {
x -= position.x;
- y -= position.y;
+ setY(getY() - position.getY());
setZ(getZ() - position.getZ());
}
public void mult(Position position) {
x *= position.x;
- y *= position.y;
+ setY(getY() * position.getY());
setZ(getZ() * position.getZ());
}
public void div(Position position) {
x /= position.x;
- y /= position.y;
+ setY(getY() / position.getY());
setZ(getZ() / position.getZ());
}
public void mult(float scalar) {
x *= scalar;
- y *= scalar;
+ setY(getY() * scalar);
setZ(getZ() * scalar);
}
public void div(float scalar) {
x /= scalar;
- y /= scalar;
+ setY(getY() / scalar);
setZ(getZ() / scalar);
}
@@ -111,7 +115,7 @@ public static Position add(Position position, float scalar) {
Position result = new Position(position);
result.x += scalar;
- result.y += scalar;
+ result.setY(result.getY() + scalar);
result.setZ(result.getZ() + scalar);
return result;
@@ -121,7 +125,7 @@ public static Position subtract(Position position, float scalar) {
Position result = new Position(position);
result.x -= scalar;
- result.y -= scalar;
+ result.setY(result.getY() - scalar);
result.setZ(result.getZ() - scalar);
return result;
@@ -131,7 +135,7 @@ public static Position mult(Position position, float scalar) {
Position result = new Position(position);
result.x *= scalar;
- result.y *= scalar;
+ result.setY(result.getY() * scalar);
result.setZ(result.getZ() * scalar);
return result;
@@ -141,7 +145,7 @@ public static Position div(Position position, float scalar) {
Position result = new Position(position);
result.x /= scalar;
- result.y /= scalar;
+ result.setY(result.getY() / scalar);
result.setZ(result.getZ() / scalar);
return result;
@@ -151,7 +155,7 @@ public static Position add(Position pos1, Position pos2) {
Position result = new Position(pos1);
result.x += pos2.x;
- result.y += pos2.y;
+ result.setY(result.getY() + pos2.getY());
result.setZ(result.getZ() + pos2.getZ());
return result;
@@ -161,7 +165,7 @@ public static Position subtract(Position pos1, Position pos2) {
Position result = new Position(pos1);
result.x -= pos2.x;
- result.y -= pos2.y;
+ result.setY(result.getY() - pos2.getY());
result.setZ(result.getZ() - pos2.getZ());
return result;
@@ -171,7 +175,7 @@ public static Position mult(Position pos1, Position pos2) {
Position result = new Position(pos1);
result.x *= pos2.x;
- result.y *= pos2.y;
+ result.setY(result.getY() * pos2.getY());
result.setZ(result.getZ() * pos2.getZ());
return result;
@@ -181,7 +185,7 @@ public static Position div(Position pos1, Position pos2) {
Position result = new Position(pos1);
result.x /= pos2.x;
- result.y /= pos2.y;
+ result.setY(result.getY() / pos2.getY());
result.setZ(result.getZ() / pos2.getZ());
return result;
@@ -197,7 +201,7 @@ public static Position min(Collection<GraphVertex> collection,
&& (includeAux || !vertex.isAuxiliaryEdge())) {
minPos.x = Math.min(minPos.x, vertex.getPosition().x);
- minPos.y = Math.min(minPos.y, vertex.getPosition().y);
+ minPos.setY(Math.min(minPos.getY(), vertex.getPosition().getY()));
minPos.setZ(Math.min(minPos.getZ(), vertex.getPosition().getZ()));
}
@@ -216,7 +220,7 @@ public static Position max(Collection<GraphVertex> collection, boolean restrictT
&& (includeAux || !vertex.isAuxiliaryEdge())) {
maxPos.x = Math.max(maxPos.x, vertex.getPosition().x);
- maxPos.y = Math.max(maxPos.y, vertex.getPosition().y);
+ maxPos.setY(Math.max(maxPos.getY(), vertex.getPosition().getY()));
maxPos.setZ(Math.max(maxPos.getZ(), vertex.getPosition().getZ()));
}
}
@@ -234,7 +238,7 @@ public static Position max(Collection<GraphVertex> collection, boolean restrictT
*/
public static float width(Position pos1, Position pos2) {
Position diffPos = Position.subtract(pos1, pos2);
- float width = Math.max(diffPos.x, diffPos.y);
+ float width = Math.max(diffPos.x, diffPos.getY());
width = Math.max(diffPos.getZ(), width);
return width;
@@ -247,7 +251,7 @@ public static float width(Position pos1, Position pos2) {
*/
public float distanceTo(Position position) {
float xDiff = this.x - position.x;
- float yDiff = this.y - position.y;
+ float yDiff = this.getY() - position.getY();
float zDiff = this.getZ() - position.getZ();
return (float) Math.sqrt(xDiff * xDiff
View
2 src/org/sosy_lab/ccvisu/graph/RadiusOfGroup.java
@@ -43,7 +43,7 @@ public float getX() {
}
public float getY() {
- return barycenter.y;
+ return barycenter.getY();
}
public float getZ() {
View
16 src/org/sosy_lab/ccvisu/minimizer/MinimizerBarnesHut.java
@@ -575,7 +575,7 @@ private float addRepulsionDir(final int index, OctTree tree, Position dir) {
private void getDirection(final int index, Position dir) {
Position vertexPosition = graph.getVertices().get(index).getPosition();
dir.x = 0.0f;
- dir.y = 0.0f;
+ dir.setY(0.0f);
dir.setZ(0.0f);
// compute repulsion force vector
@@ -616,7 +616,7 @@ private void getDirection(final int index, Position dir) {
// ensure that the length of dir is at most 1/8
// of the maximum Euclidean distance between nodes
- float length = (float) Math.sqrt(dir.x * dir.x + dir.y * dir.y + dir.getZ() * dir.getZ());
+ float length = (float) Math.sqrt(dir.x * dir.x + dir.getY() * dir.getY() + dir.getZ() * dir.getZ());
if (length > octTree.width() / 8) {
length /= octTree.width() / 8;
dir.div(length);
@@ -795,7 +795,7 @@ private void addNode2(int nodeIndex, Position nodePos, float nodeWeight) {
childIndex += 1 << 0;
}
- if (nodePos.y > (minPos.y + maxPos.y) / 2) {
+ if (nodePos.getY() > (minPos.getY() + maxPos.getY()) / 2) {
childIndex += 1 << 1;
}
@@ -816,11 +816,11 @@ private void addNode2(int nodeIndex, Position nodePos, float nodeWeight) {
}
if ((childIndex & 1 << 1) == 0) {
- newMinPos.y = minPos.y;
- newMaxPos.y = (minPos.y + maxPos.y) / 2;
+ newMinPos.setY(minPos.getY());
+ newMaxPos.setY((minPos.getY() + maxPos.getY()) / 2);
} else {
- newMinPos.y = (minPos.y + maxPos.y) / 2;
- newMaxPos.y = maxPos.y;
+ newMinPos.setY((minPos.getY() + maxPos.getY()) / 2);
+ newMaxPos.setY(maxPos.getY());
}
if ((childIndex & 1 << 2) == 0) {
@@ -859,7 +859,7 @@ private void moveNode(Position oldPos, Position newPos, float nodeWeight) {
childIndex += 1 << 0;
}
- if (oldPos.y > (minPos.y + maxPos.y) / 2) {
+ if (oldPos.getY() > (minPos.getY() + maxPos.getY()) / 2) {
childIndex += 1 << 1;
}
View
20 src/org/sosy_lab/ccvisu/writers/WriterDataLayout.java
@@ -136,7 +136,7 @@ public GraphicLayoutInfo calculateOffsetAndScale(Dimension size) {
if (stretchGraphToBounds) {
width = maxPos.x - minPos.x;
- height = maxPos.y - minPos.y;
+ height = maxPos.getY() - minPos.getY();
} else {
width = Position.width(maxPos, minPos);
height = width;
@@ -154,22 +154,22 @@ public GraphicLayoutInfo calculateOffsetAndScale(Dimension size) {
Position offset = new Position();
offset.x = Position.add(Position.mult(minPos, -1), 0.05f * width).x;
- offset.y = Position.add(Position.mult(minPos, -1), 0.05f * height).y;
+ offset.setY(Position.add(Position.mult(minPos, -1), 0.05f * height).getY());
// Flip y-coordinate.
Position scale = new Position(1, -1, 1);
scale.x *= (0.9f * sizeX / width);
if (stretchGraphToBounds) {
- scale.y *= (0.9f * sizeY / (height + OFFSET_FROM_BORDERS));
+ scale.setY(scale.getY() * (0.9f * sizeY / (height + OFFSET_FROM_BORDERS)));
} else {
- scale.y *= (0.9f * sizeY / height);
+ scale.setY(scale.getY() * (0.9f * sizeY / height));
}
Position maxPosScaled = Position.add(maxPos, offset);
maxPosScaled.mult(scale);
if (stretchGraphToBounds) {
- sizeY = (int) Math.abs(maxPosScaled.y) + OFFSET_FROM_BORDERS;
+ sizeY = (int) Math.abs(maxPosScaled.getY()) + OFFSET_FROM_BORDERS;
} else {
// do nothing
}
@@ -200,8 +200,8 @@ public void writeGraphicsLayout(List<GraphVertex> vertices,
Position sourcePos = graphicLayoutInfo.mapToOriginal(edge.getSource().getPosition());
Position targetPos = graphicLayoutInfo.mapToOriginal(edge.getTarget().getPosition());
- writeEdge(edge, (int) sourcePos.x, (int) sourcePos.y, (int) sourcePos.getZ(),
- (int) targetPos.x, (int) targetPos.y, (int) targetPos.getZ());
+ writeEdge(edge, (int) sourcePos.x, (int) sourcePos.getY(), (int) sourcePos.getZ(),
+ (int) targetPos.x, (int) targetPos.getY(), (int) targetPos.getZ());
}
}
}
@@ -237,16 +237,16 @@ private void calculateAndWriteVertex(int sizeX, int sizeY,
if (vertex.getShape() == Shape.FIXED_SIZE_BOX) {
int radius = 2;
- writeVertex(vertex, (int) position.x, (int) position.y, (int) position.getZ(), radius, color);
+ writeVertex(vertex, (int) position.x, (int) position.getY(), (int) position.getZ(), radius, color);
} else if (vertex.getShape() == Shape.FILLER_RECT) {
int width = Math.max(1, Math.round(sizeX / graphicLayoutInfo.getWidth()));
int height = Math.max(1, Math.round(sizeY / graphicLayoutInfo.getHeight()));
- writeVertex(vertex, (int) position.x, (int) position.y, (int) position.getZ(), width, height, color);
+ writeVertex(vertex, (int) position.x, (int) position.getY(), (int) position.getZ(), width, height, color);
} else {
int radius = calculateVertexRadius(vertex.getDegree());
- writeVertex(vertex, (int) position.x, (int) position.y, (int) position.getZ(), radius, color);
+ writeVertex(vertex, (int) position.x, (int) position.getY(), (int) position.getZ(), radius, color);
}
}
View
2 src/org/sosy_lab/ccvisu/writers/WriterDataLayoutDISP.java
@@ -262,7 +262,7 @@ public void writeDISP(Dimension size, Graphics graphics, int xCanvasSize,
group.getY(), 0));
int x = (int) (position.x + insetleft);
- int y = (int) (position.y - insetbottom);
+ int y = (int) (position.getY() - insetbottom);
int left = x - 5;
int right = x + 5;
View
2 src/org/sosy_lab/ccvisu/writers/WriterDataLayoutLAY.java
@@ -85,7 +85,7 @@ public void writeVertex(GraphVertex vertex, int xPos, int yPos, int zPos,
int width, int height, Color color) {
out.println("LAY\t" + vertex.getPosition().x + "\t"
- + vertex.getPosition().y + "\t"
+ + vertex.getPosition().getY() + "\t"
+ vertex.getPosition().getZ() + "\t"
+ vertex.getDegree() + "\t"
+ mkConnected(vertex.getName()) + "\t"
View
10 src/org/sosy_lab/ccvisu/writers/WriterDataLayoutVRML.java
@@ -264,8 +264,8 @@ public void writeGraphicsLayout(List<GraphVertex> vertices,
Position position = vertex.getPosition();
xPosMin = Math.min(xPosMin, position.x);
xPosMax = Math.max(xPosMax, position.x);
- yPosMin = Math.min(yPosMin, position.y);
- yPosMax = Math.max(yPosMax, position.y);
+ yPosMin = Math.min(yPosMin, position.getY());
+ yPosMax = Math.max(yPosMax, position.getY());
zPosMin = Math.min(zPosMin, position.getZ());
zPosMax = Math.max(zPosMax, position.getZ());
}
@@ -301,10 +301,10 @@ public void writeGraphicsLayout(List<GraphVertex> vertices,
Position targetPos = edge.getTarget().getPosition();
writeEdge(edge,
(int) ((sourcePos.x + xOffset) * scale),
- (int) ((sourcePos.y + yOffset) * -scale + size),
+ (int) ((sourcePos.getY() + yOffset) * -scale + size),
(int) ((sourcePos.getZ() + zOffset) * scale),
(int) ((targetPos.x + xOffset) * scale),
- (int) ((targetPos.y + yOffset) * -scale + size),
+ (int) ((targetPos.getY() + yOffset) * -scale + size),
(int) ((targetPos.getZ() + zOffset) * scale));
}
}
@@ -337,7 +337,7 @@ private void writeVertexPrepare(GraphVertex vertex, int size, float scale,
Position vertexPosition = vertex.getPosition();
int xPos = (int) ((vertexPosition.x + xOffset) * scale);
- int yPos = (int) ((vertexPosition.y + yOffset) * -scale + size);
+ int yPos = (int) ((vertexPosition.getY() + yOffset) * -scale + size);
int zPos = (int) ((vertexPosition.getZ() + zOffset) * scale);
// Determine color for vertex.
View
2 test/unit-test/org/sosy_lab/ccvisu/clustering/test/ClustererMinDistPercTest.java
@@ -262,7 +262,7 @@ public void createClustersOfLayout_UsingHeuristic() {
private GraphVertex createTestVertex (String uniqueName, int posX, int posY, int posZ) {
GraphVertex vertex = new GraphVertex(uniqueName);
vertex.getPosition().x = posX;
- vertex.getPosition().y = posY;
+ vertex.getPosition().setY(posY);
vertex.getPosition().setZ(posZ);
return vertex;
View
2 test/unit-test/org/sosy_lab/ccvisu/graph/test/GroupTest.java
@@ -105,7 +105,7 @@ public void f() {
private GraphVertex createTestVertex (String uniqueName, int posX, int posY, int posZ) {
GraphVertex vertex = new GraphVertex(uniqueName, vertexIdSeqNo++);
vertex.getPosition().x = posX;
- vertex.getPosition().y = posY;
+ vertex.getPosition().setY(posY);
vertex.getPosition().setZ(posZ);
return vertex;

0 comments on commit e505c11

Please sign in to comment.
Something went wrong with that request. Please try again.