mmb.engine.visuals.VisLine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.engine.visuals;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import com.github.davidmoten.rtree2.geometry.Geometries;
import com.github.davidmoten.rtree2.geometry.Line;
import mmb.Nil;
import mmb.menu.world.window.WorldFrame;
/**
* @author oskar
*
*/
public final class VisLine implements Visual {
public final double x1;
public final double y1;
public final double x2;
public final double y2;
public final Line line;
public final Color c;
@Override
public Line border() {
return line;
}
@Override
public void render(Graphics g, WorldFrame frame) {
Point a = frame.worldPositionOnScreen(x1, y1);
Point b = frame.worldPositionOnScreen(x2, y2);
g.setColor(c);
g.drawLine(a.x, a.y, b.x, b.y);
}
/**
* @param x1 first X coordinate
* @param y1 first Y coordinate
* @param x2 second X coordinate
* @param y2 second Y coordinate
* @param c color
*/
public VisLine(double x1, double y1, double x2, double y2, Color c) {
super();
line = Geometries.line(x1, y1, x2, y2);
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.c = c;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((c == null) ? 0 : c.hashCode());
long temp;
temp = Double.doubleToLongBits(x1);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(x2);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y1);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y2);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(@Nil Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VisLine other = (VisLine) obj;
if (c == null) {
if (other.c != null)
return false;
} else if (!c.equals(other.c))
return false;
if (Double.doubleToLongBits(x1) != Double.doubleToLongBits(other.x1))
return false;
if (Double.doubleToLongBits(x2) != Double.doubleToLongBits(other.x2))
return false;
if (Double.doubleToLongBits(y1) != Double.doubleToLongBits(other.y1))
return false;
if (Double.doubleToLongBits(y2) != Double.doubleToLongBits(other.y2))
return false;
return true;
}
@Override
public String toString() {
return "VisLine [x1=" + x1 + ", y1=" + y1 + ", x2=" + x2 + ", y2=" + y2 + ", c=" + c + "]";
}
}