org.joml.Circlef Maven / Gradle / Ivy
/*
* The MIT License
*
* Copyright (c) 2017-2019 JOML
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.joml;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.joml.internal.Options;
import org.joml.internal.Runtime;
/**
* Represents a 2D circle using single-precision floating-point numbers.
*
* @author Kai Burjack
*/
public class Circlef {
public float x, y, r;
/**
* Create a new {@link Circlef} with center position (0, 0, 0)
and radius 0
.
*/
public Circlef() {
}
/**
* Create a new {@link Circlef} as a copy of the given source
.
*
* @param source
* the {@link Circlef} to copy from
*/
public Circlef(Circlef source) {
this.x = source.x;
this.y = source.y;
this.r = source.r;
}
/**
* Create a new {@link Circlef} with center position (x, y)
and radius r
.
*
* @param x
* the x coordinate of the circle's center
* @param y
* the y coordinate of the circle's center
* @param r
* the radius of the circle
*/
public Circlef(float x, float y, float r) {
this.x = x;
this.y = y;
this.r = r;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Float.floatToIntBits(r);
result = prime * result + Float.floatToIntBits(x);
result = prime * result + Float.floatToIntBits(y);
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Circlef other = (Circlef) obj;
if (Float.floatToIntBits(r) != Float.floatToIntBits(other.r))
return false;
if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
return false;
if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
return false;
return true;
}
/**
* Return a string representation of this circle.
*
* This method creates a new {@link DecimalFormat} on every invocation with the format string "0.000E0;-
".
*
* @return the string representation
*/
public String toString() {
return Runtime.formatNumbers(toString(Options.NUMBER_FORMAT));
}
/**
* Return a string representation of this circle by formatting the vector components with the given {@link NumberFormat}.
*
* @param formatter
* the {@link NumberFormat} used to format the components with
* @return the string representation
*/
public String toString(NumberFormat formatter) {
return "(" + formatter.format(x) + " " + formatter.format(y) + " " + formatter.format(r) + ")";
}
}