From fcf3c073147eda99458873fd03736ccbc27ada13 Mon Sep 17 00:00:00 2001 From: Werner Randelshofer Date: Fri, 9 Aug 2024 12:51:49 +0200 Subject: [PATCH] Remove PrefsIntKey and PrefsURIListKey. Remove MathUtil.clamp methods, because java.lang.Math provides these methods now. --- .../application/prefs/PrefsIntKey.java | 48 ----------- .../application/prefs/PrefsURIListKey.java | 34 -------- .../org/jhotdraw8/base/util/MathUtil.java | 79 ------------------- .../jhotdraw8/color/FXColorInterpolator.java | 3 +- .../org/jhotdraw8/color/FXColorUtil.java | 3 +- .../color/ParametricHlsColorSpace.java | 8 +- .../org/jhotdraw8/color/RgbBitConverters.java | 14 ++-- .../org/jhotdraw8/color/util/MathUtil.java | 49 ------------ .../draw/css/converter/ColorCssConverter.java | 31 ++++++-- .../css/converter/EffectCssConverter.java | 25 +++--- .../draw/css/value/ShsbaCssColor.java | 11 +-- .../draw/css/value/SrgbaCssColor.java | 26 +++--- .../draw/gui/ZoomableScrollPane.java | 13 +-- .../jhotdraw8/draw/locator/BoundsLocator.java | 5 +- .../org/jhotdraw8/draw/tool/CreationTool.java | 7 +- .../jhotdraw8/draw/tool/LineCreationTool.java | 7 +- .../draw/tool/SimpleDragTracker.java | 9 ++- .../jhotdraw8/draw/tool/TextCreationTool.java | 9 ++- .../colorspace/ChromaticityDiagram.java | 12 ++- .../examples/colorspace/ColorRect.java | 6 +- .../mini/BezierArcLengthExampleMain.java | 5 +- .../fxcontrols/colorchooser/AlphaSlider.java | 12 ++- .../colorchooser/ColorChooserPaneModel.java | 5 +- .../colorchooser/ColorRectangleSlider.java | 19 ++--- .../fxcontrols/colorchooser/ColorSlider.java | 12 ++- .../org/jhotdraw8/geom/FXGeom.java | 9 ++- .../jhotdraw8/geom/biarc/ArcToCubicCurve.java | 3 +- .../IntersectCubicCurveCubicCurve.java | 3 +- .../intersect/IntersectCubicCurveEllipse.java | 3 +- .../geom/intersect/IntersectRayRay.java | 9 +-- .../geom/shape/SimplePathMetrics.java | 10 +-- 31 files changed, 145 insertions(+), 344 deletions(-) delete mode 100755 org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsIntKey.java delete mode 100755 org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsURIListKey.java delete mode 100644 org.jhotdraw8.base/src/main/java/org.jhotdraw8.base/org/jhotdraw8/base/util/MathUtil.java diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsIntKey.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsIntKey.java deleted file mode 100755 index 69bcdf1e5..000000000 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsIntKey.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * @(#)PrefsIntKey.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ -package org.jhotdraw8.application.prefs; - - -import java.util.prefs.Preferences; - -/** - * PrefsIntKey. - * - * @author Werner Randelshofer - */ -public class PrefsIntKey { - - private final String key; - private final int defaultValue; - private final int clampMin; - private final int clampMax; - - public PrefsIntKey(String key, int defaultValue, int clampMin, int clampMax) { - this.key = key; - this.defaultValue = defaultValue; - this.clampMin = clampMin; - this.clampMax = clampMax; - } - - public int get(Preferences prefs) { - return clamp(prefs.getInt(key, defaultValue), clampMin, clampMax); - } - - public void put(Preferences prefs, int newValue) { - prefs.putInt(key, newValue); - } - - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - private int clamp(int value, int min, int max) { - return min <= value ? (Math.min(value, max)) : min; - } -} diff --git a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsURIListKey.java b/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsURIListKey.java deleted file mode 100755 index 18b287cbb..000000000 --- a/org.jhotdraw8.application/src/main/java/org.jhotdraw8.application/org/jhotdraw8/application/prefs/PrefsURIListKey.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * @(#)PrefsURIListKey.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.application.prefs; - - -import java.util.List; -import java.util.prefs.Preferences; - -/** - * PrefsURIListKey. The words are separated by tab character. - * - * @author Werner Randelshofer - */ -public class PrefsURIListKey { - private final String key; - private final List defaultValue; - - - public PrefsURIListKey(String key, List defaultValue) { - this.key = key; - this.defaultValue = List.copyOf(defaultValue); - - } - - public List get(Preferences prefs) { - return defaultValue; - } - - public void put(Preferences prefs, int newValue) { - } -} diff --git a/org.jhotdraw8.base/src/main/java/org.jhotdraw8.base/org/jhotdraw8/base/util/MathUtil.java b/org.jhotdraw8.base/src/main/java/org.jhotdraw8.base/org/jhotdraw8/base/util/MathUtil.java deleted file mode 100644 index 9d10093d9..000000000 --- a/org.jhotdraw8.base/src/main/java/org.jhotdraw8.base/org/jhotdraw8/base/util/MathUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * @(#)MathUtil.java - * Copyright © 2023 The authors and contributors of JHotDraw. MIT License. - */ - -package org.jhotdraw8.base.util; - -public class MathUtil { - /** - * Don't let anyone instantiate this class. - */ - private MathUtil() { - } - - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - public static long clamp(long value, long min, long max) { - if (value < min) { - return min; - } - return Math.min(value, max); - } - - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - public static double clamp(double value, double min, double max) { - if (Double.isNaN(value) || value < min) { - return min; - } else if (value > max) { - return max; - } - return value; - } - - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - public static float clamp(float value, float min, float max) { - if (Float.isNaN(value) || value < min) { - return min; - } else if (value > max) { - return max; - } - return value; - } - - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - public static int clamp(int value, int min, int max) { - if (value < min) { - return min; - } - return Math.min(value, max); - } - -} diff --git a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorInterpolator.java b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorInterpolator.java index bc256a2a3..7abd9a5b3 100644 --- a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorInterpolator.java +++ b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorInterpolator.java @@ -6,7 +6,6 @@ package org.jhotdraw8.color; import javafx.scene.paint.Color; -import org.jhotdraw8.color.util.MathUtil; import java.awt.color.ColorSpace; @@ -90,7 +89,7 @@ public Color interpolate(double t) { interpolated[hueComponent] = interp; } float[] srgb = cs.toRGB(interpolated); - return new Color(MathUtil.clamp(srgb[0], 0, 1), MathUtil.clamp(srgb[1], 0, 1), MathUtil.clamp(srgb[2], 0, 1), 1); + return new Color(Math.clamp(srgb[0], (float) 0, (float) 1), Math.clamp(srgb[1], (float) 0, (float) 1), Math.clamp(srgb[2], (float) 0, (float) 1), 1); } diff --git a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorUtil.java b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorUtil.java index e7df6becf..19624ed3c 100644 --- a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorUtil.java +++ b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/FXColorUtil.java @@ -6,7 +6,6 @@ package org.jhotdraw8.color; import javafx.scene.paint.Color; -import org.jhotdraw8.color.util.MathUtil; public class FXColorUtil { @@ -37,7 +36,7 @@ public static float[] fromColor(NamedColorSpace colorSpace, Color c) { */ public static Color toColor(NamedColorSpace colorSpace, float[] components) { float[] srgb = colorSpace.toRGB(components); - return new Color(MathUtil.clamp(srgb[0], 0, 1), MathUtil.clamp(srgb[1], 0, 1), MathUtil.clamp(srgb[2], 0, 1), 1); + return new Color(Math.clamp(srgb[0], (float) 0, (float) 1), Math.clamp(srgb[1], (float) 0, (float) 1), Math.clamp(srgb[2], (float) 0, (float) 1), 1); } /** diff --git a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/ParametricHlsColorSpace.java b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/ParametricHlsColorSpace.java index c6539009a..770299fe0 100755 --- a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/ParametricHlsColorSpace.java +++ b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/ParametricHlsColorSpace.java @@ -8,8 +8,6 @@ import java.awt.color.ColorSpace; import java.io.Serial; -import static org.jhotdraw8.color.util.MathUtil.clamp; - /** * A parametric HLS color space computed from an RGB color space. *

@@ -157,9 +155,9 @@ protected float[] hlsToRgb(float[] hls, float[] rgb) { blue = p; } - rgb[0] = (float) clamp(red, 0d, 1d); - rgb[1] = (float) clamp(green, 0d, 1d); - rgb[2] = (float) clamp(blue, 0d, 1d); + rgb[0] = (float) Math.clamp(red, 0d, 1d); + rgb[1] = (float) Math.clamp(green, 0d, 1d); + rgb[2] = (float) Math.clamp(blue, 0d, 1d); return rgb; } diff --git a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/RgbBitConverters.java b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/RgbBitConverters.java index c713de3fb..98eec892e 100644 --- a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/RgbBitConverters.java +++ b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/RgbBitConverters.java @@ -5,8 +5,6 @@ package org.jhotdraw8.color; -import static org.jhotdraw8.color.util.MathUtil.clamp; - /** * Provides conversion functions between RGB bit representations. */ @@ -182,7 +180,7 @@ public static int rgbFloatToArgb32(float[] rgb, float alpha) { || rgb[0] > EPSILON + 1 || rgb[1] > EPSILON + 1 || rgb[2] > EPSILON + 1) { return 0; }*/ - return (clamp((int) (alpha * 255), 0, 255) << 24) | rgbFloatToRgb24(rgb); + return (Math.clamp((int) (alpha * 255), 0, 255) << 24) | rgbFloatToRgb24(rgb); } public static int rgbFloatToPreArgb32(float[] rgb, float alpha, float[] pre) { @@ -192,11 +190,11 @@ public static int rgbFloatToPreArgb32(float[] rgb, float alpha, float[] pre) { || rgb[0] > EPSILON + 1 || rgb[1] > EPSILON + 1 || rgb[2] > EPSILON + 1) { return 0; }*/ - alpha = clamp(alpha, 0, 1); + alpha = Math.clamp(alpha, (float) 0, (float) 1); pre[0] = rgb[0] * alpha; pre[1] = rgb[1] * alpha; pre[2] = rgb[2] * alpha; - return (clamp((int) (alpha * 255), 0, 255) << 24) | rgbFloatToRgb24(pre); + return (Math.clamp((int) (alpha * 255), 0, 255) << 24) | rgbFloatToRgb24(pre); } /** @@ -206,9 +204,9 @@ public static int rgbFloatToPreArgb32(float[] rgb, float alpha, float[] pre) { * @return 24-bit RGB color value */ public static int rgbFloatToRgb24(float[] rgb) { - return (clamp((int) ((rgb[0] + 1f / 512) * 255f), 0, 255) << 16) - | (clamp((int) ((rgb[1] + 1f / 512) * 255f), 0, 255) << 8) - | clamp((int) ((rgb[2] + 1f / 512) * 255f), 0, 255); + return (Math.clamp((int) ((rgb[0] + 1f / 512) * 255f), 0, 255) << 16) + | (Math.clamp((int) ((rgb[1] + 1f / 512) * 255f), 0, 255) << 8) + | Math.clamp((int) ((rgb[2] + 1f / 512) * 255f), 0, 255); } /** diff --git a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/util/MathUtil.java b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/util/MathUtil.java index bd353983d..3744b450f 100644 --- a/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/util/MathUtil.java +++ b/org.jhotdraw8.color/src/main/java/org.jhotdraw8.color/org/jhotdraw8/color/util/MathUtil.java @@ -12,55 +12,6 @@ public class MathUtil { private MathUtil() { } - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - public static float clamp(float value, float min, float max) { - if (Float.isNaN(value) || value < min) { - return min; - } else if (value > max) { - return max; - } - return value; - } - - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - public static double clamp(double value, double min, double max) { - if (Double.isNaN(value) || value < min) { - return min; - } else if (value > max) { - return max; - } - return value; - } - - /** - * Clamps a value to the given range. - * - * @param value the value - * @param min the lower bound of the range - * @param max the upper bound of the range - * @return the constrained value - */ - public static int clamp(int value, int min, int max) { - if (value < min) { - return min; - } - return Math.min(value, max); - } - public static boolean almostEqual(float a, float b, float eps) { return Math.abs(a - b) < eps; } diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/ColorCssConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/ColorCssConverter.java index e6949a6d7..12ea7e888 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/ColorCssConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/ColorCssConverter.java @@ -36,8 +36,6 @@ import java.util.List; import java.util.function.Consumer; -import static org.jhotdraw8.base.util.MathUtil.clamp; - /** * CssColorConverter. *

@@ -205,12 +203,13 @@ yield switch (tt.currentStringNonNull().toLowerCase()) { throw tt.createParseException("Could not convert a string to a CssColor because the closing bracket ')' is missing."); } float[] rgb = clampColors(params); + double value = params.get(3).getValue(); return new CssColor( "color(" + colorSpaceParam + " " + colorParamToString(params) + ")", - new Color(rgb[0], rgb[1], rgb[2], params.size() == 4 ? clamp(params.get(3).getValue(), 0, 1) : 1.0)); + new Color(rgb[0], rgb[1], rgb[2], params.size() == 4 ? Math.clamp(value, 0, 1) : 1.0)); } private static List parseParams(CssTokenizer tt, NamedColorSpace cs) throws IOException, ParseException { @@ -280,7 +279,13 @@ private CssColor parseRgbFunction(CssTokenizer tt) throws ParseException, IOExce rgb[i] = rgb[i] / 255f; } var clamped = clampColors(rgb); - float alpha = params.size() == 4 ? clamp(toPercentage(params.get(3), 0.01, tt), 0, 1) : 1; + float alpha; + if (params.size() == 4) { + float value = toPercentage(params.get(3), 0.01, tt); + alpha = Math.clamp(value, (float) 0, (float) 1); + } else { + alpha = 1; + } return new CssColor( "rgb(" + colorParamToString(params) + ")", new Color(clamped[0], clamped[1], clamped[2], alpha)); @@ -294,7 +299,13 @@ private CssColor parseHslFunction(CssTokenizer tt) throws ParseException, IOExce toPercentage(params.get(1), 1 / 100d, tt) }; float[] rgb = clampColors(CSS_HLS_COLOR_SPACE.toRGB(hls)); - float alpha = params.size() == 4 ? clamp(toPercentage(params.get(3), 0.01, tt), 0, 1) : 1; + float alpha; + if (params.size() == 4) { + float value = toPercentage(params.get(3), 0.01, tt); + alpha = Math.clamp(value, (float) 0, (float) 1); + } else { + alpha = 1; + } return new CssColor( "hsl(" + colorParamToString(params) + ")", new Color(rgb[0], rgb[1], rgb[2], alpha) @@ -310,7 +321,13 @@ private CssColor parseHsbFunction(CssTokenizer tt) throws ParseException, IOExce }; float[] rgb = JAVAFX_HSB_COLOR_SPACE.toRGB(hsb); float[] clamped = clampColors(rgb); - float alpha = params.size() == 4 ? clamp(toPercentage(params.get(3), 0.01, tt), 0, 1) : 1; + float alpha; + if (params.size() == 4) { + float value = toPercentage(params.get(3), 0.01, tt); + alpha = Math.clamp(value, (float) 0, (float) 1); + } else { + alpha = 1; + } return new CssColor( "hsb(" + colorParamToString(params) + ")", new Color(clamped[0], clamped[1], clamped[2], alpha)); @@ -360,7 +377,7 @@ private static float[] clampColors(List params) { private static float[] clampColors(float[] params) { float[] clamped = new float[3]; for (int i = 0; i < clamped.length; i++) { - clamped[i] = clamp(params[i], 0, 1); + clamped[i] = Math.clamp(params[i], (float) 0, (float) 1); } return clamped; } diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/EffectCssConverter.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/EffectCssConverter.java index 940f33ede..67a4ceeff 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/EffectCssConverter.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/converter/EffectCssConverter.java @@ -19,7 +19,6 @@ import javafx.scene.paint.Color; import org.jhotdraw8.base.converter.IdResolver; import org.jhotdraw8.base.converter.IdSupplier; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.css.converter.CssConverter; import org.jhotdraw8.css.converter.KebabCaseEnumCssConverter; import org.jhotdraw8.css.parser.CssToken; @@ -187,7 +186,7 @@ private Effect parseBloom(CssTokenizer tt) throws ParseException, IOException { if (tt.next() != ')') { throw tt.createParseException("CSS Effect: ')' expected."); } - return new Bloom(MathUtil.clamp(threshold, 0, 1)); + return new Bloom(Math.clamp(threshold, 0, 1)); } private Effect parseBoxBlur(CssTokenizer tt) throws ParseException, IOException { @@ -196,7 +195,8 @@ private Effect parseBoxBlur(CssTokenizer tt) throws ParseException, IOException int iterations = 1; switch (tt.next()) { case CssTokenType.TT_NUMBER: - width = MathUtil.clamp(tt.currentNumberNonNull().doubleValue(), 0, 255); + double value = tt.currentNumberNonNull().doubleValue(); + width = Math.clamp(value, 0, 255); break; default: tt.pushBack(); @@ -206,7 +206,8 @@ private Effect parseBoxBlur(CssTokenizer tt) throws ParseException, IOException } switch (tt.next()) { case CssTokenType.TT_NUMBER: - height = MathUtil.clamp(tt.currentNumberNonNull().doubleValue(), 0, 255); + double value = tt.currentNumberNonNull().doubleValue(); + height = Math.clamp(value, 0, 255); break; default: tt.pushBack(); @@ -216,7 +217,8 @@ private Effect parseBoxBlur(CssTokenizer tt) throws ParseException, IOException } switch (tt.next()) { case CssTokenType.TT_NUMBER: - iterations = MathUtil.clamp(tt.currentNumberNonNull().intValue(), 0, 3); + int value = tt.currentNumberNonNull().intValue(); + iterations = Math.clamp(value, 0, 3); break; default: tt.pushBack(); @@ -245,7 +247,7 @@ private Effect parseColorAdjust(CssTokenizer tt) throws ParseException, IOExcept default: tt.pushBack(); } - adjust = MathUtil.clamp(adjust, 0, 1); + adjust = Math.clamp(adjust, 0, 1); switch (ident) { case "hue": hue = adjust; @@ -349,13 +351,13 @@ private Effect parseDropShadowOrInnerShadow(CssTokenizer tt, boolean isDropShado final Effect effect; if (isDropShadow) { - DropShadow dropShadow = new DropShadow(blurType, color, MathUtil.clamp(radius, 0, 127), spreadOrChocke, offsetX, offsetY); + DropShadow dropShadow = new DropShadow(blurType, color, Math.clamp(radius, 0, 127), spreadOrChocke, offsetX, offsetY); if (input != null) { dropShadow.setInput(input); } effect = dropShadow; } else { - InnerShadow innerhShadow = new InnerShadow(blurType, color, MathUtil.clamp(radius, 0, 127), spreadOrChocke, offsetX, offsetY); + InnerShadow innerhShadow = new InnerShadow(blurType, color, Math.clamp(radius, 0, 127), spreadOrChocke, offsetX, offsetY); if (input != null) { innerhShadow.setInput(input); } @@ -408,7 +410,8 @@ private Effect parseGaussianBlur(CssTokenizer tt) throws ParseException, IOExcep double radius = 5; switch (tt.next()) { case CssTokenType.TT_NUMBER: - radius = MathUtil.clamp(tt.currentNumberNonNull().doubleValue(), 0, 63); + double value = tt.currentNumberNonNull().doubleValue(); + radius = Math.clamp(value, 0, 63); break; default: tt.pushBack(); @@ -434,7 +437,7 @@ private Effect parseGlow(CssTokenizer tt) throws ParseException, IOException { if (tt.next() != ')') { throw tt.createParseException("CSS Effect: ')' expected."); } - return new Glow(MathUtil.clamp(level, 0, 1)); + return new Glow(Math.clamp(level, 0, 1)); } private Effect parseInnerShadow(CssTokenizer tt) throws ParseException, IOException { @@ -480,7 +483,7 @@ private Effect parseShadow(CssTokenizer tt) throws ParseException, IOException { throw tt.createParseException("CSS Effect: ')' expected."); } } - return new Shadow(blurType, color, MathUtil.clamp(radius, 0, 127)); + return new Shadow(blurType, color, Math.clamp(radius, 0, 127)); } @Override diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/ShsbaCssColor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/ShsbaCssColor.java index 475af1948..9db3c6a99 100644 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/ShsbaCssColor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/ShsbaCssColor.java @@ -10,8 +10,6 @@ import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.UnitConverter; -import static org.jhotdraw8.base.util.MathUtil.clamp; - /** * sHSBA color encoded with numbers and/or percentages. * @@ -59,12 +57,15 @@ public ShsbaCssColor(Color color) { } public ShsbaCssColor(CssSize hue, CssSize saturation, CssSize brightness, CssSize opacity) { + double value = UnitConverter.PERCENTAGE.equals(opacity.getUnits()) ? opacity.getValue() / 100 : opacity.getValue(); + double value1 = UnitConverter.PERCENTAGE.equals(brightness.getUnits()) ? brightness.getValue() / 100 : brightness.getValue(); + double value2 = UnitConverter.PERCENTAGE.equals(saturation.getUnits()) ? saturation.getValue() / 100 : saturation.getValue(); super(toName(hue, saturation, brightness, opacity), Color.hsb( UnitConverter.PERCENTAGE.equals(hue.getUnits()) ? hue.getValue() / 360 : hue.getValue(), - clamp(UnitConverter.PERCENTAGE.equals(saturation.getUnits()) ? saturation.getValue() / 100 : saturation.getValue(), 0, 1), - clamp(UnitConverter.PERCENTAGE.equals(brightness.getUnits()) ? brightness.getValue() / 100 : brightness.getValue(), 0, 1), - clamp(UnitConverter.PERCENTAGE.equals(opacity.getUnits()) ? opacity.getValue() / 100 : opacity.getValue(), 0, 1) + Math.clamp(value2, 0, 1), + Math.clamp(value1, 0, 1), + Math.clamp(value, 0, 1) ) ); this.hue = hue; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SrgbaCssColor.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SrgbaCssColor.java index 457c06512..b106956d7 100644 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SrgbaCssColor.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/css/value/SrgbaCssColor.java @@ -10,8 +10,6 @@ import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.css.value.UnitConverter; -import static org.jhotdraw8.base.util.MathUtil.clamp; - /** * sRGBA color encoded with numbers and/or percentages. * @@ -58,22 +56,30 @@ public SrgbaCssColor(Color color) { } public SrgbaCssColor(CssSize red, CssSize green, CssSize blue, CssSize opacity) { + double value = UnitConverter.PERCENTAGE.equals(opacity.getUnits()) ? opacity.getValue() / 100 : opacity.getValue(); + double value1 = UnitConverter.PERCENTAGE.equals(blue.getUnits()) ? blue.getValue() * 2.55 : blue.getValue(); + double value2 = UnitConverter.PERCENTAGE.equals(green.getUnits()) ? green.getValue() * 2.55 : green.getValue(); + double value3 = UnitConverter.PERCENTAGE.equals(red.getUnits()) ? red.getValue() * 2.55 : red.getValue(); + double value4 = UnitConverter.PERCENTAGE.equals(opacity.getUnits()) ? opacity.getValue() / 100 : opacity.getValue(); + double value5 = UnitConverter.PERCENTAGE.equals(blue.getUnits()) ? blue.getValue() / 100 : blue.getValue() / 255; + double value6 = UnitConverter.PERCENTAGE.equals(green.getUnits()) ? green.getValue() / 100 : green.getValue() / 255; + double value7 = UnitConverter.PERCENTAGE.equals(red.getUnits()) ? red.getValue() / 100 : red.getValue() / 255; super(toName(red, green, blue, opacity), (UnitConverter.PERCENTAGE.equals(red.getUnits()) || UnitConverter.PERCENTAGE.equals(green.getUnits()) || UnitConverter.PERCENTAGE.equals(blue.getUnits())) ? Color.color( - clamp(UnitConverter.PERCENTAGE.equals(red.getUnits()) ? red.getValue() / 100 : red.getValue() / 255, 0, 1), - clamp(UnitConverter.PERCENTAGE.equals(green.getUnits()) ? green.getValue() / 100 : green.getValue() / 255, 0, 1), - clamp(UnitConverter.PERCENTAGE.equals(blue.getUnits()) ? blue.getValue() / 100 : blue.getValue() / 255, 0, 1), - clamp(UnitConverter.PERCENTAGE.equals(opacity.getUnits()) ? opacity.getValue() / 100 : opacity.getValue(), 0, 1) + Math.clamp(value7, 0, 1), + Math.clamp(value6, 0, 1), + Math.clamp(value5, 0, 1), + Math.clamp(value4, 0, 1) ) : Color.rgb( - (int) Math.round(clamp(UnitConverter.PERCENTAGE.equals(red.getUnits()) ? red.getValue() * 2.55 : red.getValue(), 0, 255)), - (int) Math.round(clamp(UnitConverter.PERCENTAGE.equals(green.getUnits()) ? green.getValue() * 2.55 : green.getValue(), 0, 255)), - (int) Math.round(clamp(UnitConverter.PERCENTAGE.equals(blue.getUnits()) ? blue.getValue() * 2.55 : blue.getValue(), 0, 255)), - clamp(UnitConverter.PERCENTAGE.equals(opacity.getUnits()) ? opacity.getValue() / 100 : opacity.getValue(), 0, 1) + (int) Math.round(Math.clamp(value3, 0, 255)), + (int) Math.round(Math.clamp(value2, 0, 255)), + (int) Math.round(Math.clamp(value1, 0, 255)), + Math.clamp(value, 0, 1) ) ); this.red = red; diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/gui/ZoomableScrollPane.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/gui/ZoomableScrollPane.java index 07a2b1a73..bed087edc 100644 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/gui/ZoomableScrollPane.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/gui/ZoomableScrollPane.java @@ -47,7 +47,6 @@ import javafx.scene.transform.Scale; import javafx.scene.transform.Transform; import javafx.scene.transform.Translate; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.fxbase.binding.CustomBinding; import org.jhotdraw8.geom.FXTransforms; import org.jspecify.annotations.Nullable; @@ -443,7 +442,7 @@ private void onScrollEvent(ScrollEvent event, ScrollBar scrollBar, double delta) // we only consume if we can scroll if (visible < max - min) { - scrollBar.setValue(MathUtil.clamp(value - delta, min, max)); + scrollBar.setValue(Math.clamp(value - delta, min, max)); event.consume(); } } @@ -537,7 +536,7 @@ private static double getScrollBarPosition(ScrollBar sb) { if (visible > max) { return -Math.round((visible - max) * 0.5); } - return MathUtil.clamp(Math.round((max - min - visible) * (value - min) / (max - min)) + min, min, max); + return Math.clamp(Math.round((max - min - visible) * (value - min) / (max - min)) + min, min, max); } public Bounds getViewportRect() { @@ -585,8 +584,12 @@ public void scrollContentRectToVisible(double x, double y, double w, double h) { hvalue = cx * (hmax - hmin) / (hmax - hvisible) + hmin, vvalue = cy * (vmax - vmin) / (vmax - vvisible) + vmin; - horizontalScrollBar.setValue(MathUtil.clamp(hvalue, horizontalScrollBar.getMin(), horizontalScrollBar.getMax())); - verticalScrollBar.setValue(MathUtil.clamp(vvalue, verticalScrollBar.getMin(), verticalScrollBar.getMax())); + double min1 = horizontalScrollBar.getMin(); + double max1 = horizontalScrollBar.getMax(); + horizontalScrollBar.setValue(Math.clamp(hvalue, min1, max1)); + double min = verticalScrollBar.getMin(); + double max = verticalScrollBar.getMax(); + verticalScrollBar.setValue(Math.clamp(vvalue, min, max)); } diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/locator/BoundsLocator.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/locator/BoundsLocator.java index 00c89f55f..4cc439cc4 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/locator/BoundsLocator.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/locator/BoundsLocator.java @@ -6,7 +6,6 @@ import javafx.geometry.Bounds; import javafx.geometry.Point2D; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.draw.figure.Figure; import org.jspecify.annotations.Nullable; @@ -89,8 +88,8 @@ public BoundsLocator(Bounds bounds, Point2D p) { * @param y a local coordinate on the figre */ public BoundsLocator(Bounds bounds, double x, double y) { - this(MathUtil.clamp((x - bounds.getMinX()) / bounds.getWidth(), 0, 1), - MathUtil.clamp((y - bounds.getMinY()) / bounds.getHeight(), 0, 1)); + this(Math.clamp((x - bounds.getMinX()) / bounds.getWidth(), 0, 1), + Math.clamp((y - bounds.getMinY()) / bounds.getHeight(), 0, 1)); } public double getRelativeX() { diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/CreationTool.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/CreationTool.java index 41332329e..ce6e47c3e 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/CreationTool.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/CreationTool.java @@ -8,7 +8,6 @@ import javafx.scene.Cursor; import javafx.scene.input.MouseEvent; import org.jhotdraw8.application.resources.Resources; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.DrawingEditor; import org.jhotdraw8.draw.DrawingView; @@ -93,8 +92,10 @@ protected void onMousePressed(MouseEvent event, DrawingView view) { x2 = x1; y2 = y1; - double anchorX = MathUtil.clamp(createdFigure.getNonNull(AnchorableFigure.ANCHOR_X), 0, 1); - double anchorY = MathUtil.clamp(createdFigure.getNonNull(AnchorableFigure.ANCHOR_Y), 0, 1); + double value1 = createdFigure.getNonNull(AnchorableFigure.ANCHOR_X); + double anchorX = Math.clamp(value1, 0, 1); + double value = createdFigure.getNonNull(AnchorableFigure.ANCHOR_Y); + double anchorY = Math.clamp(value, 0, 1); CssPoint2D c = diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/LineCreationTool.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/LineCreationTool.java index 4ab73e50d..ebca31b50 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/LineCreationTool.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/LineCreationTool.java @@ -7,7 +7,6 @@ import javafx.geometry.Point2D; import javafx.scene.input.MouseEvent; import org.jhotdraw8.application.resources.Resources; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.figure.AnchorableFigure; @@ -61,8 +60,10 @@ protected void onMousePressed(MouseEvent event, DrawingView view) { DrawingModel dm = view.getModel(); dm.addChildTo(createdFigure, parent); - double anchorX = MathUtil.clamp(createdFigure.getNonNull(AnchorableFigure.ANCHOR_X), 0, 1); - double anchorY = MathUtil.clamp(createdFigure.getNonNull(AnchorableFigure.ANCHOR_Y), 0, 1); + double value1 = createdFigure.getNonNull(AnchorableFigure.ANCHOR_X); + double anchorX = Math.clamp(value1, 0, 1); + double value = createdFigure.getNonNull(AnchorableFigure.ANCHOR_Y); + double anchorY = Math.clamp(value, 0, 1); CssPoint2D c = view.getConstrainer().constrainPoint(createdFigure, diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/SimpleDragTracker.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/SimpleDragTracker.java index 2bf5a4915..6473e59a9 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/SimpleDragTracker.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/SimpleDragTracker.java @@ -8,8 +8,6 @@ import javafx.geometry.Point2D; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; -import org.jspecify.annotations.Nullable; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.draw.DrawingView; import org.jhotdraw8.draw.css.value.CssPoint2D; import org.jhotdraw8.draw.figure.AnchorableFigure; @@ -17,6 +15,7 @@ import org.jhotdraw8.draw.model.DrawingModel; import org.jhotdraw8.fxbase.undo.CompositeEdit; import org.jhotdraw8.graph.iterator.BfsDfsVertexSpliterator; +import org.jspecify.annotations.Nullable; import java.util.Collection; import java.util.HashSet; @@ -127,8 +126,10 @@ public void trackMouseDragged(MouseEvent event, DrawingView view) { // or whatever corner is specified in the anchor Bounds bounds = anchorFigure.getLayoutBounds(); - double anchorX = MathUtil.clamp(anchorFigure.getNonNull(AnchorableFigure.ANCHOR_X), 0, 1); - double anchorY = MathUtil.clamp(anchorFigure.getNonNull(AnchorableFigure.ANCHOR_Y), 0, 1); + double value1 = anchorFigure.getNonNull(AnchorableFigure.ANCHOR_X); + double anchorX = Math.clamp(value1, 0, 1); + double value = anchorFigure.getNonNull(AnchorableFigure.ANCHOR_Y); + double anchorY = Math.clamp(value, 0, 1); Point2D loc = new Point2D(bounds.getMinX() + anchorX * bounds.getWidth(), bounds.getMinY() + anchorY * bounds.getHeight()); diff --git a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/TextCreationTool.java b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/TextCreationTool.java index 9f628b46b..395359b5b 100755 --- a/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/TextCreationTool.java +++ b/org.jhotdraw8.draw/src/main/java/org.jhotdraw8.draw/org/jhotdraw8/draw/tool/TextCreationTool.java @@ -10,9 +10,7 @@ import javafx.scene.control.TextArea; import javafx.scene.input.KeyCode; import javafx.scene.input.MouseEvent; -import org.jspecify.annotations.Nullable; import org.jhotdraw8.application.resources.Resources; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.css.value.CssSize; import org.jhotdraw8.draw.DrawingEditor; import org.jhotdraw8.draw.DrawingView; @@ -25,6 +23,7 @@ import org.jhotdraw8.draw.figure.TextEditableFigure; import org.jhotdraw8.draw.handle.HandleType; import org.jhotdraw8.draw.model.DrawingModel; +import org.jspecify.annotations.Nullable; import java.util.function.Supplier; @@ -127,8 +126,10 @@ protected void onMousePressed(MouseEvent event, DrawingView view) { DrawingModel dm = view.getModel(); dm.addChildTo(createdFigure, parent); - double anchorX = MathUtil.clamp(createdFigure.getNonNull(AnchorableFigure.ANCHOR_X), 0, 1); - double anchorY = MathUtil.clamp(createdFigure.getNonNull(AnchorableFigure.ANCHOR_Y), 0, 1); + double value1 = createdFigure.getNonNull(AnchorableFigure.ANCHOR_X); + double anchorX = Math.clamp(value1, 0, 1); + double value = createdFigure.getNonNull(AnchorableFigure.ANCHOR_Y); + double anchorY = Math.clamp(value, 0, 1); CssPoint2D c = view.getConstrainer().constrainPoint(createdFigure, new CssPoint2D( diff --git a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ChromaticityDiagram.java b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ChromaticityDiagram.java index 04cf9df80..04445e843 100644 --- a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ChromaticityDiagram.java +++ b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ChromaticityDiagram.java @@ -25,12 +25,12 @@ import javafx.scene.shape.Path; import javafx.scene.shape.PathElement; import javafx.scene.transform.Transform; -import org.jspecify.annotations.Nullable; import org.jhotdraw8.base.concurrent.RangeTask; import org.jhotdraw8.color.DisplayP3ColorSpace; import org.jhotdraw8.color.NamedColorSpace; import org.jhotdraw8.color.RgbBitConverters; import org.jhotdraw8.color.SrgbColorSpace; +import org.jspecify.annotations.Nullable; import java.awt.color.ColorSpace; import java.awt.geom.Path2D; @@ -40,8 +40,6 @@ import java.util.List; import java.util.function.BiConsumer; -import static org.jhotdraw8.color.util.MathUtil.clamp; - /** * Draws a chromacity diagram. @@ -254,7 +252,7 @@ private static void scaleToMax(float[] colorvalue) { max = Math.max(max, colorvalue[i]); } for (int i = 0; i < colorvalue.length; i++) { - colorvalue[i] = clamp(colorvalue[i] / max, 0, 1); + colorvalue[i] = Math.clamp(colorvalue[i] / max, (float) 0, (float) 1); } } @@ -290,9 +288,9 @@ private static void reduceChromaIfNegative(float[] colorvalue, int x, int y) { } private static void clampIfTooBright(float[] colorvalue) { - colorvalue[0] = clamp(colorvalue[0], 0, 1); - colorvalue[1] = clamp(colorvalue[1], 0, 1); - colorvalue[2] = clamp(colorvalue[2], 0, 1); + colorvalue[0] = Math.clamp(colorvalue[0], (float) 0, (float) 1); + colorvalue[1] = Math.clamp(colorvalue[1], (float) 0, (float) 1); + colorvalue[2] = Math.clamp(colorvalue[2], (float) 0, (float) 1); } private static void grayIfTooBright(float[] colorvalue) { diff --git a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ColorRect.java b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ColorRect.java index cca65afff..5101b2871 100644 --- a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ColorRect.java +++ b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/colorspace/ColorRect.java @@ -20,8 +20,6 @@ import java.awt.color.ColorSpace; -import static org.jhotdraw8.base.util.MathUtil.clamp; - public class ColorRect extends HBox { private final ObjectProperty colorSpace = new SimpleObjectProperty<>(new NamedColorSpaceAdapter("sRGB", ColorSpace.getInstance(ColorSpace.CS_sRGB))); private final ObjectProperty baseColor = new SimpleObjectProperty<>(new float[3]); @@ -76,8 +74,8 @@ public void update() { float cy = extentCY * y / h + minValueCY; colorValue[yComp] = cy; float[] rgbValue = cs.toRGB(colorValue, rgb); - Color color = new Color(clamp(rgbValue[0], 0, 1), - clamp(rgbValue[1], 0, 1), clamp(rgbValue[2], 0, 1), 1); + Color color = new Color(Math.clamp(rgbValue[0], (float) 0, (float) 1), + Math.clamp(rgbValue[1], (float) 0, (float) 1), Math.clamp(rgbValue[2], (float) 0, (float) 1), 1); pw.setColor(x, y, color); } } diff --git a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/BezierArcLengthExampleMain.java b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/BezierArcLengthExampleMain.java index d4f93a958..d13735bd2 100644 --- a/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/BezierArcLengthExampleMain.java +++ b/org.jhotdraw8.examples/src/main/java/org.jhotdraw8.examples/org/jhotdraw8/examples/mini/BezierArcLengthExampleMain.java @@ -19,7 +19,6 @@ import javafx.scene.shape.Rectangle; import javafx.scene.text.Text; import javafx.stage.Stage; -import org.jhotdraw8.base.util.MathUtil; import org.jhotdraw8.collection.pair.OrderedPair; import org.jhotdraw8.collection.primitive.DoubleArrayList; import org.jhotdraw8.geom.CubicCurveCharacteristics; @@ -87,8 +86,8 @@ public void setPosition(double x, double y) { } private void onMouseDragged(MouseEvent evt) { - setPosition(MathUtil.clamp(round(evt.getX() / 10) * 10, 4, Integer.MAX_VALUE), - MathUtil.clamp(round(evt.getY() / 10) * 10, 4, Integer.MAX_VALUE)); + setPosition(Math.clamp(round(evt.getX() / 10) * 10, 4, (long) Integer.MAX_VALUE), + Math.clamp(round(evt.getY() / 10) * 10, 4, (long) Integer.MAX_VALUE)); handlesChanged(); } } diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/AlphaSlider.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/AlphaSlider.java index 08da6fe87..d9a545247 100644 --- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/AlphaSlider.java +++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/AlphaSlider.java @@ -25,8 +25,6 @@ import java.util.Objects; import java.util.function.ToIntFunction; -import static org.jhotdraw8.base.util.MathUtil.clamp; - /** * This slider shows one component dimension of an {@link NamedColorSpace} @@ -110,8 +108,8 @@ protected void onMousePressedOrDragged(MouseEvent mouseEvent) { requestFocus(); float width = (float) getWidth(); float height = (float) getHeight(); - float x = clamp((float) mouseEvent.getX(), 0, width); - float y = clamp((float) mouseEvent.getY(), 0, height); + float x = Math.clamp((float) mouseEvent.getX(), (float) 0, width); + float y = Math.clamp((float) mouseEvent.getY(), (float) 0, height); float vmax = getAlphaMaxValue(); float vmin = getAlphaMinValue(); @@ -303,19 +301,19 @@ protected void onKeyPressed(KeyEvent keyEvent) { // increment by tick unit case UP, RIGHT -> { keyEvent.consume(); - setAlpha(clamp((float) (vSnappedToTick + tickUnit), vMin, vMax)); + setAlpha(Math.clamp((float) (vSnappedToTick + tickUnit), vMin, vMax)); } // decrement by tick unit case DOWN, LEFT -> { keyEvent.consume(); - setAlpha(clamp((float) (vSnappedToTick - tickUnit), vMin, vMax)); + setAlpha(Math.clamp((float) (vSnappedToTick - tickUnit), vMin, vMax)); } // snap to tick unit case SPACE -> { keyEvent.consume(); - setAlpha(clamp((float) vSnappedToTick, vMin, vMax)); + setAlpha(Math.clamp((float) vSnappedToTick, vMin, vMax)); } } } diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorChooserPaneModel.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorChooserPaneModel.java index 620b511c8..7f7a804be 100644 --- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorChooserPaneModel.java +++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorChooserPaneModel.java @@ -45,8 +45,6 @@ import java.util.Map; import java.util.function.ToIntFunction; -import static org.jhotdraw8.color.util.MathUtil.clamp; - /** * Data flow: *

@@ -829,7 +827,8 @@ private void updateDisplayColor(Observable o, Object oldv, Object newv) {
             displayCs.fromRGB(sourceCs.toRGB(component, rgb), rgb);
             int value = RgbBitConverters.rgbFloatToArgb32(rgb, alpha.floatValue());
             int argb = entry == null ? value : entry.getValue().applyAsInt(value);
-            Color previewColorValue = Color.rgb((argb >>> 16) & 0xff, (argb >>> 8) & 0xff, (argb) & 0xff, clamp(alpha.floatValue(), 0, 1));
+            float value1 = alpha.floatValue();
+            Color previewColorValue = Color.rgb((argb >>> 16) & 0xff, (argb >>> 8) & 0xff, (argb) & 0xff, Math.clamp(value1, (float) 0, (float) 1));
             String hexStr = "00000000" + Integer.toHexString(argb);
             hexStr = hexStr.substring(hexStr.length() - 8);
             previewColor.set(previewColorValue);
diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorRectangleSlider.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorRectangleSlider.java
index 3dea4b21c..eea14b393 100644
--- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorRectangleSlider.java
+++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorRectangleSlider.java
@@ -15,7 +15,6 @@
 import javafx.scene.input.KeyEvent;
 import javafx.scene.input.MouseEvent;
 import org.jhotdraw8.base.concurrent.TileTask;
-import org.jhotdraw8.base.util.MathUtil;
 import org.jhotdraw8.color.NamedColorSpace;
 import org.jspecify.annotations.Nullable;
 
@@ -23,8 +22,6 @@
 import java.util.Objects;
 import java.util.function.ToIntFunction;
 
-import static org.jhotdraw8.base.util.MathUtil.clamp;
-
 
 /**
  * This slider shows two component dimension of an {@link NamedColorSpace}
@@ -125,8 +122,8 @@ protected void onMousePressedOrDragged(MouseEvent mouseEvent) {
         requestFocus();
         float width = (float) getWidth();
         float height = (float) getHeight();
-        float x = MathUtil.clamp((float) mouseEvent.getX(), 0, width);
-        float y = MathUtil.clamp((float) mouseEvent.getY(), 0, height);
+        float x = Math.clamp((float) mouseEvent.getX(), (float) 0, width);
+        float y = Math.clamp((float) mouseEvent.getY(), (float) 0, height);
         NamedColorSpace cs = getSourceColorSpace();
         if (cs == null) {
             return;
@@ -251,28 +248,28 @@ protected void onKeyPressed(KeyEvent keyEvent) {
             // increment by tick unit
             case UP -> {
                 keyEvent.consume();
-                setYValue(clamp((float) (ySnappedToTick + yTickUnit), yMin, yMax));
+                setYValue(Math.clamp((float) (ySnappedToTick + yTickUnit), yMin, yMax));
             }
             case RIGHT -> {
                 keyEvent.consume();
-                setXValue(clamp((float) (xSnappedToTick + xTickUnit), xMin, xMax));
+                setXValue(Math.clamp((float) (xSnappedToTick + xTickUnit), xMin, xMax));
             }
 
             // decrement by tick unit
             case DOWN -> {
                 keyEvent.consume();
-                setYValue(clamp((float) (ySnappedToTick - yTickUnit), yMin, yMax));
+                setYValue(Math.clamp((float) (ySnappedToTick - yTickUnit), yMin, yMax));
             }
             case LEFT -> {
                 keyEvent.consume();
-                setXValue(clamp((float) (xSnappedToTick - xTickUnit), xMin, xMax));
+                setXValue(Math.clamp((float) (xSnappedToTick - xTickUnit), xMin, xMax));
             }
 
             // snap to tick unit
             case SPACE -> {
                 keyEvent.consume();
-                setYValue(clamp((float) ySnappedToTick, yMin, yMax));
-                setXValue(clamp((float) xSnappedToTick, xMin, xMax));
+                setYValue(Math.clamp((float) ySnappedToTick, yMin, yMax));
+                setXValue(Math.clamp((float) xSnappedToTick, xMin, xMax));
             }
         }
     }
diff --git a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorSlider.java b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorSlider.java
index 1b41623fd..1d3bc94a3 100644
--- a/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorSlider.java
+++ b/org.jhotdraw8.fxcontrols/src/main/java/org.jhotdraw8.fxcontrols/org/jhotdraw8/fxcontrols/colorchooser/ColorSlider.java
@@ -26,8 +26,6 @@
 import java.util.Objects;
 import java.util.function.ToIntFunction;
 
-import static org.jhotdraw8.base.util.MathUtil.clamp;
-
 
 /**
  * This slider shows one component dimension of an {@link NamedColorSpace}
@@ -92,19 +90,19 @@ protected void onKeyPressed(KeyEvent keyEvent) {
             // increment by tick unit
             case UP, RIGHT -> {
                 keyEvent.consume();
-                setValue(clamp((float) (vSnappedToTick + tickUnit), vMin, vMax));
+                setValue(Math.clamp((float) (vSnappedToTick + tickUnit), vMin, vMax));
             }
 
             // decrement by tick unit
             case DOWN, LEFT -> {
                 keyEvent.consume();
-                setValue(clamp((float) (vSnappedToTick - tickUnit), vMin, vMax));
+                setValue(Math.clamp((float) (vSnappedToTick - tickUnit), vMin, vMax));
             }
 
             // snap to tick unit
             case SPACE -> {
                 keyEvent.consume();
-                setValue(clamp((float) vSnappedToTick, vMin, vMax));
+                setValue(Math.clamp((float) vSnappedToTick, vMin, vMax));
             }
         }
     }
@@ -161,8 +159,8 @@ protected void onMousePressedOrDragged(MouseEvent mouseEvent) {
         requestFocus();
         float width = (float) getWidth();
         float height = (float) getHeight();
-        float x = clamp((float) mouseEvent.getX(), 0, width);
-        float y = clamp((float) mouseEvent.getY(), 0, height);
+        float x = Math.clamp((float) mouseEvent.getX(), (float) 0, width);
+        float y = Math.clamp((float) mouseEvent.getY(), (float) 0, height);
         NamedColorSpace cs = getSourceColorSpace();
         if (cs == null) {
             return;
diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/FXGeom.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/FXGeom.java
index 0c4da4811..abf0054de 100644
--- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/FXGeom.java
+++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/FXGeom.java
@@ -9,14 +9,13 @@
 import javafx.geometry.Rectangle2D;
 import javafx.scene.transform.Affine;
 import javafx.scene.transform.Transform;
-import org.jhotdraw8.base.util.MathUtil;
 import org.jhotdraw8.geom.intersect.IntersectLineLine;
 import org.jhotdraw8.geom.intersect.IntersectionPointEx;
 import org.jhotdraw8.geom.intersect.IntersectionResultEx;
 import org.jhotdraw8.geom.intersect.IntersectionStatus;
 import org.jspecify.annotations.Nullable;
 
-import java.awt.*;
+import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.PathIterator;
 
@@ -120,13 +119,15 @@ public static Point2D angleToPoint(Rectangle2D r, double angle) {
         double x = 0, y = 0;
         if (abs(si) > e) {
             x = (1.0 + co / abs(si)) / 2.0 * r.getWidth();
-            x = MathUtil.clamp(x, 0, r.getWidth());
+            double max = r.getWidth();
+            x = Math.clamp(x, 0, max);
         } else if (co >= 0.0) {
             x = r.getWidth();
         }
         if (abs(co) > e) {
             y = (1.0 + si / abs(co)) / 2.0 * r.getHeight();
-            y = MathUtil.clamp(y, 0, r.getHeight());
+            double max = r.getHeight();
+            y = Math.clamp(y, 0, max);
         } else if (si >= 0.0) {
             y = r.getHeight();
         }
diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/biarc/ArcToCubicCurve.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/biarc/ArcToCubicCurve.java
index 273f75505..412bd3dda 100644
--- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/biarc/ArcToCubicCurve.java
+++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/biarc/ArcToCubicCurve.java
@@ -7,7 +7,6 @@
 
 import org.jhotdraw8.base.function.DoubleConsumer2;
 import org.jhotdraw8.base.function.DoubleConsumer6;
-import org.jhotdraw8.base.util.MathUtil;
 import org.jhotdraw8.geom.Angles;
 
 import java.util.ArrayList;
@@ -261,7 +260,7 @@ private static double unitVectorAngle(double ux, double uy, double vx, double vy
         int sign = (ux * vy - uy * vx < 0) ? -1 : 1;
 
         // Rounding errors, e.g. -1.0000000000000002 can screw up this.
-        double dot = MathUtil.clamp(ux * vx + uy * vy, -1, 1);
+        double dot = Math.clamp(ux * vx + uy * vy, -1, 1);
 
         return sign * Math.acos(dot);
     }
diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveCubicCurve.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveCubicCurve.java
index cf0125de8..9e19ed269 100644
--- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveCubicCurve.java
+++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveCubicCurve.java
@@ -4,7 +4,6 @@
  */
 package org.jhotdraw8.geom.intersect;
 
-import org.jhotdraw8.base.util.MathUtil;
 import org.jhotdraw8.collection.primitive.DoubleArrayList;
 import org.jhotdraw8.geom.CubicCurves;
 import org.jhotdraw8.geom.PointAndDerivative;
@@ -358,7 +357,7 @@ public static IntersectionResult intersectCubicCurveCubicCurve(Point2D a0, Point
                                                 Points2D.multiply(c23, s * s * s),
                                                 Points2D.multiply(c22, s * s),
                                                 Points2D.multiply(c21, s), c20),
-                                        MathUtil.clamp(xRoot, 0, 1)));
+                                        Math.clamp(xRoot, 0, 1)));
                                 break checkRoots;
                             }
                         }
diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveEllipse.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveEllipse.java
index d291072e3..6006e8dc0 100644
--- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveEllipse.java
+++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectCubicCurveEllipse.java
@@ -4,7 +4,6 @@
  */
 package org.jhotdraw8.geom.intersect;
 
-import org.jhotdraw8.base.util.MathUtil;
 import org.jhotdraw8.collection.primitive.DoubleArrayList;
 import org.jhotdraw8.geom.Angles;
 import org.jhotdraw8.geom.CubicCurves;
@@ -143,7 +142,7 @@ public static IntersectionResult intersectCubicCurveEllipse(
         DoubleArrayList roots = poly.getRootsInInterval(-epsilon, 1 + epsilon);
 
         for (Double root : roots) {
-            double t = MathUtil.clamp(root, 0, 1);
+            double t = Math.clamp(root, 0, 1);
 
             result.add(new IntersectionPoint(
                     Points2D.sum(Points2D.multiply(c3, t * t * t), Points2D.multiply(c2, t * t), Points2D.multiply(c1, t), c0), t));
diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectRayRay.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectRayRay.java
index 36e824b2e..f2a897375 100644
--- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectRayRay.java
+++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/intersect/IntersectRayRay.java
@@ -4,7 +4,6 @@
  */
 package org.jhotdraw8.geom.intersect;
 
-import org.jhotdraw8.base.util.MathUtil;
 import org.jhotdraw8.geom.Points;
 
 import java.awt.geom.Point2D;
@@ -169,7 +168,7 @@ public static IntersectionResultEx intersectRayRayEx(
                         result.add(new IntersectionPointEx(
                                 new Point2D.Double(aox, aoy),
                                 0, derivativeA,
-                                MathUtil.clamp(argB, 0, bmax), derivativeB
+                                Math.clamp(argB, 0, bmax), derivativeB
                         ));
                     } else {
                         status = IntersectionStatus.NO_INTERSECTION_PARALLEL;
@@ -180,7 +179,7 @@ public static IntersectionResultEx intersectRayRayEx(
                         status = IntersectionStatus.INTERSECTION;
                         result.add(new IntersectionPointEx(
                                 new Point2D.Double(box, boy),
-                                MathUtil.clamp(argA, 0, amax), derivativeA, 0, derivativeB
+                                Math.clamp(argA, 0, amax), derivativeA, 0, derivativeB
                         ));
                     } else {
                         status = IntersectionStatus.NO_INTERSECTION_PARALLEL;
@@ -203,8 +202,8 @@ public static IntersectionResultEx intersectRayRayEx(
                     }
 
                     if (at0 < 1 + epsilon && at1 > -epsilon) {
-                        at0 = MathUtil.clamp(at0, 0.0, amax);
-                        at1 = MathUtil.clamp(at1, 0.0, bmax);
+                        at0 = Math.clamp(at0, 0.0, amax);
+                        at1 = Math.clamp(at1, 0.0, bmax);
                         double bt0, bt1;
                         if (Points.almostZero(bdx)) {
                             bt0 = (aoy + at0 * ady - boy) / bdy;
diff --git a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/SimplePathMetrics.java b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/SimplePathMetrics.java
index 110dda67c..cf80959cb 100644
--- a/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/SimplePathMetrics.java
+++ b/org.jhotdraw8.geom/src/main/java/org.jhotdraw8.geom/org/jhotdraw8/geom/shape/SimplePathMetrics.java
@@ -5,7 +5,6 @@
 
 package org.jhotdraw8.geom.shape;
 
-import org.jhotdraw8.base.util.MathUtil;
 import org.jhotdraw8.geom.AbstractShape;
 import org.jhotdraw8.geom.AwtShapes;
 import org.jhotdraw8.geom.CubicCurves;
@@ -18,7 +17,7 @@
 import org.jhotdraw8.geom.intersect.IntersectionStatus;
 import org.jspecify.annotations.Nullable;
 
-import java.awt.*;
+import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.PathIterator;
 import java.awt.geom.Rectangle2D;
@@ -101,7 +100,8 @@ public PointAndDerivative evalAtArcLength(double s) {
         if (commands.length == 0) {
             return new PointAndDerivative(0, 0, 1, 0);
         }
-        s = MathUtil.clamp(s, 0, arcLength());
+        double max = arcLength();
+        s = Math.clamp(s, 0, max);
         int search = Arrays.binarySearch(lengths, s);
         int i = search < 0 ? Math.min(commands.length - 1, ~search) : search;
 
@@ -281,8 +281,8 @@ public PathIterator getSubPathIteratorAtArcLength(double s0, double s1, @Nullabl
         }
 
         double totalArcLength = arcLength();
-        s0 = MathUtil.clamp(s0, 0, totalArcLength);
-        s1 = MathUtil.clamp(s1, s0, totalArcLength);
+        s0 = Math.clamp(s0, 0, totalArcLength);
+        s1 = Math.clamp(s1, s0, totalArcLength);
         boolean startsAtFirstSegment = s0 == 0;
         boolean endsAtLastSegment = s1 == totalArcLength;