All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tvd12.gamebox.math.Vec2 Maven / Gradle / Ivy

There is a newer version: 1.2.4
Show newest version
package com.tvd12.gamebox.math;

import com.tvd12.ezyfox.util.EzyEquals;
import com.tvd12.ezyfox.util.EzyHashCodes;

public class Vec2 {

	public float x;
	public float y;
	
	public static final Vec2 ZERO = new Vec2();
	
	public Vec2() {
		this(0.0F, 0.0F);
	}
	
	public Vec2(Vec2 v) {
		this.x = v.x;
		this.y = v.y;
	}
	
	public Vec2(double x, double y) {
		this.x = (float)x;
		this.y = (float)y;
	}
	
	public Vec2(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public void set(double x, double y) {
		this.x = (float)x;
		this.y = (float)y;
	}
	
	public void set(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public void multiple(float a) {
		this.x *= a;
		this.y *= a;
	}
	
	public Vec2 multipleNew(float a) {
		return new Vec2(this.x * a, this.y * a);
	}
	
	@Override
	public boolean equals(Object obj) {
		return new EzyEquals()
				.function(t -> t.x)
				.function(t -> t.y)
				.isEquals(this, obj);
	}
	
	@Override
	public int hashCode() {
		return new EzyHashCodes()
				.append(x, y)
				.toHashCode();
	}
	
	@Override
	public String toString() {
		return new StringBuilder()
				.append("(")
					.append(x).append(", ")
					.append(y)
				.append(")")
				.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy