Skip to content

Commit

Permalink
Merge pull request #564 from Shallowmallow/Simplification
Browse files Browse the repository at this point in the history
Simplification, removing useless  SIGNIFICANT_DECIMAL_DIGITS
  • Loading branch information
ianharrigan authored Jan 14, 2024
2 parents 47b8faa + b13073f commit 53d4b7e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions haxe/ui/core/Component.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,8 @@ class Component extends ComponentImpl
/** The gap between the component and its children, on the right side **/ @:style(layout) public var paddingTop:Null<Float>;
/** The gap between the component and its children, on the bottom **/ @:style(layout) public var paddingBottom:Null<Float>;

/** The gap between the component and its children, on the top **/ @:style(layout) public var horizontalSpacing:Null<Float>;
/** The gap between the component and its children, on the left side **/ @:style(layout) public var verticalSpacing:Null<Float>;
/** The horizontal spacing between the component's children in pixels **/ @:style(layout) public var horizontalSpacing:Null<Float>;
/** The vertical spacing between the component's children in pixels **/ @:style(layout) public var verticalSpacing:Null<Float>;

/** The amount of left offsetting to apply to the calculated position **/ @:style public var marginLeft:Null<Float>;
/** The amount of right offsetting to apply to the calculated position**/ @:style public var marginRight:Null<Float>;
Expand Down
4 changes: 2 additions & 2 deletions haxe/ui/styles/Style.hx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class Style {
/** The amount of right offset to apply to the calculated position **/ @:optional public var marginRight:Null<Float>;
/** The amount of bottom offset to apply to the calculated position **/ @:optional public var marginBottom:Null<Float>;

/** The vertical spacing between the component's children in pixels**/ @:optional public var horizontalSpacing:Null<Float>;
/** The horizontal spacing between the component's children in pixels**/ @:optional public var verticalSpacing:Null<Float>;
/** The horizontal spacing between the component's children in pixels**/ @:optional public var horizontalSpacing:Null<Float>;
/** The vertical spacing between the component's children in pixels**/ @:optional public var verticalSpacing:Null<Float>;

/** The color of the text **/ @:optional public var color:Null<Int>;

Expand Down
11 changes: 7 additions & 4 deletions haxe/ui/util/MathUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package haxe.ui.util;
class MathUtil {
public static inline var MAX_INT:Int = 2147483647; // 2**31 - 1
public static inline var MIN_INT:Int = -2147483648;
public static inline var SIGNIFICANT_DECIMAL_DIGITS:Int = 7; // 32 bit floats have 24 bits precision log10(2**24) ≈ 7.225 (for 64 bits it's 15)
public static inline var MAX_FLOAT_DIFFERENCE:Float = 0.0000001; // account for floating-point inaccuracy
public static inline var MAX_FLOAT_DIFFERENCE:Float = 0.0000001; // account for floating-point inaccuracy, 32 bit floats have 24 bits precision log10(2**24) ≈ 7.225 (for 64 bits it's 15)

public static inline function distance(x1:Float, y1:Float, x2:Float, y2:Float):Float {
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

/**
Precision is the number of significant decimal digits
Returns a precision between 0 and 7
**/
public static inline function precision(v:Float):Int {
var e = 1;
var p = 0;
Expand All @@ -24,7 +27,7 @@ class MathUtil {
if (!Math.isFinite(v1) || !Math.isFinite(v2)) {
return Math.NaN;
}
var p = Std.int(Math.min(SIGNIFICANT_DECIMAL_DIGITS, Math.max(precision(v1), precision(v2))));
var p = Std.int(Math.max(precision(v1), precision(v2)));
var e = 1;
for ( i in 0...p) {
e *= 10;
Expand All @@ -42,7 +45,7 @@ class MathUtil {
if (!Math.isFinite(v) || !Math.isFinite(n)) {
return Math.NaN;
}
var p = Std.int(Math.min(SIGNIFICANT_DECIMAL_DIGITS, Math.max(precision(v), precision(n))));
var p = Std.int(Math.max(precision(v), precision(n)));
var inv = 1.0 / n;
return round(Math.fround(v * inv) / inv, p);
}
Expand Down

0 comments on commit 53d4b7e

Please sign in to comment.