Use in over ref modifier in Math functions input parameters

This commit is contained in:
2025-12-06 23:32:47 +02:00
parent ecf074801f
commit bc4b94d2bc
136 changed files with 1824 additions and 1824 deletions

View File

@@ -58,15 +58,15 @@ namespace FlaxEngine.GUI
_canvas.GetWorldMatrix(out var world);
Matrix.Translation((float)bounds.Extents.X, (float)bounds.Extents.Y, 0, out var offset);
Matrix.Multiply(ref offset, ref world, out var boxWorld);
Matrix.Multiply(offset, world, out var boxWorld);
boxWorld.Decompose(out bounds.Transformation);
// Hit test
if (bounds.Intersects(ref ray, out Vector3 hitPoint))
if (bounds.Intersects(ray, out Vector3 hitPoint))
{
// Transform world-space hit point to canvas local-space
world.Invert();
Vector3.Transform(ref hitPoint, ref world, out Vector3 localHitPoint);
Vector3.Transform(hitPoint, world, out Vector3 localHitPoint);
canvasLocation = new Float2(localHitPoint);
return ContainsPoint(ref canvasLocation, precise);
@@ -169,7 +169,7 @@ namespace FlaxEngine.GUI
// Transform canvas local-space point to the game root location
_canvas.GetWorldMatrix(out Matrix world);
Vector3 locationCanvasSpace = new Vector3(location, 0.0f);
Vector3.Transform(ref locationCanvasSpace, ref world, out Vector3 locationWorldSpace);
Vector3.Transform(locationCanvasSpace, world, out Vector3 locationWorldSpace);
camera.ProjectPoint(locationWorldSpace, out location);
return location;
}

View File

@@ -212,7 +212,7 @@ namespace FlaxEngine.GUI
set
{
value = Float2.Max(value, Float2.One);
if (Float2.NearEqual(ref _resolutionMin, ref value))
if (Float2.NearEqual(_resolutionMin, value))
return;
_resolutionMin = value;
PerformLayout();
@@ -231,7 +231,7 @@ namespace FlaxEngine.GUI
set
{
value = Float2.Max(value, Float2.One);
if (Float2.NearEqual(ref _resolutionMax, ref value))
if (Float2.NearEqual(_resolutionMax, value))
return;
_resolutionMax = value;
PerformLayout();
@@ -400,7 +400,7 @@ namespace FlaxEngine.GUI
// Draw children with scale
var scaling = new Float3(_scale, _scale, 1);
Matrix3x3.Scaling(ref scaling, out Matrix3x3 scale);
Matrix3x3.Scaling(scaling, out Matrix3x3 scale);
Render2D.PushTransform(scale);
if (ClipChildren)
{

View File

@@ -262,7 +262,7 @@ namespace FlaxEngine.GUI
public override bool ContainsPoint(ref Float2 location, bool precise = false)
{
if (precise) // Precise check for checkbox element
return _box.Contains(ref location);
return _box.Contains(location);
return base.ContainsPoint(ref location, precise);
}
@@ -271,7 +271,7 @@ namespace FlaxEngine.GUI
{
base.OnMouseMove(location);
_mouseOverBox = _box.Contains(ref location);
_mouseOverBox = _box.Contains(location);
}
/// <inheritdoc />
@@ -298,7 +298,7 @@ namespace FlaxEngine.GUI
if (button == MouseButton.Left && _isPressed)
{
OnPressEnd();
if (_box.Contains(ref location))
if (_box.Contains(location))
{
OnClick();
return true;
@@ -313,7 +313,7 @@ namespace FlaxEngine.GUI
if (button == MouseButton.Left && _isPressed)
{
OnPressEnd();
if (_box.Contains(ref location))
if (_box.Contains(location))
{
OnClick();
return true;
@@ -351,7 +351,7 @@ namespace FlaxEngine.GUI
if (_isPressed)
{
OnPressEnd();
if (_box.Contains(ref location))
if (_box.Contains(location))
{
OnClick();
return true;

View File

@@ -113,7 +113,7 @@ namespace FlaxEngine.GUI
return true;
// Close on click outside the popup
if (!new Rectangle(Float2.Zero, Size).Contains(ref location))
if (!new Rectangle(Float2.Zero, Size).Contains(location))
{
Defocus();
return true;
@@ -129,7 +129,7 @@ namespace FlaxEngine.GUI
return true;
// Close on touch outside the popup
if (!new Rectangle(Float2.Zero, Size).Contains(ref location))
if (!new Rectangle(Float2.Zero, Size).Contains(location))
{
Defocus();
return true;

View File

@@ -340,7 +340,7 @@ namespace FlaxEngine.GUI
for (int i = 0; i < textBlocksCount; i++)
{
ref TextBlock textBlock = ref textBlocks[i];
if (textBlock.Bounds.Intersects(ref viewRect))
if (textBlock.Bounds.Intersects(viewRect))
{
firstTextBlock = i;
break;
@@ -350,7 +350,7 @@ namespace FlaxEngine.GUI
for (int i = textBlocksCount - 1; i > firstTextBlock; i--)
{
ref TextBlock textBlock = ref textBlocks[i];
if (textBlock.Bounds.Intersects(ref viewRect))
if (textBlock.Bounds.Intersects(viewRect))
{
endTextBlock = i + 1;
break;

View File

@@ -416,7 +416,7 @@ public class Slider : ContainerControl
Focus();
float mousePosition = Direction is SliderDirection.HorizontalRight or SliderDirection.HorizontalLeft ? location.X : location.Y;
if (_thumbRect.Contains(ref location))
if (_thumbRect.Contains(location))
{
// Start sliding
_isSliding = true;

View File

@@ -332,7 +332,7 @@ namespace FlaxEngine.GUI
set
{
value = Float2.Round(value);
if (Float2.NearEqual(ref value, ref _targetViewOffset))
if (Float2.NearEqual(value, _targetViewOffset))
return;
_targetViewOffset = _viewOffset = value;
OnTargetViewOffsetChanged();

View File

@@ -581,7 +581,7 @@ namespace FlaxEngine.GUI
predictedLocation = new Float2(Size.X, location.Y - layoutSize.Y);
break;
}
if (new Rectangle(Float2.Zero, Size).Contains(ref predictedLocation))
if (new Rectangle(Float2.Zero, Size).Contains(predictedLocation))
{
var result = NavigationRaycast(direction, predictedLocation, visited);
if (result != null)
@@ -646,8 +646,8 @@ namespace FlaxEngine.GUI
var childNavLocation = child.Center;
var childBounds = child.Bounds;
var childNavDirection = Float2.Normalize(childNavLocation - location);
var childNavCoherence1 = Float2.Dot(ref uiDir1, ref childNavDirection);
var childNavCoherence2 = Float2.Dot(ref uiDir2, ref childNavDirection);
var childNavCoherence1 = Float2.Dot(uiDir1, childNavDirection);
var childNavCoherence2 = Float2.Dot(uiDir2, childNavDirection);
var distance = Rectangle.Distance(childBounds, location);
if (childNavCoherence1 > Mathf.Epsilon && childNavCoherence2 > Mathf.Epsilon && distance < minDistance)
{
@@ -836,9 +836,9 @@ namespace FlaxEngine.GUI
var child = children[i];
if (child.Visible)
{
Matrix3x3.Multiply(ref child._cachedTransform, ref globalTransform, out var globalChildTransform);
Matrix3x3.Multiply(child._cachedTransform, globalTransform, out var globalChildTransform);
var childGlobalRect = new Rectangle(globalChildTransform.M31, globalChildTransform.M32, child.Width * globalChildTransform.M11, child.Height * globalChildTransform.M22);
if (globalClipping.Intersects(ref childGlobalRect))
if (globalClipping.Intersects(childGlobalRect))
{
Render2D.PushTransform(child._cachedTransform);
child.Draw();

View File

@@ -56,7 +56,7 @@ namespace FlaxEngine.GUI
get => _anchorMin;
set
{
if (!_anchorMin.Equals(ref value))
if (!_anchorMin.Equals(value))
{
var bounds = Bounds;
_anchorMin = value;
@@ -75,7 +75,7 @@ namespace FlaxEngine.GUI
get => _anchorMax;
set
{
if (!_anchorMax.Equals(ref value))
if (!_anchorMax.Equals(value))
{
var bounds = Bounds;
_anchorMax = value;
@@ -94,7 +94,7 @@ namespace FlaxEngine.GUI
get => _offsets;
set
{
if (!_offsets.Equals(ref value))
if (!_offsets.Equals(value))
{
_offsets = value;
UpdateBounds();
@@ -153,7 +153,7 @@ namespace FlaxEngine.GUI
get => _bounds.Location;
set
{
if (_bounds.Location.Equals(ref value))
if (_bounds.Location.Equals(value))
return;
var bounds = new Rectangle(value, _bounds.Size);
SetBounds(ref bounds);
@@ -231,7 +231,7 @@ namespace FlaxEngine.GUI
get => _bounds.Size;
set
{
if (_bounds.Size.Equals(ref value))
if (_bounds.Size.Equals(value))
return;
var bounds = new Rectangle(_bounds.Location, value);
if (_pivotRelativeSizing)
@@ -302,7 +302,7 @@ namespace FlaxEngine.GUI
get => _bounds;
set
{
if (!_bounds.Equals(ref value))
if (!_bounds.Equals(value))
SetBounds(ref value);
}
}
@@ -362,7 +362,7 @@ namespace FlaxEngine.GUI
get => _scale;
set
{
if (!_scale.Equals(ref value))
if (!_scale.Equals(value))
{
SetScaleInternal(ref value);
}
@@ -378,7 +378,7 @@ namespace FlaxEngine.GUI
get => _pivot;
set
{
if (!_pivot.Equals(ref value))
if (!_pivot.Equals(value))
{
SetPivotInternal(ref value);
}
@@ -395,7 +395,7 @@ namespace FlaxEngine.GUI
get => _shear;
set
{
if (!_shear.Equals(ref value))
if (!_shear.Equals(value))
{
SetShearInternal(ref value);
}
@@ -425,7 +425,7 @@ namespace FlaxEngine.GUI
[NoAnimate]
public void Resize(ref Float2 value)
{
if (_bounds.Size.Equals(ref value))
if (_bounds.Size.Equals(value))
return;
var bounds = new Rectangle(_bounds.Location, value);
bounds.Location += (_bounds.Size - value) * Pivot; // Pivot-relative resizing
@@ -490,12 +490,12 @@ namespace FlaxEngine.GUI
UpdateTransform();
// Handle location/size changes
if (!_bounds.Location.Equals(ref prevBounds.Location))
if (!_bounds.Location.Equals(prevBounds.Location))
{
OnLocationChanged();
}
if (!_bounds.Size.Equals(ref prevBounds.Size))
if (!_bounds.Size.Equals(prevBounds.Size))
{
OnSizeChanged();
}
@@ -580,7 +580,7 @@ namespace FlaxEngine.GUI
_cachedTransform = m1;
// Cache inverted transform
Matrix3x3.Invert(ref _cachedTransform, out _cachedTransformInv);
Matrix3x3.Invert(_cachedTransform, out _cachedTransformInv);
}
/// <summary>
@@ -598,8 +598,8 @@ namespace FlaxEngine.GUI
var anchorMin = AnchorPresetsData[i].Min;
var anchorMax = AnchorPresetsData[i].Max;
var bounds = _bounds;
if (!Float2.NearEqual(ref _anchorMin, ref anchorMin) ||
!Float2.NearEqual(ref _anchorMax, ref anchorMax))
if (!Float2.NearEqual(_anchorMin, anchorMin) ||
!Float2.NearEqual(_anchorMax, anchorMax))
{
// Disable scrolling for anchored controls (by default but can be manually restored)
if (!anchorMin.IsZero || !anchorMax.IsZero)

View File

@@ -141,7 +141,7 @@ namespace FlaxEngine.GUI
OnParentChangedInternal();
// Check if parent size has been changed
if (_parent != null && !_parent.Size.Equals(ref oldParentSize))
if (_parent != null && !_parent.Size.Equals(oldParentSize))
{
OnParentResized();
}
@@ -204,8 +204,8 @@ namespace FlaxEngine.GUI
var result = AnchorPresets.Custom;
for (int i = 0; i < AnchorPresetsData.Length; i++)
{
if (Float2.NearEqual(ref _anchorMin, ref AnchorPresetsData[i].Min) &&
Float2.NearEqual(ref _anchorMax, ref AnchorPresetsData[i].Max))
if (Float2.NearEqual(_anchorMin, AnchorPresetsData[i].Min) &&
Float2.NearEqual(_anchorMax, AnchorPresetsData[i].Max))
{
result = AnchorPresetsData[i].Preset;
break;
@@ -1218,7 +1218,7 @@ namespace FlaxEngine.GUI
/// <returns>The converted point location in parent control coordinates.</returns>
public virtual Float2 PointToParent(ref Float2 location)
{
Matrix3x3.Transform2D(ref location, ref _cachedTransform, out var result);
Matrix3x3.Transform2D(location, _cachedTransform, out var result);
return result;
}
@@ -1239,7 +1239,7 @@ namespace FlaxEngine.GUI
/// <returns>The converted point location in control's space.</returns>
public virtual Float2 PointFromParent(ref Float2 locationParent)
{
Matrix3x3.Transform2D(ref locationParent, ref _cachedTransformInv, out var result);
Matrix3x3.Transform2D(locationParent, _cachedTransformInv, out var result);
return result;
}

View File

@@ -154,7 +154,7 @@ namespace FlaxEngine.GUI
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Margin left, Margin right)
{
return left.Equals(ref right);
return left.Equals(in right);
}
/// <summary>
@@ -166,7 +166,7 @@ namespace FlaxEngine.GUI
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Margin left, Margin right)
{
return !left.Equals(ref right);
return !left.Equals(in right);
}
/// <summary>
@@ -249,7 +249,7 @@ namespace FlaxEngine.GUI
/// </summary>
/// <param name="other">The <see cref="Margin" /> to compare with this instance.</param>
/// <returns><c>true</c> if the specified <see cref="Margin" /> is equal to this instance; otherwise, <c>false</c>.</returns>
public bool Equals(ref Margin other)
public bool Equals(in Margin other)
{
return Mathf.NearEqual(other.Left, Left) &&
Mathf.NearEqual(other.Right, Right) &&
@@ -261,9 +261,9 @@ namespace FlaxEngine.GUI
/// Determines whether the specified <see cref="Margin"/> are equal.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Equals(ref Margin a, ref Margin b)
public static bool Equals(in Margin a, in Margin b)
{
return a.Equals(ref b);
return a.Equals(in b);
}
/// <summary>
@@ -274,7 +274,7 @@ namespace FlaxEngine.GUI
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Margin other)
{
return Equals(ref other);
return Equals(in other);
}
/// <summary>
@@ -284,7 +284,7 @@ namespace FlaxEngine.GUI
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
public override bool Equals(object value)
{
return value is Margin margin && Equals(ref margin);
return value is Margin margin && Equals(in margin);
}
}
}

View File

@@ -253,7 +253,7 @@ namespace FlaxEngine.GUI
/// <inheritdoc />
public override bool OnTestTooltipOverControl(ref Float2 location)
{
return HeaderRectangle.Contains(ref location);
return HeaderRectangle.Contains(location);
}
/// <summary>
@@ -449,9 +449,9 @@ namespace FlaxEngine.GUI
var child = _children[i];
if (child.IsScrollable && child.Visible)
{
Matrix3x3.Multiply(ref child._cachedTransform, ref globalTransform, out var globalChildTransform);
Matrix3x3.Multiply(child._cachedTransform, globalTransform, out var globalChildTransform);
var childGlobalRect = new Rectangle(globalChildTransform.M31, globalChildTransform.M32, child.Width * globalChildTransform.M11, child.Height * globalChildTransform.M22);
if (globalClipping.Intersects(ref childGlobalRect))
if (globalClipping.Intersects(childGlobalRect))
{
Render2D.PushTransform(child._cachedTransform);
child.Draw();

View File

@@ -637,14 +637,14 @@ namespace FlaxEngine.GUI
{
var upperLeft = Float2.Zero;
var bottomRight = c.Size;
Matrix3x3.Transform2D(ref upperLeft, ref c._cachedTransform, out upperLeft);
Matrix3x3.Transform2D(ref bottomRight, ref c._cachedTransform, out bottomRight);
Float2.Min(ref upperLeft, ref bottomRight, out var min);
Float2.Max(ref upperLeft, ref bottomRight, out var max);
Matrix3x3.Transform2D(upperLeft, c._cachedTransform, out upperLeft);
Matrix3x3.Transform2D(bottomRight, c._cachedTransform, out bottomRight);
Float2.Min(upperLeft, bottomRight, out var min);
Float2.Max(upperLeft, bottomRight, out var max);
if (hasTotal)
{
Float2.Min(ref min, ref totalMin, out totalMin);
Float2.Max(ref max, ref totalMax, out totalMax);
Float2.Min(min, totalMin, out totalMin);
Float2.Max(max, totalMax, out totalMax);
}
else
{
@@ -697,11 +697,11 @@ namespace FlaxEngine.GUI
if (VScrollBar != null && VScrollBar.Enabled && height > MinSize)
{
if (new Rectangle(0, 0, width, AreaSize).Contains(ref location))
if (new Rectangle(0, 0, width, AreaSize).Contains(location))
{
viewOffset.Y -= MoveScale;
}
else if (new Rectangle(0, height - AreaSize, width, AreaSize).Contains(ref location))
else if (new Rectangle(0, height - AreaSize, width, AreaSize).Contains(location))
{
viewOffset.Y += MoveScale;
}
@@ -712,11 +712,11 @@ namespace FlaxEngine.GUI
if (HScrollBar != null && HScrollBar.Enabled && width > MinSize)
{
if (new Rectangle(0, 0, AreaSize, height).Contains(ref location))
if (new Rectangle(0, 0, AreaSize, height).Contains(location))
{
viewOffset.X -= MoveScale;
}
else if (new Rectangle(width - AreaSize, 0, AreaSize, height).Contains(ref location))
else if (new Rectangle(width - AreaSize, 0, AreaSize, height).Contains(location))
{
viewOffset.X += MoveScale;
}

View File

@@ -129,7 +129,7 @@ namespace FlaxEngine.GUI
get => _offset;
set
{
if (!Float2.NearEqual(ref _offset, ref value))
if (!Float2.NearEqual(_offset, value))
{
_offset = value;
PerformLayout();

View File

@@ -449,7 +449,7 @@ namespace FlaxEngine.GUI
float mousePosition = _orientation == Orientation.Vertical ? location.Y : location.X;
if (_thumbRect.Contains(ref location))
if (_thumbRect.Contains(location))
{
// Start moving thumb
_thumbClicked = true;

View File

@@ -43,7 +43,7 @@ namespace FlaxEngine.GUI
{
if (value.MinValue <= 0.0f)
throw new ArgumentException("Tiles cannot have negative size.");
if (!Float2.Equals(ref _tileSize, ref value))
if (!Float2.Equals(_tileSize, value))
{
_tileSize = value;
PerformLayout();

View File

@@ -72,7 +72,7 @@ namespace FlaxEngine.GUI
get => _slotSpacing;
set
{
if (!Float2.NearEqual(ref _slotSpacing, ref value))
if (!Float2.NearEqual(_slotSpacing, value))
{
_slotSpacing = value;
PerformLayout();