Skip to content

Commit

Permalink
Modified rhombus and chevron shapes to maintain a 60 degree angle reg…
Browse files Browse the repository at this point in the history
…ardless of size.
  • Loading branch information
jmcgillivray authored and rpavlik committed Jan 10, 2024
1 parent 28469c7 commit aacbf31
Showing 1 changed file with 48 additions and 33 deletions.
81 changes: 48 additions & 33 deletions VUE2/src/main/java/tufts/vue/shape/RectangularPoly2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.awt.geom.Rectangle2D;
import java.awt.geom.PathIterator;
import java.awt.geom.AffineTransform;
import java.lang.Math;

/**
* This class implements a polygon shape fit into a specified rectanular region.
Expand Down Expand Up @@ -140,38 +141,40 @@ public static class Diamond extends RectangularPoly2D {
public Diamond() { setSides(4); }
protected void computeVertices()
{
xpoints[0] = x + width/2;
xpoints[0] = x + width/2.0;
ypoints[0] = y;

xpoints[1] = x + width;
ypoints[1] = y + height/2;
ypoints[1] = y + height/2.0;

xpoints[2] = x + width/2;
xpoints[2] = x + width/2.0;
ypoints[2] = y + height;

xpoints[3] = x;
ypoints[3] = y + height/2;
ypoints[3] = y + height/2.0;
}
}

/** a 4 sided polygon */
public static class Rhombus extends RectangularPoly2D {
private double offset;

public Rhombus() { setSides(4); }
protected void computeVertices()
{

offset = Math.tan(60.0) * height;

xpoints[0] = x + ((double)width-(double)width*0.8);
xpoints[0] = x + offset;
ypoints[0] = y;

xpoints[1] = x + width;
ypoints[1] = y;


xpoints[2] = x + width - offset;
ypoints[2] = y + height;

xpoints[3] = x;
ypoints[3] = y + height;

xpoints[2] = x + ((double)width-(double)width*0.2);
ypoints[2] = y + height;
}
}

Expand Down Expand Up @@ -267,27 +270,39 @@ protected void computeVertices()
ypoints[7] = y + yInset;
}
}
/** a point sideways Chevron */
public static class Chevron extends RectangularPoly2D {
public Chevron() { setSides(6); }
public int getContentGravity() { return CENTER; }
protected void computeVertices()
{

xpoints[0] = x + ((double)width-(double)width*0.2);
ypoints[0] = y;
xpoints[1] = x + width;
ypoints[1] = y + (height/2);
xpoints[2] = x + ((double)width-(double)width*0.2);
ypoints[2] = y + height;
xpoints[3] = x;
ypoints[3] = y + height;
xpoints[4] = x + (double)width*0.2;
ypoints[4] = y + (height/2);
xpoints[5] = x;
ypoints[5] = y;
}
}

/** a point sideways Chevron */
public static class Chevron extends RectangularPoly2D {
private double offset;

public Chevron() { setSides(6); }

public int getContentGravity() { return CENTER; }

protected void computeVertices() {
offset = Math.tan(60.0) * height / 2.0;

xpoints[0] = x;
ypoints[0] = y;

xpoints[1] = x + width - offset;
ypoints[1] = y;

xpoints[2] = x + width;
ypoints[2] = y + (height / 2.0);

xpoints[3] = x + width - offset;
ypoints[3] = y + height;

xpoints[4] = x;
ypoints[4] = y + height;

xpoints[5] = x + offset;
ypoints[5] = y + (height / 2.0);

}
}

public void setSides(int sides)
{
if (sides < 3 || sides > 8)
Expand Down Expand Up @@ -547,7 +562,7 @@ public Object clone()

public String toString()
{
return getClass().getName() + "@" + Integer.toHexString(hashCode()) + "[sides=" + sides + " " + x + "," + y + " " + width + ", " + height + "]";
return getClass().getName() + "@" + Integer.toHexString(hashCode()) + "[sides=" + sides + " " + x + "," + y + " " + width + "x" + height + "]";
}

class PolyIterator implements PathIterator
Expand Down

0 comments on commit aacbf31

Please sign in to comment.