style: autoformat

This commit is contained in:
Laureηt 2022-04-19 21:59:20 +02:00
parent df59522366
commit ac2837a7af
No known key found for this signature in database
GPG key ID: D88C6B294FD40994

View file

@ -5,6 +5,7 @@ import algebra.*;
/** /**
* The Fragment class represents an attributed 'pixel' as generated * The Fragment class represents an attributed 'pixel' as generated
* by a Rasterizer. * by a Rasterizer.
*
* @author cdehais * @author cdehais
*/ */
@ -13,7 +14,8 @@ public class Fragment {
private int y; private int y;
private int numAttributes; private int numAttributes;
/* attributes placement: /*
* attributes placement:
* 0: depth * 0: depth
* 1-3: color * 1-3: color
* 4-6: normal * 4-6: normal
@ -21,58 +23,60 @@ public class Fragment {
*/ */
double[] attributes; double[] attributes;
public Fragment (int x, int y) { // int numAdditionalAttributes) { public Fragment(int x, int y) { // int numAdditionalAttributes) {
this.x = x; this.x = x;
this.y = y; this.y = y;
numAttributes = 9; numAttributes = 9;
attributes = new double[numAttributes]; attributes = new double[numAttributes];
} }
public int getNumAttributes () { public int getNumAttributes() {
return numAttributes; return numAttributes;
} }
/** /**
* Gets a scalar attribute at index. * Gets a scalar attribute at index.
*/ */
public double getAttribute (int index) { public double getAttribute(int index) {
return attributes[index]; return attributes[index];
} }
/** /**
* Gets a vector attribute at the given starting location and with the given dimension. * Gets a vector attribute at the given starting location and with the given
* dimension.
*/ */
public double[] getAttribute (int index, int dimension) { public double[] getAttribute(int index, int dimension) {
double[] attr = new double[dimension]; double[] attr = new double[dimension];
for (int i = 0; i < dimension; i++) { for (int i = 0; i < dimension; i++) {
attr[i] = attributes[index+i]; attr[i] = attributes[index + i];
} }
return attr; return attr;
} }
public void setAttribute (int index, double value) { public void setAttribute(int index, double value) {
attributes[index] = value; attributes[index] = value;
} }
/** /**
* Gets the x pixel coordinate of the Fragment * Gets the x pixel coordinate of the Fragment
*/ */
public int getX () { public int getX() {
return x; return x;
} }
/** /**
* Gets the y pixel coordinate of the Fragment * Gets the y pixel coordinate of the Fragment
*/ */
public int getY () { public int getY() {
return y; return y;
} }
/** /**
* Gets the pixel coordinates (x, y) of the Fragment as a size 2 array * Gets the pixel coordinates (x, y) of the Fragment as a size 2 array
*/ */
public int[] getPosition () { public int[] getPosition() {
int[] position = new int[2]; int[] position = new int[2];
position[0] = x; position[0] = x;
@ -81,56 +85,55 @@ public class Fragment {
return position; return position;
} }
public void setPosition (int x, int y) { public void setPosition(int x, int y) {
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
public double getDepth () { public double getDepth() {
return attributes[0]; return attributes[0];
} }
public void setDepth (double z) { public void setDepth(double z) {
attributes[0] = z; attributes[0] = z;
} }
public Vector3 getNormal () { public Vector3 getNormal() {
return new Vector3 (attributes[0], attributes[1], attributes[2]); return new Vector3(attributes[4], attributes[5], attributes[6]);
} }
public void setNormal (Vector normal) { public void setNormal(Vector normal) {
attributes[4] = normal.get (0); attributes[4] = normal.get(0);
attributes[5] = normal.get (1); attributes[5] = normal.get(1);
attributes[6] = normal.get (2); attributes[6] = normal.get(2);
} }
public void setNormal (double nx, double ny, double nz) { public void setNormal(double nx, double ny, double nz) {
attributes[4] = nx; attributes[4] = nx;
attributes[5] = ny; attributes[5] = ny;
attributes[6] = nz; attributes[6] = nz;
} }
public Color getColor () { public Color getColor() {
int r = (int) Math.min (255, Math.max (255 * attributes[1], 0)); int r = (int) Math.min(255, Math.max(255 * attributes[1], 0));
int g = (int) Math.min (255, Math.max (255 * attributes[2], 0)); int g = (int) Math.min(255, Math.max(255 * attributes[2], 0));
int b = (int) Math.min (255, Math.max (255 * attributes[3], 0)); int b = (int) Math.min(255, Math.max(255 * attributes[3], 0));
return new Color (r, g, b); return new Color(r, g, b);
} }
public void setColor (Color color) { public void setColor(Color color) {
attributes[1] = color.getRed (); attributes[1] = color.getRed();
attributes[2] = color.getGreen (); attributes[2] = color.getGreen();
attributes[3] = color.getBlue (); attributes[3] = color.getBlue();
} }
public void setColor (double r, double g, double b) { public void setColor(double r, double g, double b) {
attributes[1] = r; attributes[1] = r;
attributes[2] = g; attributes[2] = g;
attributes[3] = b; attributes[3] = b;
} }
public String toString() {
public String toString () {
return "(" + x + "," + y + ")"; return "(" + x + "," + y + ")";
} }
} }