Skip to content

Commit

Permalink
refactor palette
Browse files Browse the repository at this point in the history
Signed-off-by: suyashmahar <[email protected]>
  • Loading branch information
suyashmahar committed May 2, 2017
1 parent d1076a8 commit ad711bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum Palette {
Spectral(0x9e0142, 0xd53e4f, 0xf46d43, 0xfdae61, 0xfee08b, 0xffffbf, 0xe6f598, 0xabdda4, 0x66c2a5),
RdYlGn(0xa50026, 0xd73027, 0xf46d43, 0xfdae61, 0xfee08b, 0xffffbf, 0xd9ef8b, 0xa6d96a, 0x66bd63);


private final int c0;
private final int c1;
private final int c2;
private final int c3;
Expand All @@ -43,9 +43,9 @@ public enum Palette {
private final int c6;
private final int c7;
private final int c8;
private final int c9;

Palette(int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8, int c9) {
Palette(int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8) {
this.c0 = c0;
this.c1 = c1;
this.c2 = c2;
this.c3 = c3;
Expand All @@ -54,47 +54,12 @@ public enum Palette {
this.c6 = c6;
this.c7 = c7;
this.c8 = c8;
this.c9 = c9;
}

public int getC1() {
return c1;
}

public int getC2() {
return c2;
}

public int getC3() {
return c3;
}

public int getC4() {
return c4;
}

public int getC5() {
return c5;
}

public int getC6() {
return c6;
}

public int getC7() {
return c7;
}

public int getC8() {
return c8;
}

public int getC9() {
return c9;
}

public int getColor(int index){
switch (index){
case 0:
return c0;
case 1:
return c1;
case 2:
Expand All @@ -111,8 +76,6 @@ public int getColor(int index){
return c7;
case 8:
return c8;
case 9:
return c9;
default:
Log.i("Palette", "Invalid index");
break;
Expand All @@ -126,6 +89,4 @@ public static void main(String[] args) {
System.exit(-1);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ public Triangulation getColororedTriangulation(){
* depicted in the following figure:
*
*(c1 are corresponding int values representing color in ColorPalette.java)
* c1 c2 c3
* c0 c1 c2
* +-------------+--------------+
* | | |
* | r1 | r2 |
* | | |
* c8 +------------c9--------------+ c4
* c7 +------------c8--------------+ c3
* | | |
* | r3 | r4 |
* | | |
* +-------------+--------------+
* c7 c6 c5
* c6 c5 c4
*
*
* <b>Algorithm</b>
Expand Down Expand Up @@ -134,25 +134,25 @@ private int getColorForPoint(Vector2D point){

// Following if..else identifies which sub-rectangle given point lies
if (point.x < gridWidth/2 && point.y < gridHeight/2) {
topLeftColor = new ExtendedColor(colorPalette.getC1());
topRightColor = new ExtendedColor(colorPalette.getC2());
bottomLeftColor = new ExtendedColor(colorPalette.getC8());
bottomRightColor = new ExtendedColor(colorPalette.getC9());
topLeftColor = new ExtendedColor(colorPalette.getColor(0));
topRightColor = new ExtendedColor(colorPalette.getColor(1));
bottomLeftColor = new ExtendedColor(colorPalette.getColor(7));
bottomRightColor = new ExtendedColor(colorPalette.getColor(8));
} else if (point.x >= gridWidth/2 && point.y < gridHeight/2) {
topLeftColor = new ExtendedColor(colorPalette.getC2());
topRightColor = new ExtendedColor(colorPalette.getC3());
bottomLeftColor = new ExtendedColor(colorPalette.getC9());
bottomRightColor = new ExtendedColor(colorPalette.getC4());
topLeftColor = new ExtendedColor(colorPalette.getColor(1));
topRightColor = new ExtendedColor(colorPalette.getColor(2));
bottomLeftColor = new ExtendedColor(colorPalette.getColor(8));
bottomRightColor = new ExtendedColor(colorPalette.getColor(3));
} else if (point.x >= gridWidth/2 && point.y >= gridHeight/2) {
topLeftColor = new ExtendedColor(colorPalette.getC9());
topRightColor = new ExtendedColor(colorPalette.getC4());
bottomLeftColor = new ExtendedColor(colorPalette.getC6());
bottomRightColor = new ExtendedColor(colorPalette.getC5());
topLeftColor = new ExtendedColor(colorPalette.getColor(8));
topRightColor = new ExtendedColor(colorPalette.getColor(3));
bottomLeftColor = new ExtendedColor(colorPalette.getColor(5));
bottomRightColor = new ExtendedColor(colorPalette.getColor(4));
} else {
topLeftColor = new ExtendedColor(colorPalette.getC8());
topRightColor = new ExtendedColor(colorPalette.getC9());
bottomLeftColor = new ExtendedColor(colorPalette.getC7());
bottomRightColor = new ExtendedColor(colorPalette.getC6());
topLeftColor = new ExtendedColor(colorPalette.getColor(7));
topRightColor = new ExtendedColor(colorPalette.getColor(8));
bottomLeftColor = new ExtendedColor(colorPalette.getColor(6));
bottomRightColor = new ExtendedColor(colorPalette.getColor(5));
}

// Calculate corners of sub rectangle in which point is identified
Expand All @@ -170,7 +170,6 @@ private int getColorForPoint(Vector2D point){
(point.y >= gridHeight/2) ? gridHeight : gridHeight/2);

// Calculates weighted mean of colors

ExtendedColor weightedTopColor = new ExtendedColor(
(int)((topRightColor.r*(point.x - topLeft.x) + (topLeftColor.r)*(topRight.x - point.x))
/ ((topRight.x - topLeft.x))),
Expand Down

0 comments on commit ad711bf

Please sign in to comment.