[DEV] commit all with new insland

This commit is contained in:
Edouard DUPIN 2022-03-23 13:37:48 +01:00
parent a72c21ce54
commit e0509ee9bf
8 changed files with 430 additions and 471 deletions

View File

@ -1,404 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.etk;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
/**
* in the dimension class we store the data as the more usefull unit (pixel)
* but one case need to be dynamic the %, then when requested in % the register the % value
*/
@SuppressWarnings("preview")
public record Dimension(
Vector2f size,
Distance type) {
public static final Dimension ZERO = new Dimension(Vector2f.ZERO, Distance.PIXEL);
private static Vector2f ratio = new Vector2f(9999999, 888888);
private static Vector2f invRatio = new Vector2f(1, 1);
private static Dimension windowsSize = new Dimension(Vector2f.MAX_VALUE, Distance.PIXEL);
public static final float INCH_TO_MILLIMETER = 1.0f / 25.4f;
public static final float FOOT_TO_MILLIMETER = 1.0f / 304.8f;
public static final float METER_TO_MILLIMETER = 1.0f / 1000.0f;
public static final float CENTIMETER_TO_MILLIMETER = 1.0f / 10.0f;
public static final float KILOMETER_TO_MILLIMETER = 1.0f / 1000000.0f;
public static final float MILLIMETER_TO_INCH = 25.4f;
public static final float MILLIMETER_TO_FOOT = 304.8f;
public static final float MILLIMETER_TO_METER = 1000.0f;
public static final float MILLIMETER_TO_CENTIMETER = 10.0f;
public static final float MILLIMETER_TO_KILOMETER = 1000000.0f;
/**
* basic init
*/
static {
final Dimension conversion = new Dimension(new Vector2f(72, 72), Distance.INCH);
ratio = conversion.getMillimeter();
invRatio = new Vector2f(1.0f / ratio.x(), 1.0f / ratio.y());
windowsSize = new Dimension(new Vector2f(200, 200), Distance.PIXEL);
}
/**
* get the Windows diagonal size in the request unit
* @param type Unit type requested.
* @return the requested size
*/
public static float getWindowsDiag(final Distance type) {
final Vector2f size = getWindowsSize(type);
return size.length();
}
/**
* get the Windows size in the request unit
* @param type Unit type requested.
* @return the requested size
*/
public static Vector2f getWindowsSize(final Distance type) {
return windowsSize.get(type);
}
/**
* set the Milimeter ratio for calculation
* @param ratio Milimeter ration for the screen calculation interpolation
* @param type Unit type requested.
* @note: same as @ref setPixelPerInch (internal manage convertion)
*/
public static void setPixelRatio(final Vector2f ratio, final Distance type) {
Log.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
final Dimension conversion = new Dimension(ratio, type);
Log.info(" == > " + conversion);
Dimension.ratio = conversion.getMillimeter();
invRatio = new Vector2f(1.0f / Dimension.ratio.x(), 1.0f / Dimension.ratio.y());
Log.info("Set a new screen ratio for the screen : ratioMm=" + Dimension.ratio);
}
/**
* set the current Windows size
* @param size size of the current windows in pixel.
*/
public static void setPixelWindowsSize(final Vector2f size) {
windowsSize = new Dimension(size);
Log.verbose("Set a new Windows property size " + windowsSize + "px");
}
/**
* Constructor (default :0,0 mode pixel)
*/
public Dimension() {
this(Vector2f.ZERO, Distance.PIXEL);
}
/**
* Constructor
* @param size Requested dimension
*/
public Dimension(final Vector2f size) {
this(size, Distance.PIXEL);
}
public Dimension(final Vector2f size, final Distance type) {
this.size = size;
this.type = type;
}
/**
* get the current dimension in requested type
* @param type Type of unit requested.
* @return dimension requested.
*/
public Vector2f get(final Distance type) {
return switch (type) {
case POURCENT -> getPourcent();
case PIXEL -> getPixel();
case METER -> getMeter();
case CENTIMETER -> getCentimeter();
case MILLIMETER -> getMillimeter();
case KILOMETER -> getKilometer();
case INCH -> getInch();
case FOOT -> getFoot();
case ELEMENT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case EX -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case PC -> {
Log.error("Does not support other than Px and % type of dimention : " + type + " automaticly convert with {72,72} pixel/inch");
yield null;
}
case POINT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
default -> throw new IllegalArgumentException("Unexpected value: " + type);
};
}
/**
* get the current dimension in Centimeter
* @return dimension in Centimeter
*/
public Vector2f getCentimeter() {
return getMillimeter().multiply(MILLIMETER_TO_CENTIMETER);
}
/**
* get the current dimension in Foot
* @return dimension in Foot
*/
public Vector2f getFoot() {
return getMillimeter().multiply(MILLIMETER_TO_FOOT);
}
/**
* get the current dimension in Inch
* @return dimension in Inch
*/
public Vector2f getInch() {
return getMillimeter().multiply(MILLIMETER_TO_INCH);
}
/**
* get the current dimension in Kilometer
* @return dimension in Kilometer
*/
public Vector2f getKilometer() {
return getMillimeter().multiply(MILLIMETER_TO_KILOMETER);
}
/**
* get the current dimension in Meter
* @return dimension in Meter
*/
public Vector2f getMeter() {
return getMillimeter().multiply(MILLIMETER_TO_METER);
}
/**
* get the current dimension in Millimeter
* @return dimension in Millimeter
*/
public Vector2f getMillimeter() {
return new Vector2f(getPixel().x() * invRatio.x(), getPixel().y() * invRatio.y());
}
/**
* get the current dimension in pixel
* @return dimension in Pixel
*/
public Vector2f getPixel() {
if (this.type != Distance.POURCENT) {
return this.size;
}
return getPixel(windowsSize.getPixel());
}
public Vector2f getPixel(final Vector2f uppersize) {
if (this.type != Distance.POURCENT) {
return this.size;
}
final Vector2f res = new Vector2f(uppersize.x() * this.size.x() * 0.01f, uppersize.y() * this.size.y() * 0.01f);
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
return res;
}
public Vector2i getPixeli() {
Vector2f tmpSize = windowsSize.getPixel();
return getPixeli(new Vector2i((int) tmpSize.x(), (int) tmpSize.y()));
}
public Vector2i getPixeli(final Vector2i uppersize) {
if (this.type != Distance.POURCENT) {
return new Vector2i((int) this.size.x(), (int) this.size.y());
}
final Vector2i res = new Vector2i((int) (uppersize.x() * this.size.x() * 0.01f), (int) (uppersize.y() * this.size.y() * 0.01f));
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
return res;
}
/**
* get the current dimension in Pourcent
* @return dimension in Pourcent
*/
public Vector2f getPourcent() {
if (this.type != Distance.POURCENT) {
final Vector2f windDim = windowsSize.getPixel();
//GALE_DEBUG(" windows dimension : " /*+ windowsSize*/ + " == > " + windDim + "px"); // ==> infinite loop ...
//printf(" windows dimension : %f,%f", windDim.x(),windDim.y());
//printf(" data : %f,%f", m_data.x(),m_data.y());
return new Vector2f((this.size.x() / windDim.x()) * 100.0f, (this.size.y() / windDim.y()) * 100.0f);
}
return new Vector2f(this.size.x() * 100.0f, this.size.y() * 100.0f);
};
/**
* get the dimension type
* @return the type
*/
public Distance getType() {
return this.type;
}
/**
* set the current dimension in requested type
* @param config dimension configuration.
*/
public static Dimension valueOf(String config) {
Distance type = Distance.PIXEL;
if (config.endsWith("%")) {
type = Distance.POURCENT;
config = config.substring(0, config.length() - 1);
} else if (config.endsWith("px")) {
type = Distance.PIXEL;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("ft")) {
type = Distance.FOOT;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("in")) {
type = Distance.INCH;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("km")) {
type = Distance.KILOMETER;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("mm")) {
type = Distance.MILLIMETER;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("cm")) {
type = Distance.CENTIMETER;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("m")) {
type = Distance.METER;
config = config.substring(0, config.length() - 1);
} else if (config.endsWith("em")) {
type = Distance.ELEMENT;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("ex")) {
type = Distance.EX;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("pt")) {
type = Distance.POINT;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("pc")) {
type = Distance.PC;
config = config.substring(0, config.length() - 2);
} else {
Log.critical("Can not parse dimension : '" + config + "'");
return null;
}
final Vector2f tmp = Vector2f.valueOf(config);
final Dimension ret = new Dimension(tmp, type);
Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
return ret;
}
/**
* string cast :
*/
@Override
public String toString() {
String str = get(getType()).toString();
switch (getType()) {
case POURCENT -> str += "%";
case PIXEL -> str += "px";
case METER -> str += "m";
case CENTIMETER -> str += "cm";
case MILLIMETER -> str += "mm";
case KILOMETER -> str += "km";
case INCH -> str += "in";
case FOOT -> str += "ft";
case ELEMENT -> str += "em";
case EX -> str += "ex";
case POINT -> str += "pt";
case PC -> str += "pc";
default -> str += "";
}
return str;
}
public static Dimension valueOf(String contentX, String contentY) {
Distance typeX = Distance.UNKNOW;
if (contentX.endsWith("%")) {
typeX = Distance.POURCENT;
contentX = contentX.substring(0, contentX.length() - 1);
} else if (contentX.endsWith("px")) {
typeX = Distance.PIXEL;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("ft")) {
typeX = Distance.FOOT;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("in")) {
typeX = Distance.INCH;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("km")) {
typeX = Distance.KILOMETER;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("mm")) {
typeX = Distance.MILLIMETER;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("cm")) {
typeX = Distance.CENTIMETER;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("m")) {
typeX = Distance.METER;
contentX = contentX.substring(0, contentX.length() - 1);
} else if (contentX.endsWith("em")) {
typeX = Distance.ELEMENT;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("ex")) {
typeX = Distance.EX;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("pt")) {
typeX = Distance.POINT;
contentX = contentX.substring(0, contentX.length() - 2);
} else if (contentX.endsWith("pc")) {
typeX = Distance.PC;
contentX = contentX.substring(0, contentX.length() - 2);
}
float tmpX = Float.valueOf(contentX);
Distance typeY = Distance.UNKNOW;
if (contentY.endsWith("%")) {
typeY = Distance.POURCENT;
contentY = contentY.substring(0, contentY.length() - 1);
} else if (contentY.endsWith("px")) {
typeY = Distance.PIXEL;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("ft")) {
typeY = Distance.FOOT;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("in")) {
typeY = Distance.INCH;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("km")) {
typeY = Distance.KILOMETER;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("mm")) {
typeY = Distance.MILLIMETER;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("cm")) {
typeY = Distance.CENTIMETER;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("m")) {
typeY = Distance.METER;
contentY = contentY.substring(0, contentY.length() - 1);
} else if (contentY.endsWith("em")) {
typeY = Distance.ELEMENT;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("ex")) {
typeY = Distance.EX;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("pt")) {
typeY = Distance.POINT;
contentY = contentY.substring(0, contentY.length() - 2);
} else if (contentY.endsWith("pc")) {
typeY = Distance.PC;
contentY = contentY.substring(0, contentY.length() - 2);
}
float tmpY = Float.valueOf(contentY);
if (typeX == Distance.UNKNOW && typeY == Distance.UNKNOW) {
return new Dimension(new Vector2f(tmpX, tmpY), Distance.PIXEL);
} else if (typeX == Distance.UNKNOW) {
return new Dimension(new Vector2f(tmpX, tmpY), typeY);
}
return new Dimension(new Vector2f(tmpX, tmpY), typeX);
}
}

View File

@ -11,12 +11,12 @@ import org.atriasoft.etk.internal.Log;
* in the dimension class we store the data as the more usefull unit (pixel)
* but one case need to be dynamic the %, then when requested in % the register the % value
*/
@SuppressWarnings("preview")
public record Dimension1D(
public record Dimension1f(
float size,
Distance type) {
private static final float BASIC_RATIO = 72.0f / 25.4f;
public static final Dimension1D ZERO = new Dimension1D(0);
public static final Dimension1f ZERO = new Dimension1f(0);
public static final float INCH_TO_MILLIMETER = 1.0f / 25.4f;
public static final float FOOT_TO_MILLIMETER = 1.0f / 304.8f;
public static final float METER_TO_MILLIMETER = 1.0f / 1000.0f;
@ -31,7 +31,7 @@ public record Dimension1D(
/**
* Constructor (default :0,0 mode pixel)
*/
public Dimension1D() {
public Dimension1f() {
this(0, Distance.PIXEL);
}
@ -39,11 +39,11 @@ public record Dimension1D(
* Constructor
* @param size Requested dimension
*/
public Dimension1D(final float size) {
public Dimension1f(final float size) {
this(size, Distance.PIXEL);
}
public Dimension1D(final float size, final Distance type) {
public Dimension1f(final float size, final Distance type) {
this.size = size;
this.type = type;
}
@ -87,47 +87,15 @@ public record Dimension1D(
* set the current dimension in requested type
* @param config dimension configuration.
*/
public static Dimension1D valueOf(String config) {
Distance type = Distance.PIXEL;
if (config.endsWith("%")) {
type = Distance.POURCENT;
config = config.substring(0, config.length() - 1);
} else if (config.endsWith("px")) {
type = Distance.PIXEL;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("ft")) {
type = Distance.FOOT;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("in")) {
type = Distance.INCH;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("km")) {
type = Distance.KILOMETER;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("mm")) {
type = Distance.MILLIMETER;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("cm")) {
type = Distance.CENTIMETER;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("m")) {
type = Distance.METER;
config = config.substring(0, config.length() - 1);
} else if (config.endsWith("em")) {
type = Distance.ELEMENT;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("ex")) {
type = Distance.EX;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("pt")) {
type = Distance.POINT;
config = config.substring(0, config.length() - 2);
} else if (config.endsWith("pc")) {
type = Distance.PC;
config = config.substring(0, config.length() - 2);
public static Dimension1f valueOf(String config) {
Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");
return null;
}
final float tmp = Float.valueOf(config);
final Dimension1D ret = new Dimension1D(tmp, type);
final Dimension1f ret = new Dimension1f(tmp, type);
Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
return ret;
}
@ -137,23 +105,7 @@ public record Dimension1D(
*/
@Override
public String toString() {
String str = Float.toString(this.size);
switch (getType()) {
case POURCENT -> str += "%";
case PIXEL -> str += "px";
case METER -> str += "m";
case CENTIMETER -> str += "cm";
case MILLIMETER -> str += "mm";
case KILOMETER -> str += "km";
case INCH -> str += "in";
case FOOT -> str += "ft";
case ELEMENT -> str += "em";
case EX -> str += "ex";
case POINT -> str += "pt";
case PC -> str += "pc";
default -> str += "";
}
return str;
return Float.toString(this.size) + getType().toSmallString();
}
}

View File

@ -0,0 +1,290 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.etk;
import org.atriasoft.etk.internal.Log;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector3f;
/**
* in the dimension class we store the data as the more usefull unit (pixel)
* but one case need to be dynamic the %, then when requested in % the register the % value
*/
public record Dimension3f(
Vector3f size,
Distance type) {
public static final Dimension3f ZERO = new Dimension3f(Vector3f.ZERO, Distance.PIXEL);
private static Vector3f ratio = new Vector3f(9999999, 888888, 7777777);
private static Vector3f invRatio = Vector3f.ONE;
private static Dimension3f windowsSize = new Dimension3f(Vector3f.MAX_VALUE, Distance.PIXEL);
public static final float INCH_TO_MILLIMETER = 1.0f / 25.4f;
public static final float FOOT_TO_MILLIMETER = 1.0f / 304.8f;
public static final float METER_TO_MILLIMETER = 1.0f / 1000.0f;
public static final float CENTIMETER_TO_MILLIMETER = 1.0f / 10.0f;
public static final float KILOMETER_TO_MILLIMETER = 1.0f / 1000000.0f;
public static final float MILLIMETER_TO_INCH = 25.4f;
public static final float MILLIMETER_TO_FOOT = 304.8f;
public static final float MILLIMETER_TO_METER = 1000.0f;
public static final float MILLIMETER_TO_CENTIMETER = 10.0f;
public static final float MILLIMETER_TO_KILOMETER = 1000000.0f;
/**
* basic init
*/
static {
final Dimension3f conversion = new Dimension3f(new Vector3f(72, 72, 72), Distance.INCH);
ratio = conversion.getMillimeter();
invRatio = new Vector3f(1.0f / ratio.x(), 1.0f / ratio.y(), 1.0f / ratio.z());
windowsSize = new Dimension3f(new Vector3f(200, 200, 200), Distance.PIXEL);
}
/**
* get the Windows diagonal size in the request unit
* @param type Unit type requested.
* @return the requested size
*/
public static float getWindowsDiag(final Distance type) {
final Vector3f size = getWindowsSize(type);
return size.length();
}
/**
* get the Windows size in the request unit
* @param type Unit type requested.
* @return the requested size
*/
public static Vector3f getWindowsSize(final Distance type) {
return windowsSize.get(type);
}
/**
* set the Milimeter ratio for calculation
* @param ratio Milimeter ration for the screen calculation interpolation
* @param type Unit type requested.
* @note: same as @ref setPixelPerInch (internal manage convertion)
*/
public static void setPixelRatio(final Vector3f ratio, final Distance type) {
Log.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
final Dimension3f conversion = new Dimension3f(ratio, type);
Log.info(" == > " + conversion);
Dimension3f.ratio = conversion.getMillimeter();
invRatio = new Vector3f(1.0f / Dimension3f.ratio.x(), 1.0f / Dimension3f.ratio.y(), 1.0f / Dimension3f.ratio.z());
Log.info("Set a new screen ratio for the screen : ratioMm=" + Dimension3f.ratio);
}
/**
* set the current Windows size
* @param size size of the current windows in pixel.
*/
public static void setPixelWindowsSize(final Vector3f size) {
windowsSize = new Dimension3f(size);
Log.verbose("Set a new Windows property size " + windowsSize + "px");
}
/**
* Constructor (default :0,0 mode pixel)
*/
public Dimension3f() {
this(Vector3f.ZERO, Distance.PIXEL);
}
/**
* Constructor
* @param size Requested dimension
*/
public Dimension3f(final Vector3f size) {
this(size, Distance.PIXEL);
}
public Dimension3f(final Vector3f size, final Distance type) {
this.size = size;
this.type = type;
}
/**
* get the current dimension in requested type
* @param type Type of unit requested.
* @return dimension requested.
*/
public Vector3f get(final Distance type) {
return switch (type) {
case POURCENT -> getPourcent();
case PIXEL -> getPixel();
case METER -> getMeter();
case CENTIMETER -> getCentimeter();
case MILLIMETER -> getMillimeter();
case KILOMETER -> getKilometer();
case INCH -> getInch();
case FOOT -> getFoot();
case ELEMENT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case EX -> throw new UnsupportedOperationException("Unimplemented case: " + type);
case PC -> {
Log.error("Does not support other than Px and % type of dimention : " + type + " automaticly convert with {72,72} pixel/inch");
yield null;
}
case POINT -> throw new UnsupportedOperationException("Unimplemented case: " + type);
default -> throw new IllegalArgumentException("Unexpected value: " + type);
};
}
/**
* get the current dimension in Centimeter
* @return dimension in Centimeter
*/
public Vector3f getCentimeter() {
return getMillimeter().multiply(MILLIMETER_TO_CENTIMETER);
}
/**
* get the current dimension in Foot
* @return dimension in Foot
*/
public Vector3f getFoot() {
return getMillimeter().multiply(MILLIMETER_TO_FOOT);
}
/**
* get the current dimension in Inch
* @return dimension in Inch
*/
public Vector3f getInch() {
return getMillimeter().multiply(MILLIMETER_TO_INCH);
}
/**
* get the current dimension in Kilometer
* @return dimension in Kilometer
*/
public Vector3f getKilometer() {
return getMillimeter().multiply(MILLIMETER_TO_KILOMETER);
}
/**
* get the current dimension in Meter
* @return dimension in Meter
*/
public Vector3f getMeter() {
return getMillimeter().multiply(MILLIMETER_TO_METER);
}
/**
* get the current dimension in Millimeter
* @return dimension in Millimeter
*/
public Vector3f getMillimeter() {
return new Vector3f(getPixel().x() * invRatio.x(), getPixel().y() * invRatio.y(), getPixel().z() * invRatio.z());
}
/**
* get the current dimension in pixel
* @return dimension in Pixel
*/
public Vector3f getPixel() {
if (this.type != Distance.POURCENT) {
return this.size;
}
return getPixel(windowsSize.getPixel());
}
public Vector3f getPixel(final Vector3f uppersize) {
if (this.type != Distance.POURCENT) {
return this.size;
}
final Vector3f res = new Vector3f(uppersize.x() * this.size.x() * 0.01f, uppersize.y() * this.size.y() * 0.01f, uppersize.z() * this.size.z() * 0.01f);
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
return res;
}
public Vector2i getPixeli() {
Vector3f tmpSize = windowsSize.getPixel();
return getPixeli(new Vector2i((int) tmpSize.x(), (int) tmpSize.y()));
}
public Vector2i getPixeli(final Vector2i uppersize) {
if (this.type != Distance.POURCENT) {
return new Vector2i((int) this.size.x(), (int) this.size.y());
}
final Vector2i res = new Vector2i((int) (uppersize.x() * this.size.x() * 0.01f), (int) (uppersize.y() * this.size.y() * 0.01f));
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
return res;
}
/**
* get the current dimension in Pourcent
* @return dimension in Pourcent
*/
public Vector3f getPourcent() {
if (this.type != Distance.POURCENT) {
final Vector3f windDim = windowsSize.getPixel();
//GALE_DEBUG(" windows dimension : " /*+ windowsSize*/ + " == > " + windDim + "px"); // ==> infinite loop ...
//printf(" windows dimension : %f,%f", windDim.x(),windDim.y());
//printf(" data : %f,%f", m_data.x(),m_data.y());
return new Vector3f((this.size.x() / windDim.x()) * 100.0f, (this.size.y() / windDim.y()) * 100.0f, (this.size.z() / windDim.z()) * 100.0f);
}
return new Vector3f(this.size.x() * 100.0f, this.size.y() * 100.0f, this.size.z() * 100.0f);
}
/**
* get the dimension type
* @return the type
*/
public Distance getType() {
return this.type;
}
/**
* set the current dimension in requested type
* @param config dimension configuration.
*/
public static Dimension3f valueOf(String config) {
Distance type = Distance.parseEndSmallString(config);
config = type.removeEndString(config);
if (type == Distance.UNKNOW) {
Log.critical("Can not parse dimension : '" + config + "'");
return null;
}
final Vector3f tmp = Vector3f.valueOf(config);
final Dimension3f ret = new Dimension3f(tmp, type);
Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
return ret;
}
/**
* string cast :
*/
@Override
public String toString() {
return get(getType()).toString() + getType().toSmallString();
}
public static Dimension3f valueOf(String contentX, String contentY, String contentZ) {
Distance typeX = Distance.parseEndSmallString(contentX);
contentX = typeX.removeEndString(contentX);
float tmpX = Float.valueOf(contentX);
Distance typeY = Distance.parseEndSmallString(contentY);
contentX = typeY.removeEndString(contentY);
float tmpY = Float.valueOf(contentY);
Distance typeZ = Distance.parseEndSmallString(contentZ);
contentX = typeZ.removeEndString(contentZ);
float tmpZ = Float.valueOf(contentZ);
if (typeX != Distance.UNKNOW) {
return new Dimension3f(new Vector3f(tmpX, tmpY, tmpZ), typeX);
}
if (typeY != Distance.UNKNOW) {
return new Dimension3f(new Vector3f(tmpX, tmpY, tmpZ), typeY);
}
if (typeZ != Distance.UNKNOW) {
return new Dimension3f(new Vector3f(tmpX, tmpY, tmpZ), typeZ);
}
return new Dimension3f(new Vector3f(tmpX, tmpY, tmpZ), Distance.PIXEL);
}
}

View File

@ -14,4 +14,102 @@ public enum Distance {
EX, //!< "ex"
POINT, //!< "pt"
PC; //!< "pc"
public static Distance parseEndSmallString(String data) {
if (data.endsWith("%")) {
return Distance.POURCENT;
} else if (data.endsWith("px")) {
return Distance.PIXEL;
} else if (data.endsWith("ft")) {
return Distance.FOOT;
} else if (data.endsWith("in")) {
return Distance.INCH;
} else if (data.endsWith("km")) {
return Distance.KILOMETER;
} else if (data.endsWith("mm")) {
return Distance.MILLIMETER;
} else if (data.endsWith("cm")) {
return Distance.CENTIMETER;
} else if (data.endsWith("m")) {
return Distance.METER;
} else if (data.endsWith("em")) {
return Distance.ELEMENT;
} else if (data.endsWith("ex")) {
return Distance.EX;
} else if (data.endsWith("pt")) {
return Distance.POINT;
} else if (data.endsWith("pc")) {
return Distance.PC;
}
return UNKNOW;
}
public static Distance parseSmallString(String data) {
if (data.equals("%")) {
return Distance.POURCENT;
} else if (data.equals("px")) {
return Distance.PIXEL;
} else if (data.equals("ft")) {
return Distance.FOOT;
} else if (data.equals("in")) {
return Distance.INCH;
} else if (data.equals("km")) {
return Distance.KILOMETER;
} else if (data.equals("mm")) {
return Distance.MILLIMETER;
} else if (data.equals("cm")) {
return Distance.CENTIMETER;
} else if (data.equals("m")) {
return Distance.METER;
} else if (data.equals("em")) {
return Distance.ELEMENT;
} else if (data.equals("ex")) {
return Distance.EX;
} else if (data.equals("pt")) {
return Distance.POINT;
} else if (data.equals("pc")) {
return Distance.PC;
}
return UNKNOW;
}
public String removeEndString(String data) {
return switch (this) {
case POURCENT -> data.substring(0, data.length() - 1);
case PIXEL -> data.substring(0, data.length() - 2);
case METER -> data.substring(0, data.length() - 1);
case CENTIMETER -> data.substring(0, data.length() - 2);
case MILLIMETER -> data.substring(0, data.length() - 2);
case KILOMETER -> data.substring(0, data.length() - 2);
case INCH -> data.substring(0, data.length() - 2);
case FOOT -> data.substring(0, data.length() - 2);
case ELEMENT -> data.substring(0, data.length() - 2);
case EX -> data.substring(0, data.length() - 2);
case POINT -> data.substring(0, data.length() - 2);
case PC -> data.substring(0, data.length() - 2);
default -> data;
};
}
/**
* string cast :
*/
public String toSmallString() {
return switch (this) {
case POURCENT -> "%";
case PIXEL -> "px";
case METER -> "m";
case CENTIMETER -> "cm";
case MILLIMETER -> "mm";
case KILOMETER -> "km";
case INCH -> "in";
case FOOT -> "ft";
case ELEMENT -> "em";
case EX -> "ex";
case POINT -> "pt";
case PC -> "pc";
default -> "";
};
}
}

View File

@ -42,18 +42,22 @@ public record Vector2f(
return new Vector2f((int) obj1.x, (int) obj1.y);
}
@CheckReturnValue
public static Vector2f max(final Vector2f obj1, final Vector2f obj2) {
return new Vector2f(Math.max(obj1.x, obj2.x), Math.max(obj1.y, obj2.y));
}
@CheckReturnValue
public static Vector2f max(final Vector2f obj1, final Vector2f obj2, final Vector2f obj3) {
return new Vector2f(FMath.max(obj1.x, obj2.x, obj3.x), FMath.max(obj1.y, obj2.y, obj3.y));
}
@CheckReturnValue
public static Vector2f min(final Vector2f obj1, final Vector2f obj2) {
return new Vector2f(Math.min(obj1.x, obj2.x), Math.min(obj1.y, obj2.y));
}
@CheckReturnValue
public static Vector2f min(final Vector2f obj1, final Vector2f obj2, final Vector2f obj3) {
return new Vector2f(FMath.min(obj1.x, obj2.x, obj3.x), FMath.min(obj1.y, obj2.y, obj3.y));
}

View File

@ -14,6 +14,7 @@ public record Vector3f(
* @param stop second vector
* @return Length value
*/
@CheckReturnValue
public static float length2(final Vector3f start, final Vector3f stop) {
final float x = stop.x - start.x;
final float y = stop.y - start.y;
@ -21,6 +22,7 @@ public record Vector3f(
return x * x + y * y + z * z;
}
@CheckReturnValue
public static Vector3f valueOf(String value) {
float val1 = 0;
float val2 = 0;
@ -570,8 +572,8 @@ public record Vector3f(
public static final Vector3f ONE_X = new Vector3f(1, 0, 0);
public static final Vector3f ONE_Y = new Vector3f(0, 1, 0);
public static final Vector3f ONE_Z = new Vector3f(0, 0, 1);
public static final Vector3f MAX = new Vector3f(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
public static final Vector3f MIN = new Vector3f(-Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE);
public static final Vector3f MAX_VALUE = new Vector3f(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
public static final Vector3f MIN_VALUE = new Vector3f(-Float.MAX_VALUE, -Float.MAX_VALUE, -Float.MAX_VALUE);
public static final Vector3f VALUE_2 = new Vector3f(2, 2, 2);
public static final Vector3f VALUE_4 = new Vector3f(4, 4, 4);
public static final Vector3f VALUE_8 = new Vector3f(8, 8, 8);
@ -599,10 +601,17 @@ public record Vector3f(
return this.x * (obj1.y * obj2.z - obj1.z * obj2.y) + this.y * (obj1.z * obj2.x - obj1.x * obj2.z) + this.z * (obj1.x * obj2.y - obj1.y * obj2.x);
}
@CheckReturnValue
public static Vector3f valueOf(final String valuesX, final String valuesY, final String valuesZ) {
float val1 = Float.valueOf(valuesX);
float val2 = Float.valueOf(valuesY);
float val3 = Float.valueOf(valuesZ);
return new Vector3f(val1, val2, val3);
}
@CheckReturnValue
public static Vector3f clipInt(final Vector3f obj1) {
return new Vector3f((int) obj1.x, (int) obj1.y, (int) obj1.z);
}
}

View File

@ -435,6 +435,16 @@ public record Vector3i(
return new Vector3i(Math.max(this.x, obj.x), Math.max(this.y, obj.y), Math.max(this.z, obj.z));
}
@CheckReturnValue
public Vector3i max(final int xxx, final int yyy, final int zzz) {
return new Vector3i(Math.max(this.x, xxx), Math.max(this.y, yyy), Math.max(this.z, zzz));
}
@CheckReturnValue
public Vector3i min(final int xxx, final int yyy, final int zzz) {
return new Vector3i(Math.min(this.x, xxx), Math.min(this.y, yyy), Math.min(this.z, zzz));
}
/**
* Set each element to the min of the current values and the values of another Vector3i
* @param obj The other Vector3i to compare with