From bc4b94d2bc5887d58758d0e59189bd52113fec47 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 6 Dec 2025 23:32:47 +0200 Subject: [PATCH] Use `in` over `ref` modifier in `Math` functions input parameters --- .../Dedicated/MeshReferenceEditor.cs | 4 +- .../CustomEditors/Editors/AssetRefEditor.cs | 4 +- .../CustomEditors/Editors/CollectionEditor.cs | 4 +- .../Editors/FlaxObjectRefEditor.cs | 4 +- .../CustomEditors/Editors/TypeEditor.cs | 4 +- Source/Editor/Editor.cs | 2 +- Source/Editor/GUI/AssetPicker.cs | 2 +- Source/Editor/GUI/CurveEditor.Contents.cs | 4 +- Source/Editor/GUI/CurveEditor.cs | 12 +- Source/Editor/GUI/Input/SliderControl.cs | 2 +- .../GUI/Timeline/EditCurveTrackGizmo.cs | 6 +- .../Editor/GUI/Timeline/GUI/GradientEditor.cs | 2 +- .../GUI/Timeline/GUI/KeyframesEditor.cs | 4 +- .../Editor/GUI/Timeline/GUI/PositionHandle.cs | 2 +- Source/Editor/GUI/Timeline/Media.cs | 8 +- .../GUI/Timeline/SceneAnimationTimeline.cs | 6 +- Source/Editor/GUI/Timeline/Timeline.cs | 4 +- Source/Editor/GUI/Timeline/Track.cs | 2 +- .../Timeline/Tracks/AnimationEventTrack.cs | 2 +- Source/Editor/GUI/Tree/Tree.cs | 2 +- Source/Editor/GUI/Tree/TreeNode.cs | 4 +- Source/Editor/Gizmo/GridGizmo.cs | 4 +- Source/Editor/Gizmo/TransformGizmo.cs | 2 +- .../Editor/Gizmo/TransformGizmoBase.Draw.cs | 36 +-- .../Gizmo/TransformGizmoBase.Selection.cs | 34 +-- Source/Editor/Gizmo/TransformGizmoBase.cs | 24 +- Source/Editor/Gizmo/UIEditorGizmo.cs | 14 +- .../Gizmo/ViewportRubberBandSelector.cs | 4 +- Source/Editor/SceneGraph/ActorNodeWithIcon.cs | 2 +- .../SceneGraph/Actors/AnimatedModelNode.cs | 14 +- .../Editor/SceneGraph/Actors/BoxBrushNode.cs | 2 +- .../Editor/SceneGraph/Actors/BoxVolumeNode.cs | 2 +- .../Editor/SceneGraph/Actors/NavLinkNode.cs | 2 +- Source/Editor/SceneGraph/Actors/SplineNode.cs | 4 +- .../SceneGraph/Actors/SpriteRenderNode.cs | 12 +- .../SceneGraph/Actors/StaticModelNode.cs | 2 +- .../Editor/SceneGraph/Actors/UICanvasNode.cs | 2 +- Source/Editor/SceneGraph/SceneGraphNode.cs | 2 +- .../Archetypes/Animation.MultiBlend.cs | 8 +- .../Archetypes/Animation.StateMachine.cs | 44 ++-- Source/Editor/Surface/Archetypes/Function.cs | 6 +- Source/Editor/Surface/Archetypes/Material.cs | 4 +- .../Surface/Archetypes/ParticleModules.cs | 2 +- Source/Editor/Surface/Archetypes/Particles.cs | 2 +- Source/Editor/Surface/Archetypes/Tools.cs | 10 +- Source/Editor/Surface/Elements/OutputBox.cs | 14 +- Source/Editor/Surface/SurfaceComment.cs | 14 +- Source/Editor/Surface/SurfaceControl.cs | 2 +- Source/Editor/Surface/SurfaceNode.cs | 12 +- Source/Editor/Surface/SurfaceRootControl.cs | 4 +- Source/Editor/Surface/VisjectSurfaceWindow.cs | 2 +- Source/Editor/Tools/ClothPainting.cs | 2 +- .../Editor/Tools/Foliage/EditFoliageGizmo.cs | 6 +- .../Tools/Terrain/Brushes/CircleBrush.cs | 2 +- Source/Editor/Tools/Terrain/Paint/Mode.cs | 2 +- .../Tools/Terrain/Paint/SingleLayerMode.cs | 2 +- .../Tools/Terrain/PaintTerrainGizmoMode.cs | 4 +- .../Tools/Terrain/Sculpt/FlattenMode.cs | 2 +- .../Editor/Tools/Terrain/Sculpt/HolesMode.cs | 2 +- Source/Editor/Tools/Terrain/Sculpt/Mode.cs | 2 +- .../Editor/Tools/Terrain/Sculpt/NoiseMode.cs | 2 +- .../Editor/Tools/Terrain/Sculpt/SculptMode.cs | 2 +- .../Editor/Tools/Terrain/Sculpt/SmoothMode.cs | 2 +- .../Tools/Terrain/SculptTerrainGizmoMode.cs | 4 +- Source/Editor/Tools/VertexPainting.cs | 4 +- .../Undo/Actions/TransformObjectsAction.cs | 2 +- Source/Editor/Utilities/Utils.cs | 30 +-- Source/Editor/Viewport/Cameras/FPSCamera.cs | 4 +- .../Editor/Viewport/Cameras/ViewportCamera.cs | 2 +- Source/Editor/Viewport/EditorViewport.cs | 16 +- .../Viewport/MainEditorGizmoViewport.cs | 14 +- .../Editor/Viewport/PrefabWindowViewport.cs | 6 +- .../Editor/Viewport/Previews/ModelPreview.cs | 2 +- .../Viewport/Previews/SkinnedModelPreview.cs | 2 +- .../Editor/Viewport/ViewportDraggingHelper.cs | 2 +- .../Editor/Windows/Assets/ModelBaseWindow.cs | 2 +- Source/Editor/Windows/GameWindow.cs | 2 +- Source/Engine/Animations/Curve.cs | 156 ++++++------- Source/Engine/Core/Math/BoundingBox.cs | 118 +++++----- Source/Engine/Core/Math/BoundingFrustum.cs | 156 ++++++------- Source/Engine/Core/Math/BoundingSphere.cs | 76 +++---- Source/Engine/Core/Math/CollisionsHelper.cs | 196 ++++++++--------- Source/Engine/Core/Math/Color.cs | 26 +-- Source/Engine/Core/Math/Double2.cs | 124 +++++------ Source/Engine/Core/Math/Double3.cs | 148 ++++++------- Source/Engine/Core/Math/Double4.cs | 88 ++++---- Source/Engine/Core/Math/Float2.cs | 124 +++++------ Source/Engine/Core/Math/Float3.cs | 148 ++++++------- Source/Engine/Core/Math/Float4.cs | 88 ++++---- Source/Engine/Core/Math/FloatR10G10B10A2.cs | 2 +- Source/Engine/Core/Math/FloatR11G11B10.cs | 2 +- Source/Engine/Core/Math/Half.cs | 2 +- Source/Engine/Core/Math/Half2.cs | 6 +- Source/Engine/Core/Math/Half3.cs | 6 +- Source/Engine/Core/Math/Half4.cs | 6 +- Source/Engine/Core/Math/Int2.cs | 54 ++--- Source/Engine/Core/Math/Int3.cs | 56 ++--- Source/Engine/Core/Math/Int4.cs | 44 ++-- Source/Engine/Core/Math/Matrix.cs | 208 +++++++++--------- Source/Engine/Core/Math/Matrix2x2.cs | 24 +- Source/Engine/Core/Math/Matrix3x3.cs | 162 +++++++------- .../Engine/Core/Math/OrientedBoundingBox.cs | 60 ++--- Source/Engine/Core/Math/Plane.cs | 66 +++--- Source/Engine/Core/Math/Quaternion.cs | 156 ++++++------- Source/Engine/Core/Math/Ray.cs | 88 ++++---- Source/Engine/Core/Math/Rectangle.cs | 32 +-- Source/Engine/Core/Math/Transform.cs | 94 ++++---- Source/Engine/Core/Math/Vector2.cs | 124 +++++------ Source/Engine/Core/Math/Vector3.cs | 154 ++++++------- Source/Engine/Core/Math/Vector4.cs | 88 ++++---- Source/Engine/Core/Math/Viewport.cs | 32 +-- Source/Engine/Graphics/Models/MeshAccessor.cs | 4 +- Source/Engine/Graphics/RenderView.cs | 14 +- .../Textures/GPUTextureDescription.cs | 2 +- Source/Engine/Level/Actor.cs | 4 +- Source/Engine/Physics/Collisions.cs | 2 +- Source/Engine/Tests/TestTransform.cs | 34 +-- Source/Engine/UI/GUI/CanvasRootControl.cs | 8 +- Source/Engine/UI/GUI/CanvasScaler.cs | 6 +- Source/Engine/UI/GUI/Common/CheckBox.cs | 10 +- Source/Engine/UI/GUI/Common/Dropdown.cs | 4 +- .../Engine/UI/GUI/Common/RichTextBoxBase.cs | 4 +- Source/Engine/UI/GUI/Common/Slider.cs | 2 +- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 2 +- Source/Engine/UI/GUI/ContainerControl.cs | 10 +- Source/Engine/UI/GUI/Control.Bounds.cs | 30 +-- Source/Engine/UI/GUI/Control.cs | 10 +- Source/Engine/UI/GUI/Margin.cs | 14 +- Source/Engine/UI/GUI/Panels/DropPanel.cs | 6 +- Source/Engine/UI/GUI/Panels/Panel.cs | 20 +- .../Engine/UI/GUI/Panels/PanelWithMargins.cs | 2 +- Source/Engine/UI/GUI/Panels/ScrollBar.cs | 2 +- Source/Engine/UI/GUI/Panels/TilesPanel.cs | 2 +- .../Engine/UI/GUI/Panels/UniformGridPanel.cs | 2 +- Source/Engine/UI/UICanvas.cs | 46 ++-- Source/Engine/UI/UIControl.cs | 2 +- 136 files changed, 1824 insertions(+), 1824 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/MeshReferenceEditor.cs b/Source/Editor/CustomEditors/Dedicated/MeshReferenceEditor.cs index 9cb8ab57c..4cf2d9ebd 100644 --- a/Source/Editor/CustomEditors/Dedicated/MeshReferenceEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/MeshReferenceEditor.cs @@ -164,11 +164,11 @@ namespace FlaxEditor.CustomEditors.Dedicated var button2Rect = new Rectangle(button1Rect.Right + 2, 1, 14, 14); // Deselect - if (isSelected && button1Rect.Contains(ref location)) + if (isSelected && button1Rect.Contains(location)) Value = new ModelInstanceActor.MeshReference { Actor = null, LODIndex = -1, MeshIndex = -1 }; // Picker dropdown menu - if ((isSelected ? button2Rect : button1Rect).Contains(ref location)) + if ((isSelected ? button2Rect : button1Rect).Contains(location)) ShowDropDownMenu(); return base.OnMouseUp(location, button); diff --git a/Source/Editor/CustomEditors/Editors/AssetRefEditor.cs b/Source/Editor/CustomEditors/Editors/AssetRefEditor.cs index b407d9a3c..a9122cf17 100644 --- a/Source/Editor/CustomEditors/Editors/AssetRefEditor.cs +++ b/Source/Editor/CustomEditors/Editors/AssetRefEditor.cs @@ -192,7 +192,7 @@ namespace FlaxEditor.CustomEditors.Editors public override bool OnMouseDown(Float2 location, MouseButton button) { - if (DropdownRect.Contains(ref location)) + if (DropdownRect.Contains(location)) { Focus(); ShowPicker(); @@ -206,7 +206,7 @@ namespace FlaxEditor.CustomEditors.Editors { base.OnMouseMove(location); - if (DropdownRect.Contains(ref location)) + if (DropdownRect.Contains(location)) Cursor = CursorType.Default; else Cursor = CursorType.IBeam; diff --git a/Source/Editor/CustomEditors/Editors/CollectionEditor.cs b/Source/Editor/CustomEditors/Editors/CollectionEditor.cs index b3fff5644..3c54f4d14 100644 --- a/Source/Editor/CustomEditors/Editors/CollectionEditor.cs +++ b/Source/Editor/CustomEditors/Editors/CollectionEditor.cs @@ -155,7 +155,7 @@ namespace FlaxEditor.CustomEditors.Editors /// public override bool OnMouseDown(Float2 location, MouseButton button) { - if (button == MouseButton.Left && _arrangeButtonRect.Contains(ref location)) + if (button == MouseButton.Left && _arrangeButtonRect.Contains(location)) { _arrangeButtonInUse = true; Focus(); @@ -371,7 +371,7 @@ namespace FlaxEditor.CustomEditors.Editors /// public override bool OnMouseDown(Float2 location, MouseButton button) { - if (button == MouseButton.Left && _arrangeButtonRect.Contains(ref location)) + if (button == MouseButton.Left && _arrangeButtonRect.Contains(location)) { _arrangeButtonInUse = true; Focus(); diff --git a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs index d7ab6d12b..9c207812c 100644 --- a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs +++ b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs @@ -321,11 +321,11 @@ namespace FlaxEditor.CustomEditors.Editors var button2Rect = new Rectangle(button1Rect.Right + 2, 1, 14, 14); // Deselect - if (_value != null && button1Rect.Contains(ref location)) + if (_value != null && button1Rect.Contains(location)) Value = null; // Picker dropdown menu - if (_supportsPickDropDown && (isSelected ? button2Rect : button1Rect).Contains(ref location)) + if (_supportsPickDropDown && (isSelected ? button2Rect : button1Rect).Contains(location)) { ShowDropDownMenu(); return true; diff --git a/Source/Editor/CustomEditors/Editors/TypeEditor.cs b/Source/Editor/CustomEditors/Editors/TypeEditor.cs index 462902181..c51b3cbcd 100644 --- a/Source/Editor/CustomEditors/Editors/TypeEditor.cs +++ b/Source/Editor/CustomEditors/Editors/TypeEditor.cs @@ -219,11 +219,11 @@ namespace FlaxEditor.CustomEditors.Editors var button2Rect = new Rectangle(button1Rect.Right + 2, 1, 14, 14); // Deselect - if (_value && button1Rect.Contains(ref location) && _type == ScriptType.Null) + if (_value && button1Rect.Contains(location) && _type == ScriptType.Null) Value = ScriptType.Null; // Picker dropdown menu - if ((isSelected && _type == ScriptType.Null ? button2Rect : button1Rect).Contains(ref location)) + if ((isSelected && _type == ScriptType.Null ? button2Rect : button1Rect).Contains(location)) ShowDropDownMenu(); return base.OnMouseUp(location, button); diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs index 58466e35d..aef5385d0 100644 --- a/Source/Editor/Editor.cs +++ b/Source/Editor/Editor.cs @@ -1056,7 +1056,7 @@ namespace FlaxEditor if (actor) { Internal_GetEditorBoxWithChildren(FlaxEngine.Object.GetUnmanagedPtr(actor), out var box); - BoundingSphere.FromBox(ref box, out sphere); + BoundingSphere.FromBox(box, out sphere); if (sphere == BoundingSphere.Empty) sphere = new BoundingSphere(actor.Position, sphere.Radius); sphere.Radius = Math.Max(sphere.Radius, 15.0f); diff --git a/Source/Editor/GUI/AssetPicker.cs b/Source/Editor/GUI/AssetPicker.cs index bf04aa068..4843af52d 100644 --- a/Source/Editor/GUI/AssetPicker.cs +++ b/Source/Editor/GUI/AssetPicker.cs @@ -96,7 +96,7 @@ namespace FlaxEditor.GUI private void DoDrag() { // Do the drag drop operation if has selected element - if (new Rectangle(Float2.Zero, Size).Contains(ref _mouseDownPos)) + if (new Rectangle(Float2.Zero, Size).Contains(_mouseDownPos)) { if (Validator.SelectedAsset != null) DoDragDrop(DragAssets.GetDragData(Validator.SelectedAsset)); diff --git a/Source/Editor/GUI/CurveEditor.Contents.cs b/Source/Editor/GUI/CurveEditor.Contents.cs index c2831046b..35cd5d136 100644 --- a/Source/Editor/GUI/CurveEditor.Contents.cs +++ b/Source/Editor/GUI/CurveEditor.Contents.cs @@ -62,7 +62,7 @@ namespace FlaxEditor.GUI for (int i = 0; i < children.Count; i++) { if (children[i] is KeyframePoint p) - p.IsSelected = p.Bounds.Intersects(ref selectionRect); + p.IsSelected = p.Bounds.Intersects(selectionRect); } _editor.UpdateTangents(); } @@ -85,7 +85,7 @@ namespace FlaxEditor.GUI internal void OnMove(Float2 location) { // Skip updating keyframes until move actual starts to be meaningful - if (Float2.Distance(ref _movingSelectionStartPosLock, ref location) < 1.5f) + if (Float2.Distance(_movingSelectionStartPosLock, location) < 1.5f) return; _movingSelectionStartPosLock = Float2.Minimum; diff --git a/Source/Editor/GUI/CurveEditor.cs b/Source/Editor/GUI/CurveEditor.cs index 4188295f0..06fc0295c 100644 --- a/Source/Editor/GUI/CurveEditor.cs +++ b/Source/Editor/GUI/CurveEditor.cs @@ -689,8 +689,8 @@ namespace FlaxEditor.GUI if (selectedOnly && !point.IsSelected) continue; var pos = point.Point; - Float2.Min(ref posMin, ref pos, out posMin); - Float2.Max(ref posMax, ref pos, out posMax); + Float2.Min(posMin, pos, out posMin); + Float2.Max(posMax, pos, out posMax); } // Apply margin around the area @@ -703,16 +703,16 @@ namespace FlaxEditor.GUI PointFromKeyframesToContents(ref posMin, ref viewRect); PointFromKeyframesToContents(ref posMax, ref viewRect); var tmp = posMin; - Float2.Min(ref posMin, ref posMax, out posMin); - Float2.Max(ref posMax, ref tmp, out posMax); + Float2.Min(posMin, posMax, out posMin); + Float2.Max(posMax, tmp, out posMax); var contentsSize = posMax - posMin; // Convert from Contents to Main Panel posMin = _contents.PointToParent(posMin); posMax = _contents.PointToParent(posMax); tmp = posMin; - Float2.Min(ref posMin, ref posMax, out posMin); - Float2.Max(ref posMax, ref tmp, out posMax); + Float2.Min(posMin, posMax, out posMin); + Float2.Max(posMax, tmp, out posMax); // Update zoom (leave unchanged when focusing a single point) var zoomMask = EnableZoom; diff --git a/Source/Editor/GUI/Input/SliderControl.cs b/Source/Editor/GUI/Input/SliderControl.cs index 4703da73d..1bfed5eee 100644 --- a/Source/Editor/GUI/Input/SliderControl.cs +++ b/Source/Editor/GUI/Input/SliderControl.cs @@ -180,7 +180,7 @@ namespace FlaxEditor.GUI.Input Focus(); float mousePosition = location.X; - if (_thumbRect.Contains(ref location)) + if (_thumbRect.Contains(location)) { // Start sliding _isSliding = true; diff --git a/Source/Editor/GUI/Timeline/EditCurveTrackGizmo.cs b/Source/Editor/GUI/Timeline/EditCurveTrackGizmo.cs index f5212d108..d04603be2 100644 --- a/Source/Editor/GUI/Timeline/EditCurveTrackGizmo.cs +++ b/Source/Editor/GUI/Timeline/EditCurveTrackGizmo.cs @@ -144,7 +144,7 @@ namespace FlaxEditor.GUI.Timeline var k = keyframes[i]; var sphere = new BoundingSphere(k.Value, KeyframeSize); - if (sphere.Intersects(ref selectRay)) + if (sphere.Intersects(selectRay)) { SelectKeyframe(_track, i, 0); return; @@ -154,7 +154,7 @@ namespace FlaxEditor.GUI.Timeline { var t = k.Value + k.TangentIn; var box = BoundingBox.FromSphere(new BoundingSphere(t, TangentSize)); - if (box.Intersects(ref selectRay)) + if (box.Intersects(selectRay)) { SelectKeyframe(_track, i, 1); return; @@ -165,7 +165,7 @@ namespace FlaxEditor.GUI.Timeline { var t = k.Value + k.TangentOut; var box = BoundingBox.FromSphere(new BoundingSphere(t, TangentSize)); - if (box.Intersects(ref selectRay)) + if (box.Intersects(selectRay)) { SelectKeyframe(_track, i, 2); return; diff --git a/Source/Editor/GUI/Timeline/GUI/GradientEditor.cs b/Source/Editor/GUI/Timeline/GUI/GradientEditor.cs index 1ea90da88..772917e7b 100644 --- a/Source/Editor/GUI/Timeline/GUI/GradientEditor.cs +++ b/Source/Editor/GUI/Timeline/GUI/GradientEditor.cs @@ -115,7 +115,7 @@ namespace FlaxEditor.GUI.Timeline.GUI /// public override void OnMouseMove(Float2 location) { - if (_isMoving && Float2.DistanceSquared(ref location, ref _startMovePos) > 25.0f) + if (_isMoving && Float2.DistanceSquared(location, _startMovePos) > 25.0f) { _startMovePos = Float2.Minimum; var x = PointToParent(location).X; diff --git a/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs b/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs index d6fa0e076..5e4bfdf91 100644 --- a/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs +++ b/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs @@ -115,7 +115,7 @@ namespace FlaxEditor.GUI { if (Children[i] is KeyframePoint p) { - p.IsSelected = p.Bounds.Intersects(ref selectionRect); + p.IsSelected = p.Bounds.Intersects(selectionRect); } } } @@ -401,7 +401,7 @@ namespace FlaxEditor.GUI Cursor = CursorType.Default; // Check if no move has been made at all - if (Float2.Distance(ref location, ref _rightMouseDownPos) < 2.0f) + if (Float2.Distance(location, _rightMouseDownPos) < 2.0f) { var selectionCount = _editor.SelectionCount; var point = GetChildAt(location) as KeyframePoint; diff --git a/Source/Editor/GUI/Timeline/GUI/PositionHandle.cs b/Source/Editor/GUI/Timeline/GUI/PositionHandle.cs index 05ae245ee..95620a7b1 100644 --- a/Source/Editor/GUI/Timeline/GUI/PositionHandle.cs +++ b/Source/Editor/GUI/Timeline/GUI/PositionHandle.cs @@ -50,7 +50,7 @@ namespace FlaxEditor.GUI.Timeline.GUI var color = (_timeline.IsMovingPositionHandle ? style.SelectionBorder : style.Foreground).AlphaMultiplied(0.6f); Matrix3x3.RotationZ(Mathf.PiOverTwo, out var m1); var m2 = Matrix3x3.Translation2D(0, timeAxisHeaderOffset); - Matrix3x3.Multiply(ref m1, ref m2, out var m3); + Matrix3x3.Multiply(m1, m2, out var m3); Render2D.PushTransform(m3); // TODO: Convert to its own sprite or 9 slice Render2D.DrawSprite(icon, new Rectangle(new Float2(10, -icon.Size.X * 0.5f - 1), Size + new Float2(0, 1)), color); diff --git a/Source/Editor/GUI/Timeline/Media.cs b/Source/Editor/GUI/Timeline/Media.cs index 1dc5e8b7d..8eeb6863a 100644 --- a/Source/Editor/GUI/Timeline/Media.cs +++ b/Source/Editor/GUI/Timeline/Media.cs @@ -356,7 +356,7 @@ namespace FlaxEditor.GUI.Timeline { Render2D.DrawLine(bounds.UpperLeft, bounds.BottomLeft, moveColor, moveThickness); } - else if (IsMouseOver && CanResize && MoveLeftEdgeRect.Contains(ref _mouseLocation)) + else if (IsMouseOver && CanResize && MoveLeftEdgeRect.Contains(_mouseLocation)) { Render2D.DrawLine(bounds.UpperLeft, bounds.BottomLeft, Color.Yellow); } @@ -364,7 +364,7 @@ namespace FlaxEditor.GUI.Timeline { Render2D.DrawLine(bounds.UpperRight, bounds.BottomRight, moveColor, moveThickness); } - else if (IsMouseOver && CanResize && MoveRightEdgeRect.Contains(ref _mouseLocation)) + else if (IsMouseOver && CanResize && MoveRightEdgeRect.Contains(_mouseLocation)) { Render2D.DrawLine(bounds.UpperRight, bounds.BottomRight, Color.Yellow); } @@ -384,8 +384,8 @@ namespace FlaxEditor.GUI.Timeline _startMoveLocation = Root.MousePosition; _startMoveStartFrame = StartFrame; _startMoveDuration = DurationFrames; - _startMoveLeftEdge = MoveLeftEdgeRect.Contains(ref location) && CanResize; - _startMoveRightEdge = MoveRightEdgeRect.Contains(ref location) && CanResize; + _startMoveLeftEdge = MoveLeftEdgeRect.Contains(location) && CanResize; + _startMoveRightEdge = MoveRightEdgeRect.Contains(location) && CanResize; StartMouseCapture(true); if (_startMoveLeftEdge || _startMoveRightEdge) return true; diff --git a/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs b/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs index b42e33139..30fb0dfba 100644 --- a/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs +++ b/Source/Editor/GUI/Timeline/SceneAnimationTimeline.cs @@ -337,7 +337,7 @@ namespace FlaxEditor.GUI.Timeline DebugDraw.DrawSphere(sphere, selected ? Color.Yellow : Color.Red); sphere.Radius *= 0.95f; DebugDraw.DrawSphere(sphere, new Color(1, 0, 0, coveredAlpha), 0, false); - if (select && sphere.Intersects(ref selectRay)) + if (select && sphere.Intersects(selectRay)) SelectKeyframeGizmo(curveTrack, i, 0); if (!k.TangentIn.IsZero) @@ -349,7 +349,7 @@ namespace FlaxEditor.GUI.Timeline var box = BoundingBox.FromSphere(new BoundingSphere(t, EditCurveTrackGizmo.TangentSize)); DebugDraw.DrawBox(box, selected ? Color.Yellow : Color.AliceBlue); DebugDraw.DrawBox(box, Color.AliceBlue.AlphaMultiplied(coveredAlpha), 0, false); - if (select && box.Intersects(ref selectRay)) + if (select && box.Intersects(selectRay)) SelectKeyframeGizmo(curveTrack, i, 2); } @@ -362,7 +362,7 @@ namespace FlaxEditor.GUI.Timeline var box = BoundingBox.FromSphere(new BoundingSphere(t, EditCurveTrackGizmo.TangentSize)); DebugDraw.DrawBox(box, selected ? Color.Yellow : Color.AliceBlue); DebugDraw.DrawBox(box, Color.AliceBlue.AlphaMultiplied(coveredAlpha), 0, false); - if (select && box.Intersects(ref selectRay)) + if (select && box.Intersects(selectRay)) SelectKeyframeGizmo(curveTrack, i, 2); } diff --git a/Source/Editor/GUI/Timeline/Timeline.cs b/Source/Editor/GUI/Timeline/Timeline.cs index 15e7eb953..3fc6c50f2 100644 --- a/Source/Editor/GUI/Timeline/Timeline.cs +++ b/Source/Editor/GUI/Timeline/Timeline.cs @@ -2078,7 +2078,7 @@ namespace FlaxEditor.GUI.Timeline if (button == MouseButton.Right && _isRightMouseButtonDown) { _isRightMouseButtonDown = false; - if (Float2.Distance(ref location, ref _rightMouseButtonDownPos) < 4.0f) + if (Float2.Distance(location, _rightMouseButtonDownPos) < 4.0f) ShowContextMenu(location); } @@ -2243,7 +2243,7 @@ namespace FlaxEditor.GUI.Timeline foreach (var media in _tracks[i].Media) { - if (media.Bounds.Intersects(ref mediaRect)) + if (media.Bounds.Intersects(mediaRect)) { SelectedMedia.Add(media); selectionChanged = true; diff --git a/Source/Editor/GUI/Timeline/Track.cs b/Source/Editor/GUI/Timeline/Track.cs index a102e6dda..120eee947 100644 --- a/Source/Editor/GUI/Timeline/Track.cs +++ b/Source/Editor/GUI/Timeline/Track.cs @@ -810,7 +810,7 @@ namespace FlaxEditor.GUI.Timeline /// True if hits it. protected virtual bool TestHeaderHit(ref Float2 location) { - return new Rectangle(0, 0, Width, HeaderHeight).Contains(ref location); + return new Rectangle(0, 0, Width, HeaderHeight).Contains(location); } /// diff --git a/Source/Editor/GUI/Timeline/Tracks/AnimationEventTrack.cs b/Source/Editor/GUI/Timeline/Tracks/AnimationEventTrack.cs index f1ef4f9f5..84fc2b877 100644 --- a/Source/Editor/GUI/Timeline/Tracks/AnimationEventTrack.cs +++ b/Source/Editor/GUI/Timeline/Tracks/AnimationEventTrack.cs @@ -208,7 +208,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks // Hit-test dot var size = Height - 2.0f; var rect = new Rectangle(new Float2(size * -0.5f) + Size * 0.5f, new Float2(size)); - return rect.Contains(ref location); + return rect.Contains(location); } return base.ContainsPoint(ref location, precise); diff --git a/Source/Editor/GUI/Tree/Tree.cs b/Source/Editor/GUI/Tree/Tree.cs index 3f60572f6..e097c7dd9 100644 --- a/Source/Editor/GUI/Tree/Tree.cs +++ b/Source/Editor/GUI/Tree/Tree.cs @@ -258,7 +258,7 @@ namespace FlaxEditor.GUI.Tree } var nodeArea = new Rectangle(pos, child.Size); - if (child.IsExpanded && range.Intersects(ref nodeArea)) + if (child.IsExpanded && range.Intersects(nodeArea)) WalkSelectRangeExpandedTree(selection, child, ref range); } } diff --git a/Source/Editor/GUI/Tree/TreeNode.cs b/Source/Editor/GUI/Tree/TreeNode.cs index 389e9df57..8dfb66a9e 100644 --- a/Source/Editor/GUI/Tree/TreeNode.cs +++ b/Source/Editor/GUI/Tree/TreeNode.cs @@ -555,7 +555,7 @@ namespace FlaxEditor.GUI.Tree /// True if hits it. protected virtual bool TestHeaderHit(ref Float2 location) { - return _headerRect.Contains(ref location); + return _headerRect.Contains(location); } /// @@ -871,7 +871,7 @@ namespace FlaxEditor.GUI.Tree static Rectangle GetChildGlobalRectangle(Control control, ref Matrix3x3 globalTransform) { - Matrix3x3.Multiply(ref control._cachedTransform, ref globalTransform, out var globalChildTransform); + Matrix3x3.Multiply(control._cachedTransform, globalTransform, out var globalChildTransform); return new Rectangle(globalChildTransform.M31, globalChildTransform.M32, control.Width * globalChildTransform.M11, control.Height * globalChildTransform.M22); } } diff --git a/Source/Editor/Gizmo/GridGizmo.cs b/Source/Editor/Gizmo/GridGizmo.cs index da6943c9f..4317557a4 100644 --- a/Source/Editor/Gizmo/GridGizmo.cs +++ b/Source/Editor/Gizmo/GridGizmo.cs @@ -113,8 +113,8 @@ namespace FlaxEditor.Gizmo if (cb != IntPtr.Zero) { var data = new Data(); - Matrix.Multiply(ref renderContext.View.View, ref renderContext.View.Projection, out var viewProjection); - Matrix.Transpose(ref viewProjection, out data.ViewProjectionMatrix); + Matrix.Multiply(renderContext.View.View, renderContext.View.Projection, out var viewProjection); + Matrix.Transpose(viewProjection, out data.ViewProjectionMatrix); data.ViewPos = renderContext.View.WorldPosition; data.GridColor = options.Viewport.ViewportGridColor; data.Far = renderContext.View.Far; diff --git a/Source/Editor/Gizmo/TransformGizmo.cs b/Source/Editor/Gizmo/TransformGizmo.cs index 91e37ca25..4b85ca927 100644 --- a/Source/Editor/Gizmo/TransformGizmo.cs +++ b/Source/Editor/Gizmo/TransformGizmo.cs @@ -129,7 +129,7 @@ namespace FlaxEditor.Gizmo if (_selectionParents[i] is ActorNode actorNode) { var b = actorNode.Actor.EditorBoxChildren; - BoundingBox.Merge(ref editorBounds, ref b, out editorBounds); + BoundingBox.Merge(editorBounds, b, out editorBounds); bottomToCenter = Mathf.Min(bottomToCenter, actorNode.Actor.Position.Y - editorBounds.Minimum.Y); } } diff --git a/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs b/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs index 2fab098b3..55c334a84 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.Draw.cs @@ -135,7 +135,7 @@ namespace FlaxEditor.Gizmo Mesh sphereMesh = _modelSphere.LODs[0].Meshes[0]; Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m3); - Matrix.Multiply(ref m3, ref world, out m1); + Matrix.Multiply(m3, world, out m1); mx1 = m1; mx1.M41 += 0.05f; @@ -149,43 +149,43 @@ namespace FlaxEditor.Gizmo // X axis Matrix.RotationY(-Mathf.PiOverTwo, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance xAxisMaterialTransform = (isXAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisX; transAxisMesh.Draw(renderContext, xAxisMaterialTransform, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // Y axis Matrix.RotationX(Mathf.PiOverTwo, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance yAxisMaterialTransform = (isYAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisY; transAxisMesh.Draw(renderContext, yAxisMaterialTransform, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // Z axis Matrix.RotationX(Mathf.Pi, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance zAxisMaterialTransform = (isZAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisZ; transAxisMesh.Draw(renderContext, zAxisMaterialTransform, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // XY plane m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationX(Mathf.PiOverTwo), new Vector3(boxSize * boxScale, boxSize * boxScale, 0.0f)); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance xyPlaneMaterialTransform = (_activeAxis == Axis.XY && !_isDisabled) ? _materialAxisFocus : _materialAxisX; cubeMesh.Draw(renderContext, xyPlaneMaterialTransform, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // ZX plane m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.Identity, new Vector3(boxSize * boxScale, 0.0f, boxSize * boxScale)); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance zxPlaneMaterialTransform = (_activeAxis == Axis.ZX && !_isDisabled) ? _materialAxisFocus : _materialAxisY; cubeMesh.Draw(renderContext, zxPlaneMaterialTransform, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // YZ plane m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationZ(Mathf.PiOverTwo), new Vector3(0.0f, boxSize * boxScale, boxSize * boxScale)); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance yzPlaneMaterialTransform = (_activeAxis == Axis.YZ && !_isDisabled) ? _materialAxisFocus : _materialAxisZ; cubeMesh.Draw(renderContext, yzPlaneMaterialTransform, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // Center sphere Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); sphereMesh.Draw(renderContext, isCenter ? _materialAxisFocus : _materialSphere, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); break; @@ -199,7 +199,7 @@ namespace FlaxEditor.Gizmo // X axis Matrix.RotationZ(Mathf.PiOverTwo, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance xAxisMaterialRotate = (isXAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisX; rotationAxisMesh.Draw(renderContext, xAxisMaterialRotate, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); @@ -209,13 +209,13 @@ namespace FlaxEditor.Gizmo // Z axis Matrix.RotationX(-Mathf.PiOverTwo, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance zAxisMaterialRotate = (isZAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisZ; rotationAxisMesh.Draw(renderContext, zAxisMaterialRotate, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // Center box Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); sphereMesh.Draw(renderContext, isCenter ? _materialAxisFocus : _materialSphere, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); break; @@ -229,43 +229,43 @@ namespace FlaxEditor.Gizmo // X axis Matrix.RotationY(-Mathf.PiOverTwo, out m2); - Matrix.Multiply(ref m2, ref mx1, out m3); + Matrix.Multiply(m2, mx1, out m3); MaterialInstance xAxisMaterialRotate = (isXAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisX; scaleAxisMesh.Draw(renderContext, xAxisMaterialRotate, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // Y axis Matrix.RotationX(Mathf.PiOverTwo, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance yAxisMaterialRotate = (isYAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisY; scaleAxisMesh.Draw(renderContext, yAxisMaterialRotate, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // Z axis Matrix.RotationX(Mathf.Pi, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance zAxisMaterialRotate = (isZAxis && !_isDisabled) ? _materialAxisFocus : _materialAxisZ; scaleAxisMesh.Draw(renderContext, zAxisMaterialRotate, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // XY plane m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationX(Mathf.PiOverTwo), new Vector3(boxSize * boxScale, boxSize * boxScale, 0.0f)); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance xyPlaneMaterialScale = (_activeAxis == Axis.XY && !_isDisabled) ? _materialAxisFocus : _materialAxisX; cubeMesh.Draw(renderContext, xyPlaneMaterialScale, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // ZX plane m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.Identity, new Vector3(boxSize * boxScale, 0.0f, boxSize * boxScale)); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance zxPlaneMaterialScale = (_activeAxis == Axis.ZX && !_isDisabled) ? _materialAxisFocus : _materialAxisZ; cubeMesh.Draw(renderContext, zxPlaneMaterialScale, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // YZ plane m2 = Matrix.Transformation(new Vector3(boxSize, boxSize * 0.1f, boxSize), Quaternion.RotationZ(Mathf.PiOverTwo), new Vector3(0.0f, boxSize * boxScale, boxSize * boxScale)); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); MaterialInstance yzPlaneMaterialScale = (_activeAxis == Axis.YZ && !_isDisabled) ? _materialAxisFocus : _materialAxisY; cubeMesh.Draw(renderContext, yzPlaneMaterialScale, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); // Center box Matrix.Scaling(gizmoModelsScale2RealGizmoSize, out m2); - Matrix.Multiply(ref m2, ref m1, out m3); + Matrix.Multiply(m2, m1, out m3); sphereMesh.Draw(renderContext, isCenter ? _materialAxisFocus : _materialSphere, m3, StaticFlags.None, true, DrawPass.Default, 0.0f, sortOrder); break; diff --git a/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs b/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs index 16f246c55..a7284bf03 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.Selection.cs @@ -36,7 +36,7 @@ namespace FlaxEditor.Gizmo private bool IntersectsRotateCircle(Vector3 normal, ref Ray ray, out Real distance) { var plane = new Plane(Vector3.Zero, normal); - if (!plane.Intersects(ref ray, out distance)) + if (!plane.Intersects(ray, out distance)) return false; Vector3 hitPoint = ray.Position + ray.Direction * distance; Real distanceNormalized = hitPoint.Length / RotateRadiusRaw; @@ -50,8 +50,8 @@ namespace FlaxEditor.Gizmo // Transform ray into local space of the gizmo Ray localRay; - _gizmoWorld.WorldToLocalVector(ref ray.Direction, out localRay.Direction); - _gizmoWorld.WorldToLocal(ref ray.Position, out localRay.Position); + _gizmoWorld.WorldToLocalVector(ray.Direction, out localRay.Direction); + _gizmoWorld.WorldToLocal(ray.Position, out localRay.Position); // Find gizmo collisions with mouse Real closestIntersection = Real.MaxValue; @@ -62,19 +62,19 @@ namespace FlaxEditor.Gizmo case Mode.Translate: { // Axis boxes collision - if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) + if (XAxisBox.Intersects(localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.X; closestIntersection = intersection; } - if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) + if (YAxisBox.Intersects(localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.Y; closestIntersection = intersection; } - if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) + if (ZAxisBox.Intersects(localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.Z; closestIntersection = intersection; @@ -83,25 +83,25 @@ namespace FlaxEditor.Gizmo // Quad planes collision if (closestIntersection >= float.MaxValue) closestIntersection = float.MinValue; - if (XYBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (XYBox.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.XY; closestIntersection = intersection; } - if (XZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (XZBox.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.ZX; closestIntersection = intersection; } - if (YZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (YZBox.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.YZ; closestIntersection = intersection; } /*// Center - if (CenterBoxRaw.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (CenterBoxRaw.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.Center; closestIntersection = intersection; @@ -133,17 +133,17 @@ namespace FlaxEditor.Gizmo case Mode.Scale: { // Boxes collision - if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) + if (XAxisBox.Intersects(localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.X; closestIntersection = intersection; } - if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) + if (YAxisBox.Intersects(localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.Y; closestIntersection = intersection; } - if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection) + if (ZAxisBox.Intersects(localRay, out intersection) && intersection < closestIntersection) { _activeAxis = Axis.Z; closestIntersection = intersection; @@ -153,24 +153,24 @@ namespace FlaxEditor.Gizmo if (closestIntersection >= float.MaxValue) closestIntersection = float.MinValue; - if (XYBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (XYBox.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.XY; closestIntersection = intersection; } - if (XZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (XZBox.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.ZX; closestIntersection = intersection; } - if (YZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (YZBox.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.YZ; closestIntersection = intersection; } // Center - if (CenterBoxRaw.Intersects(ref localRay, out intersection) && intersection > closestIntersection) + if (CenterBoxRaw.Intersects(localRay, out intersection) && intersection > closestIntersection) { _activeAxis = Axis.Center; closestIntersection = intersection; diff --git a/Source/Editor/Gizmo/TransformGizmoBase.cs b/Source/Editor/Gizmo/TransformGizmoBase.cs index b372d78d3..3b22bc790 100644 --- a/Source/Editor/Gizmo/TransformGizmoBase.cs +++ b/Source/Editor/Gizmo/TransformGizmoBase.cs @@ -212,10 +212,10 @@ namespace FlaxEditor.Gizmo Vector3 delta = Vector3.Zero; Ray ray = Owner.MouseRay; - Matrix.RotationQuaternion(ref _gizmoWorld.Orientation, out var rotationMatrix); - Matrix.Invert(ref rotationMatrix, out var invRotationMatrix); + Matrix.RotationQuaternion(_gizmoWorld.Orientation, out var rotationMatrix); + Matrix.Invert(rotationMatrix, out var invRotationMatrix); ray.Position = Vector3.Transform(ray.Position, invRotationMatrix); - Vector3.TransformNormal(ref ray.Direction, ref invRotationMatrix, out ray.Direction); + Vector3.TransformNormal(ray.Direction, invRotationMatrix, out ray.Direction); var position = Position; var planeXY = new Plane(Vector3.Backward, Vector3.Transform(position, invRotationMatrix).Z); @@ -232,7 +232,7 @@ namespace FlaxEditor.Gizmo case Axis.X: { var plane = planeDotXY > planeDotZX ? planeXY : planeZX; - if (ray.Intersects(ref plane, out intersection)) + if (ray.Intersects(plane, out intersection)) { _intersectPosition = ray.GetPoint(intersection); if (!_lastIntersectionPosition.IsZero) @@ -244,7 +244,7 @@ namespace FlaxEditor.Gizmo case Axis.Y: { var plane = planeDotXY > planeDotYZ ? planeXY : planeYZ; - if (ray.Intersects(ref plane, out intersection)) + if (ray.Intersects(plane, out intersection)) { _intersectPosition = ray.GetPoint(intersection); if (!_lastIntersectionPosition.IsZero) @@ -256,7 +256,7 @@ namespace FlaxEditor.Gizmo case Axis.Z: { var plane = planeDotZX > planeDotYZ ? planeZX : planeYZ; - if (ray.Intersects(ref plane, out intersection)) + if (ray.Intersects(plane, out intersection)) { _intersectPosition = ray.GetPoint(intersection); if (!_lastIntersectionPosition.IsZero) @@ -267,7 +267,7 @@ namespace FlaxEditor.Gizmo } case Axis.YZ: { - if (ray.Intersects(ref planeYZ, out intersection)) + if (ray.Intersects(planeYZ, out intersection)) { _intersectPosition = ray.GetPoint(intersection); if (!_lastIntersectionPosition.IsZero) @@ -288,7 +288,7 @@ namespace FlaxEditor.Gizmo } case Axis.XY: { - if (ray.Intersects(ref planeXY, out intersection)) + if (ray.Intersects(planeXY, out intersection)) { _intersectPosition = ray.GetPoint(intersection); if (!_lastIntersectionPosition.IsZero) @@ -309,7 +309,7 @@ namespace FlaxEditor.Gizmo } case Axis.ZX: { - if (ray.Intersects(ref planeZX, out intersection)) + if (ray.Intersects(planeZX, out intersection)) { _intersectPosition = ray.GetPoint(intersection); if (!_lastIntersectionPosition.IsZero) @@ -332,7 +332,7 @@ namespace FlaxEditor.Gizmo { var gizmoToView = Position - Owner.ViewPosition; var plane = new Plane(-Vector3.Normalize(gizmoToView), gizmoToView.Length); - if (ray.Intersects(ref plane, out intersection)) + if (ray.Intersects(plane, out intersection)) { _intersectPosition = ray.GetPoint(intersection); if (!_lastIntersectionPosition.IsZero) @@ -473,11 +473,11 @@ namespace FlaxEditor.Gizmo dir = Float3.Forward * _gizmoWorld.Orientation; Float3 viewDir = Owner.ViewPosition - Position; - Float3.Dot(ref viewDir, ref dir, out float dot); + Float3.Dot(viewDir, dir, out float dot); if (dot < 0.0f) delta *= -1; - Quaternion.RotationAxis(ref dir, delta, out _rotationDelta); + Quaternion.RotationAxis(dir, delta, out _rotationDelta); break; } diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index 32e9a6639..bb90b4917 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -240,7 +240,7 @@ namespace FlaxEditor { foreach (var widget in _widgets) { - if (widget.Bounds.Contains(ref location)) + if (widget.Bounds.Contains(location)) { // Initialize widget movement _activeWidget = widget; @@ -326,7 +326,7 @@ namespace FlaxEditor { foreach (var widget in _widgets) { - if (widget.Bounds.Contains(ref location)) + if (widget.Bounds.Contains(location)) { Cursor = widget.Cursor; cursorChanged = true; @@ -643,10 +643,10 @@ namespace FlaxEditor DrawControlWidget(uiControl, ref ur, ref mousePos, ref widgetHandleSize, viewScale, new Float2(1, -1), CursorType.SizeNESW); DrawControlWidget(uiControl, ref bl, ref mousePos, ref widgetHandleSize, viewScale, new Float2(-1, 1), CursorType.SizeNESW); DrawControlWidget(uiControl, ref br, ref mousePos, ref widgetHandleSize, viewScale, new Float2(1, 1), CursorType.SizeNWSE); - Float2.Lerp(ref ul, ref bl, 0.5f, out var el); - Float2.Lerp(ref ur, ref br, 0.5f, out var er); - Float2.Lerp(ref ul, ref ur, 0.5f, out var eu); - Float2.Lerp(ref bl, ref br, 0.5f, out var eb); + Float2.Lerp(ul, bl, 0.5f, out var el); + Float2.Lerp(ur, br, 0.5f, out var er); + Float2.Lerp(ul, ur, 0.5f, out var eu); + Float2.Lerp(bl, br, 0.5f, out var eb); DrawControlWidget(uiControl, ref el, ref mousePos, ref widgetHandleSize, viewScale, new Float2(-1, 0), CursorType.SizeWE); DrawControlWidget(uiControl, ref er, ref mousePos, ref widgetHandleSize, viewScale, new Float2(1, 0), CursorType.SizeWE); DrawControlWidget(uiControl, ref eu, ref mousePos, ref widgetHandleSize, viewScale, new Float2(0, -1), CursorType.SizeNS); @@ -749,7 +749,7 @@ namespace FlaxEditor default: break; } } - if (rect.Contains(ref mousePos)) + if (rect.Contains(mousePos)) { Render2D.FillRectangle(rect, style.Foreground); Render2D.DrawRectangle(rect, style.SelectionBorder); diff --git a/Source/Editor/Gizmo/ViewportRubberBandSelector.cs b/Source/Editor/Gizmo/ViewportRubberBandSelector.cs index 542e8b388..2859e550a 100644 --- a/Source/Editor/Gizmo/ViewportRubberBandSelector.cs +++ b/Source/Editor/Gizmo/ViewportRubberBandSelector.cs @@ -124,7 +124,7 @@ public sealed class ViewportRubberBandSelector public void ProjectPoint(Vector3 worldSpaceLocation, out Float2 viewportSpaceLocation) { worldSpaceLocation -= _origin; - _viewport.Project(ref worldSpaceLocation, ref _viewProjection, out var projected); + _viewport.Project(worldSpaceLocation, _viewProjection, out var projected); viewportSpaceLocation = new Float2((float)projected.X, (float)projected.Y); } @@ -132,7 +132,7 @@ public sealed class ViewportRubberBandSelector { bounds.Minimum -= _origin; bounds.Maximum -= _origin; - return _frustum.Contains(ref bounds); + return _frustum.Contains(bounds); } } diff --git a/Source/Editor/SceneGraph/ActorNodeWithIcon.cs b/Source/Editor/SceneGraph/ActorNodeWithIcon.cs index 9b0bad8d9..2245e5108 100644 --- a/Source/Editor/SceneGraph/ActorNodeWithIcon.cs +++ b/Source/Editor/SceneGraph/ActorNodeWithIcon.cs @@ -37,7 +37,7 @@ namespace FlaxEditor.SceneGraph var center = _actor.Transform.Translation; ViewportIconsRenderer.GetBounds(center, ray.Ray.Position, out var sphere); - return CollisionsHelper.RayIntersectsSphere(ref ray.Ray, ref sphere, out distance); + return CollisionsHelper.RayIntersectsSphere(ray.Ray, sphere, out distance); } } } diff --git a/Source/Editor/SceneGraph/Actors/AnimatedModelNode.cs b/Source/Editor/SceneGraph/Actors/AnimatedModelNode.cs index cf89f0163..880410169 100644 --- a/Source/Editor/SceneGraph/Actors/AnimatedModelNode.cs +++ b/Source/Editor/SceneGraph/Actors/AnimatedModelNode.cs @@ -109,10 +109,10 @@ namespace FlaxEditor.SceneGraph.Actors // Skin vertex position with the current pose var position = positionStream.GetFloat3(j); - Float3.Transform(ref position, ref skinningMatrices[indices[0]], out Float3 pos0); - Float3.Transform(ref position, ref skinningMatrices[indices[1]], out Float3 pos1); - Float3.Transform(ref position, ref skinningMatrices[indices[2]], out Float3 pos2); - Float3.Transform(ref position, ref skinningMatrices[indices[3]], out Float3 pos3); + Float3.Transform(position, skinningMatrices[indices[0]], out Float3 pos0); + Float3.Transform(position, skinningMatrices[indices[1]], out Float3 pos1); + Float3.Transform(position, skinningMatrices[indices[2]], out Float3 pos2); + Float3.Transform(position, skinningMatrices[indices[3]], out Float3 pos3); position = pos0 * weights[0] + pos1 * weights[1] + pos2 * weights[2] + pos3 * weights[3]; // Add vertex to the bone list @@ -269,8 +269,8 @@ namespace FlaxEditor.SceneGraph.Actors for (int i = 0; i < boneVertices.Count; i++) { var pos = boneTransform.WorldToLocal(boneVertices[i]); - Vector3.Min(ref boneLocalBounds.Minimum, ref pos, out boneLocalBounds.Minimum); - Vector3.Max(ref boneLocalBounds.Maximum, ref pos, out boneLocalBounds.Maximum); + Vector3.Min(boneLocalBounds.Minimum, pos, out boneLocalBounds.Minimum); + Vector3.Max(boneLocalBounds.Maximum, pos, out boneLocalBounds.Maximum); } // Add collision shape @@ -415,7 +415,7 @@ namespace FlaxEditor.SceneGraph.Actors float bkLength = bk.Length; if (bkLength > 0.0f) { - Float3.Transform(ref bk, ref matrix, out Float3 bkA); + Float3.Transform(bk, matrix, out Float3 bkA); bk = bkA / bkLength; } } diff --git a/Source/Editor/SceneGraph/Actors/BoxBrushNode.cs b/Source/Editor/SceneGraph/Actors/BoxBrushNode.cs index 16053f0a8..ce1c8c180 100644 --- a/Source/Editor/SceneGraph/Actors/BoxBrushNode.cs +++ b/Source/Editor/SceneGraph/Actors/BoxBrushNode.cs @@ -207,7 +207,7 @@ namespace FlaxEditor.SceneGraph.Actors /// public override bool RayCastSelf(ref RayCastData ray, out Real distance, out Vector3 normal) { - if (((BoxBrush)_actor).OrientedBox.Intersects(ref ray.Ray)) + if (((BoxBrush)_actor).OrientedBox.Intersects(ray.Ray)) { for (int i = 0; i < ChildNodes.Count; i++) { diff --git a/Source/Editor/SceneGraph/Actors/BoxVolumeNode.cs b/Source/Editor/SceneGraph/Actors/BoxVolumeNode.cs index 37e51dad0..939e83d8c 100644 --- a/Source/Editor/SceneGraph/Actors/BoxVolumeNode.cs +++ b/Source/Editor/SceneGraph/Actors/BoxVolumeNode.cs @@ -107,7 +107,7 @@ namespace FlaxEditor.SceneGraph.Actors { normal = Vector3.Up; var sphere = new BoundingSphere(Transform.Translation, 10.0f); - return sphere.Intersects(ref ray.Ray, out distance); + return sphere.Intersects(ray.Ray, out distance); } /// diff --git a/Source/Editor/SceneGraph/Actors/NavLinkNode.cs b/Source/Editor/SceneGraph/Actors/NavLinkNode.cs index 49469e719..a3bfad3fa 100644 --- a/Source/Editor/SceneGraph/Actors/NavLinkNode.cs +++ b/Source/Editor/SceneGraph/Actors/NavLinkNode.cs @@ -63,7 +63,7 @@ namespace FlaxEditor.SceneGraph.Actors { normal = Vector3.Up; var sphere = new BoundingSphere(Transform.Translation, 10.0f); - return sphere.Intersects(ref ray.Ray, out distance); + return sphere.Intersects(ray.Ray, out distance); } /// diff --git a/Source/Editor/SceneGraph/Actors/SplineNode.cs b/Source/Editor/SceneGraph/Actors/SplineNode.cs index de319ca1d..f7ffc54d2 100644 --- a/Source/Editor/SceneGraph/Actors/SplineNode.cs +++ b/Source/Editor/SceneGraph/Actors/SplineNode.cs @@ -177,7 +177,7 @@ namespace FlaxEditor.SceneGraph.Actors var actor = (Spline)_node.Actor; var pos = actor.GetSplinePoint(Index); var nodeSize = NodeSizeByDistance(Transform.Translation, PointNodeSize, ray.View.Position); - return new BoundingSphere(pos, nodeSize).Intersects(ref ray.Ray, out distance); + return new BoundingSphere(pos, nodeSize).Intersects(ray.Ray, out distance); } public override void OnDebugDraw(ViewportDebugDrawData data) @@ -264,7 +264,7 @@ namespace FlaxEditor.SceneGraph.Actors var actor = (Spline)_node.Actor; var pos = actor.GetSplineTangent(_index, _isIn).Translation; var tangentSize = NodeSizeByDistance(Transform.Translation, TangentNodeSize, ray.View.Position); - return new BoundingSphere(pos, tangentSize).Intersects(ref ray.Ray, out distance); + return new BoundingSphere(pos, tangentSize).Intersects(ray.Ray, out distance); } public override void OnDebugDraw(ViewportDebugDrawData data) diff --git a/Source/Editor/SceneGraph/Actors/SpriteRenderNode.cs b/Source/Editor/SceneGraph/Actors/SpriteRenderNode.cs index c35ac4f9e..1f29cde58 100644 --- a/Source/Editor/SceneGraph/Actors/SpriteRenderNode.cs +++ b/Source/Editor/SceneGraph/Actors/SpriteRenderNode.cs @@ -37,15 +37,15 @@ namespace FlaxEditor.SceneGraph.Actors { var up = Float3.Up; Float3 translation = transform.Translation; - Matrix.Billboard(ref translation, ref viewPosition, ref up, ref viewDirection, out m2); - Matrix.Multiply(ref m1, ref m2, out m3); - Matrix.Scaling(ref transform.Scale, out m1); - Matrix.Multiply(ref m1, ref m3, out world); + Matrix.Billboard(translation, viewPosition, up, viewDirection, out m2); + Matrix.Multiply(m1, m2, out m3); + Matrix.Scaling(transform.Scale, out m1); + Matrix.Multiply(m1, m3, out world); } else { transform.GetWorld(out m2); - Matrix.Multiply(ref m1, ref m2, out world); + Matrix.Multiply(m1, m2, out world); } OrientedBoundingBox bounds; @@ -53,7 +53,7 @@ namespace FlaxEditor.SceneGraph.Actors world.Decompose(out bounds.Transformation); normal = -ray.Ray.Direction; - return bounds.Intersects(ref ray.Ray, out distance); + return bounds.Intersects(ray.Ray, out distance); } /// diff --git a/Source/Editor/SceneGraph/Actors/StaticModelNode.cs b/Source/Editor/SceneGraph/Actors/StaticModelNode.cs index e95364c2d..0db860a98 100644 --- a/Source/Editor/SceneGraph/Actors/StaticModelNode.cs +++ b/Source/Editor/SceneGraph/Actors/StaticModelNode.cs @@ -96,7 +96,7 @@ namespace FlaxEditor.SceneGraph.Actors for (int i = 0; i < verts.Length; i++) { ref var v = ref verts[i]; - var distance = Float3.DistanceSquared(ref pointLocal, ref v); + var distance = Float3.DistanceSquared(pointLocal, v); if (distance <= minDistance) { hit = true; diff --git a/Source/Editor/SceneGraph/Actors/UICanvasNode.cs b/Source/Editor/SceneGraph/Actors/UICanvasNode.cs index 539a72f4e..c4a081c37 100644 --- a/Source/Editor/SceneGraph/Actors/UICanvasNode.cs +++ b/Source/Editor/SceneGraph/Actors/UICanvasNode.cs @@ -64,7 +64,7 @@ namespace FlaxEditor.SceneGraph.Actors normal = Vector3.Up; if (Actor is UICanvas uiCanvas && uiCanvas.Is3D) - return uiCanvas.Bounds.Intersects(ref ray.Ray, out distance); + return uiCanvas.Bounds.Intersects(ray.Ray, out distance); distance = 0; return false; diff --git a/Source/Editor/SceneGraph/SceneGraphNode.cs b/Source/Editor/SceneGraph/SceneGraphNode.cs index 20ac3a6a5..0532e8cbf 100644 --- a/Source/Editor/SceneGraph/SceneGraphNode.cs +++ b/Source/Editor/SceneGraph/SceneGraphNode.cs @@ -352,7 +352,7 @@ namespace FlaxEditor.SceneGraph for (int i = 0; i < ChildNodes.Count; i++) { ChildNodes[i].GetEditorSphere(out var childSphere); - BoundingSphere.Merge(ref sphere, ref childSphere, out sphere); + BoundingSphere.Merge(sphere, childSphere, out sphere); } } diff --git a/Source/Editor/Surface/Archetypes/Animation.MultiBlend.cs b/Source/Editor/Surface/Archetypes/Animation.MultiBlend.cs index 02a59df20..291d90adc 100644 --- a/Source/Editor/Surface/Archetypes/Animation.MultiBlend.cs +++ b/Source/Editor/Surface/Archetypes/Animation.MultiBlend.cs @@ -479,7 +479,7 @@ namespace FlaxEditor.Surface.Archetypes // Scale debug pointer when it moves to make it more visible when investigating blending const float debugMaxSize = 2.0f; - float debugScale = Mathf.Saturate(Float2.Distance(ref _debugPos, ref prev) / new Float2(_rangeX.Absolute.ValuesSum, _rangeY.Absolute.ValuesSum).Length * 100.0f) * debugMaxSize + 1.0f; + float debugScale = Mathf.Saturate(Float2.Distance(_debugPos, prev) / new Float2(_rangeX.Absolute.ValuesSum, _rangeY.Absolute.ValuesSum).Length * 100.0f) * debugMaxSize + 1.0f; float debugBlendSpeed = _debugScale <= debugScale ? 4.0f : 1.0f; _debugScale = Mathf.Lerp(_debugScale, debugScale, deltaTime * debugBlendSpeed); } @@ -1189,9 +1189,9 @@ namespace FlaxEditor.Surface.Archetypes _triangleColors = new Color[_triangles.Length]; for (int i = 0; i < _triangles.Length; i += 3) { - var is0 = Float2.NearEqual(ref _triangles[i + 0], ref pos); - var is1 = Float2.NearEqual(ref _triangles[i + 1], ref pos); - var is2 = Float2.NearEqual(ref _triangles[i + 2], ref pos); + var is0 = Float2.NearEqual(_triangles[i + 0], pos); + var is1 = Float2.NearEqual(_triangles[i + 1], pos); + var is2 = Float2.NearEqual(_triangles[i + 2], pos); if (is0 || is1 || is2) { selectedTriangles.Add(_triangles[i + 0]); diff --git a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs index 4b7554741..8b8481c90 100644 --- a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs +++ b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs @@ -213,7 +213,7 @@ namespace FlaxEditor.Surface.Archetypes if (base.OnMouseDoubleClick(location, button)) return true; - if (_headerRect.Contains(ref location)) + if (_headerRect.Contains(location)) { StartRenaming(); return true; @@ -382,13 +382,13 @@ namespace FlaxEditor.Surface.Archetypes /// public override bool CanSelect(ref Float2 location) { - return _dragAreaRect.MakeOffsetted(Location).Contains(ref location); + return _dragAreaRect.MakeOffsetted(Location).Contains(location); } /// public override bool OnMouseDown(Float2 location, MouseButton button) { - if (button == MouseButton.Left && !_dragAreaRect.Contains(ref location)) + if (button == MouseButton.Left && !_dragAreaRect.Contains(location)) { _isMouseDown = true; Cursor = CursorType.Hand; @@ -687,7 +687,7 @@ namespace FlaxEditor.Surface.Archetypes var upperLeft = bounds.UpperLeft; var bottomRight = bounds.BottomRight; bounds = Rectangle.FromPoints(PointToParent(ref upperLeft), PointToParent(ref bottomRight)); - CollisionsHelper.ClosestPointRectanglePoint(ref bounds, ref startPos, out endPos); + CollisionsHelper.ClosestPointRectanglePoint(bounds, startPos, out endPos); } /// @@ -731,15 +731,15 @@ namespace FlaxEditor.Surface.Archetypes // Check click over the connection var mousePosition = Surface.SurfaceRoot.PointFromParent(ref mouse); - if (!TransitionsRectangle.Contains(ref mousePosition)) + if (!TransitionsRectangle.Contains(mousePosition)) return; for (int i = 0; i < Transitions.Count; i++) { var t = Transitions[i]; - if (t.Bounds.Contains(ref mousePosition)) + if (t.Bounds.Contains(mousePosition)) { - CollisionsHelper.ClosestPointPointLine(ref mousePosition, ref t.StartPos, ref t.EndPos, out var point); - if (Float2.DistanceSquared(ref mousePosition, ref point) < 25.0f) + CollisionsHelper.ClosestPointPointLine(mousePosition, t.StartPos, t.EndPos, out var point); + if (Float2.DistanceSquared(mousePosition, point) < 25.0f) { OnTransitionClicked(t, ref mouse, ref mousePosition, buttons); handled = true; @@ -756,15 +756,15 @@ namespace FlaxEditor.Surface.Archetypes // Check double click over the connection var mousePosition = Surface.SurfaceRoot.PointFromParent(ref mouse); - if (!TransitionsRectangle.Contains(ref mousePosition)) + if (!TransitionsRectangle.Contains(mousePosition)) return; for (int i = 0; i < Transitions.Count; i++) { var t = Transitions[i]; - if (t.Bounds.Contains(ref mousePosition)) + if (t.Bounds.Contains(mousePosition)) { - CollisionsHelper.ClosestPointPointLine(ref mousePosition, ref t.StartPos, ref t.EndPos, out var point); - if (Float2.DistanceSquared(ref mousePosition, ref point) < 25.0f) + CollisionsHelper.ClosestPointPointLine(mousePosition, t.StartPos, t.EndPos, out var point); + if (Float2.DistanceSquared(mousePosition, point) < 25.0f) { t.EditRule(); handled = true; @@ -1007,7 +1007,7 @@ namespace FlaxEditor.Surface.Archetypes var offset = diff ? -6.0f : 6.0f; var dir = startPos - endPos; dir.Normalize(); - Float2.Perpendicular(ref dir, out var nrm); + Float2.Perpendicular(dir, out var nrm); nrm *= offset; startPos += nrm; endPos += nrm; @@ -1031,7 +1031,7 @@ namespace FlaxEditor.Surface.Archetypes t.StartPos = startPos; t.EndPos = endPos; - Rectangle.FromPoints(ref startPos, ref endPos, out t.Bounds); + Rectangle.FromPoints(startPos, endPos, out t.Bounds); t.Bounds.Expand(10.0f); } @@ -1040,7 +1040,7 @@ namespace FlaxEditor.Surface.Archetypes TransitionsRectangle = Transitions[0].Bounds; for (int i = 1; i < Transitions.Count; i++) { - Rectangle.Union(ref TransitionsRectangle, ref Transitions[i].Bounds, out TransitionsRectangle); + Rectangle.Union(TransitionsRectangle, Transitions[i].Bounds, out TransitionsRectangle); } } else @@ -1120,7 +1120,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override bool CanSelect(ref Float2 location) { - return _dragAreaRect.MakeOffsetted(Location).Contains(ref location); + return _dragAreaRect.MakeOffsetted(Location).Contains(location); } /// @@ -1129,7 +1129,7 @@ namespace FlaxEditor.Surface.Archetypes if (base.OnMouseDoubleClick(location, button)) return true; - if (_renameButtonRect.Contains(ref location) || _closeButtonRect.Contains(ref location)) + if (_renameButtonRect.Contains(location) || _closeButtonRect.Contains(location)) return true; return false; @@ -1138,7 +1138,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override bool OnMouseDown(Float2 location, MouseButton button) { - if (button == MouseButton.Left && !_dragAreaRect.Contains(ref location)) + if (button == MouseButton.Left && !_dragAreaRect.Contains(location)) { _isMouseDown = true; Cursor = CursorType.Hand; @@ -1271,11 +1271,11 @@ namespace FlaxEditor.Surface.Archetypes for (int i = 0; i < Transitions.Count; i++) { var t = Transitions[i]; - var isMouseOver = t.Bounds.Contains(ref mousePosition); + var isMouseOver = t.Bounds.Contains(mousePosition); if (isMouseOver) { - CollisionsHelper.ClosestPointPointLine(ref mousePosition, ref t.StartPos, ref t.EndPos, out var point); - isMouseOver = Float2.DistanceSquared(ref mousePosition, ref point) < 25.0f; + CollisionsHelper.ClosestPointPointLine(mousePosition, t.StartPos, t.EndPos, out var point); + isMouseOver = Float2.DistanceSquared(mousePosition, point) < 25.0f; } var color = isMouseOver ? Color.Wheat : t.LineColor; SurfaceStyle.DrawStraightConnection(t.StartPos, t.EndPos, color); @@ -1474,7 +1474,7 @@ namespace FlaxEditor.Surface.Archetypes return true; // Rename - if (_renameButtonRect.Contains(ref location)) + if (_renameButtonRect.Contains(location)) { StartRenaming(); return true; diff --git a/Source/Editor/Surface/Archetypes/Function.cs b/Source/Editor/Surface/Archetypes/Function.cs index 79d3948bf..2a8fd3fa6 100644 --- a/Source/Editor/Surface/Archetypes/Function.cs +++ b/Source/Editor/Surface/Archetypes/Function.cs @@ -308,7 +308,7 @@ namespace FlaxEditor.Surface.Archetypes if (base.OnMouseDoubleClick(location, button)) return true; - if (_nameField.Bounds.Contains(ref location) && Surface.CanEdit) + if (_nameField.Bounds.Contains(location) && Surface.CanEdit) { StartRenaming(); return true; @@ -1128,7 +1128,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override bool OnMouseDoubleClick(Float2 location, MouseButton button) { - if (button == MouseButton.Left && _headerRect.Contains(ref location)) + if (button == MouseButton.Left && _headerRect.Contains(location)) { // Open function content item if exists var method = GetMethod(out var scriptType, out _, out _); @@ -1759,7 +1759,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override bool OnMouseDoubleClick(Float2 location, MouseButton button) { - if (button == MouseButton.Left && _headerRect.Contains(ref location)) + if (button == MouseButton.Left && _headerRect.Contains(location)) { OnEditSignature(); return true; diff --git a/Source/Editor/Surface/Archetypes/Material.cs b/Source/Editor/Surface/Archetypes/Material.cs index e46038639..748c9cd93 100644 --- a/Source/Editor/Surface/Archetypes/Material.cs +++ b/Source/Editor/Surface/Archetypes/Material.cs @@ -347,7 +347,7 @@ namespace FlaxEditor.Surface.Archetypes public override bool CanSelect(ref Float2 location) { - return base.CanSelect(ref location) && !_resizeButtonRect.MakeOffsetted(Location).Contains(ref location); + return base.CanSelect(ref location) && !_resizeButtonRect.MakeOffsetted(Location).Contains(location); } public override void OnSurfaceLoaded(SurfaceNodeActions action) @@ -414,7 +414,7 @@ namespace FlaxEditor.Surface.Archetypes if (base.OnMouseDown(location, button)) return true; - if (button == MouseButton.Left && _resizeButtonRect.Contains(ref location) && Surface.CanEdit) + if (button == MouseButton.Left && _resizeButtonRect.Contains(location) && Surface.CanEdit) { // Start sliding _isResizing = true; diff --git a/Source/Editor/Surface/Archetypes/ParticleModules.cs b/Source/Editor/Surface/Archetypes/ParticleModules.cs index 4a68c31e0..15840bb3d 100644 --- a/Source/Editor/Surface/Archetypes/ParticleModules.cs +++ b/Source/Editor/Surface/Archetypes/ParticleModules.cs @@ -182,7 +182,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override bool OnMouseDown(Float2 location, MouseButton button) { - if (button == MouseButton.Left && _arrangeButtonRect.Contains(ref location)) + if (button == MouseButton.Left && _arrangeButtonRect.Contains(location)) { _arrangeButtonInUse = true; Focus(); diff --git a/Source/Editor/Surface/Archetypes/Particles.cs b/Source/Editor/Surface/Archetypes/Particles.cs index 5b8c05381..dd0915abd 100644 --- a/Source/Editor/Surface/Archetypes/Particles.cs +++ b/Source/Editor/Surface/Archetypes/Particles.cs @@ -191,7 +191,7 @@ namespace FlaxEditor.Surface.Archetypes // Header var headerColor = style.BackgroundHighlighted; - if (_headerRect.Contains(ref _mousePosition)) + if (_headerRect.Contains(_mousePosition)) headerColor *= 1.07f; Render2D.FillRectangle(_headerRect, headerColor); Render2D.DrawText(style.FontLarge, Title, _headerRect, style.Foreground, TextAlignment.Center, TextAlignment.Center); diff --git a/Source/Editor/Surface/Archetypes/Tools.cs b/Source/Editor/Surface/Archetypes/Tools.cs index 8b815624a..94ebd7540 100644 --- a/Source/Editor/Surface/Archetypes/Tools.cs +++ b/Source/Editor/Surface/Archetypes/Tools.cs @@ -169,7 +169,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override void OnMouseMove(Float2 location) { - if (_isMoving && Float2.DistanceSquared(ref location, ref _startMovePos) > 25.0f) + if (_isMoving && Float2.DistanceSquared(location, _startMovePos) > 25.0f) { _startMovePos = Float2.Minimum; int index = Node._stops.IndexOf(this); @@ -1076,12 +1076,12 @@ namespace FlaxEditor.Surface.Archetypes } /// - protected override bool ShowTooltip => !string.IsNullOrEmpty(TooltipText) && _localBounds.Contains(ref _mousePosition) && !Surface.IsLeftMouseButtonDown && !Surface.IsRightMouseButtonDown && !Surface.IsPrimaryMenuOpened; + protected override bool ShowTooltip => !string.IsNullOrEmpty(TooltipText) && _localBounds.Contains(_mousePosition) && !Surface.IsLeftMouseButtonDown && !Surface.IsRightMouseButtonDown && !Surface.IsPrimaryMenuOpened; /// public override bool OnTestTooltipOverControl(ref Float2 location) { - return _localBounds.Contains(ref location) && ShowTooltip; + return _localBounds.Contains(location) && ShowTooltip; } /// @@ -1150,7 +1150,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override bool CanSelect(ref Float2 location) { - return new Rectangle(Location, DefaultSize).Contains(ref location); + return new Rectangle(Location, DefaultSize).Contains(location); } /// @@ -1230,7 +1230,7 @@ namespace FlaxEditor.Surface.Archetypes /// public override void OnMouseMove(Float2 location) { - _isMouseInConnectingBounds = IsMouseOver && _localBounds.MakeExpanded(ConnectingBounds).Contains(ref location); // Inner area for connecting, outer area for moving + _isMouseInConnectingBounds = IsMouseOver && _localBounds.MakeExpanded(ConnectingBounds).Contains(location); // Inner area for connecting, outer area for moving if (!_isMouseInConnectingBounds && !_isMouseDown) Cursor = CursorType.SizeAll; else diff --git a/Source/Editor/Surface/Elements/OutputBox.cs b/Source/Editor/Surface/Elements/OutputBox.cs index 7e271fef0..421afae77 100644 --- a/Source/Editor/Surface/Elements/OutputBox.cs +++ b/Source/Editor/Surface/Elements/OutputBox.cs @@ -156,7 +156,7 @@ namespace FlaxEditor.Surface.Elements Bezier(ref offsetStart, ref control1, ref control2, ref offsetEnd, t, out p); // Maybe it would be reasonable to return the point? - CollisionsHelper.ClosestPointPointLine(ref point, ref oldp, ref p, out var result); + CollisionsHelper.ClosestPointPointLine(point, oldp, p, out var result); if (Float2.DistanceSquared(point, result) <= squaredDistance) { return true; @@ -167,12 +167,12 @@ namespace FlaxEditor.Surface.Elements private static void Bezier(ref Float2 p0, ref Float2 p1, ref Float2 p2, ref Float2 p3, float alpha, out Float2 result) { - Float2.Lerp(ref p0, ref p1, alpha, out var p01); - Float2.Lerp(ref p1, ref p2, alpha, out var p12); - Float2.Lerp(ref p2, ref p3, alpha, out var p23); - Float2.Lerp(ref p01, ref p12, alpha, out var p012); - Float2.Lerp(ref p12, ref p23, alpha, out var p123); - Float2.Lerp(ref p012, ref p123, alpha, out result); + Float2.Lerp(p0, p1, alpha, out var p01); + Float2.Lerp(p1, p2, alpha, out var p12); + Float2.Lerp(p2, p3, alpha, out var p23); + Float2.Lerp(p01, p12, alpha, out var p012); + Float2.Lerp(p12, p23, alpha, out var p123); + Float2.Lerp(p012, p123, alpha, out result); } /// diff --git a/Source/Editor/Surface/SurfaceComment.cs b/Source/Editor/Surface/SurfaceComment.cs index 10e9fc776..63231d2fa 100644 --- a/Source/Editor/Surface/SurfaceComment.cs +++ b/Source/Editor/Surface/SurfaceComment.cs @@ -146,13 +146,13 @@ namespace FlaxEditor.Surface /// public override bool CanSelect(ref Float2 location) { - return _headerRect.MakeOffsetted(Location).Contains(ref location) && !_resizeButtonRect.MakeOffsetted(Location).Contains(ref location); + return _headerRect.MakeOffsetted(Location).Contains(location) && !_resizeButtonRect.MakeOffsetted(Location).Contains(location); } /// public override bool IsSelectionIntersecting(ref Rectangle selectionRect) { - return _headerRect.MakeOffsetted(Location).Intersects(ref selectionRect); + return _headerRect.MakeOffsetted(Location).Intersects(selectionRect); } /// @@ -287,7 +287,7 @@ namespace FlaxEditor.Surface /// public override bool ContainsPoint(ref Float2 location, bool precise) { - return _headerRect.Contains(ref location) || _resizeButtonRect.Contains(ref location); + return _headerRect.Contains(location) || _resizeButtonRect.Contains(location); } /// @@ -297,7 +297,7 @@ namespace FlaxEditor.Surface return true; // Check if can start resizing - if (button == MouseButton.Left && _resizeButtonRect.Contains(ref location) && Surface.CanEdit) + if (button == MouseButton.Left && _resizeButtonRect.Contains(location) && Surface.CanEdit) { // Start sliding _isResizing = true; @@ -336,7 +336,7 @@ namespace FlaxEditor.Surface return true; // Rename - if (_headerRect.Contains(ref location) && Surface.CanEdit) + if (_headerRect.Contains(location) && Surface.CanEdit) { StartRenaming(); return true; @@ -404,14 +404,14 @@ namespace FlaxEditor.Surface return true; // Close - if (_closeButtonRect.Contains(ref location) && Surface.CanEdit) + if (_closeButtonRect.Contains(location) && Surface.CanEdit) { Surface.Delete(this); return true; } // Color - if (_colorButtonRect.Contains(ref location) && Surface.CanEdit) + if (_colorButtonRect.Contains(location) && Surface.CanEdit) { ColorValueBox.ShowPickColorDialog?.Invoke(this, Color, OnColorChanged); return true; diff --git a/Source/Editor/Surface/SurfaceControl.cs b/Source/Editor/Surface/SurfaceControl.cs index ce5b17d86..63814fd3d 100644 --- a/Source/Editor/Surface/SurfaceControl.cs +++ b/Source/Editor/Surface/SurfaceControl.cs @@ -93,7 +93,7 @@ namespace FlaxEditor.Surface /// true if the selection rectangle is intersecting with the selectable parts of the control ; otherwise, false. public virtual bool IsSelectionIntersecting(ref Rectangle selectionRect) { - return Bounds.Intersects(ref selectionRect); + return Bounds.Intersects(selectionRect); } /// diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs index 6312bd68d..e6ef7a57b 100644 --- a/Source/Editor/Surface/SurfaceNode.cs +++ b/Source/Editor/Surface/SurfaceNode.cs @@ -868,7 +868,7 @@ namespace FlaxEditor.Surface } /// - protected override bool ShowTooltip => base.ShowTooltip && _headerRect.Contains(ref _mousePosition) && !Surface.IsLeftMouseButtonDown && !Surface.IsRightMouseButtonDown && !Surface.IsPrimaryMenuOpened; + protected override bool ShowTooltip => base.ShowTooltip && _headerRect.Contains(_mousePosition) && !Surface.IsLeftMouseButtonDown && !Surface.IsRightMouseButtonDown && !Surface.IsPrimaryMenuOpened; /// public override bool OnShowTooltip(out string text, out Float2 location, out Rectangle area) @@ -898,13 +898,13 @@ namespace FlaxEditor.Surface /// public override bool OnTestTooltipOverControl(ref Float2 location) { - return _headerRect.Contains(ref location) && ShowTooltip && !Surface.IsConnecting && !Surface.IsSelecting; + return _headerRect.Contains(location) && ShowTooltip && !Surface.IsConnecting && !Surface.IsSelecting; } /// public override bool CanSelect(ref Float2 location) { - return _headerRect.MakeOffsetted(Location).Contains(ref location); + return _headerRect.MakeOffsetted(Location).Contains(location); } /// @@ -1056,7 +1056,7 @@ namespace FlaxEditor.Surface // Header var headerColor = style.BackgroundHighlighted; - if (_headerRect.Contains(ref _mousePosition) && !Surface.IsConnecting && !Surface.IsSelecting) + if (_headerRect.Contains(_mousePosition) && !Surface.IsConnecting && !Surface.IsSelecting) headerColor *= 1.07f; Render2D.FillRectangle(_headerRect, headerColor); Render2D.DrawText(style.FontLarge, Title, _headerRect, style.Foreground, TextAlignment.Center, TextAlignment.Center); @@ -1099,7 +1099,7 @@ namespace FlaxEditor.Surface if (base.OnMouseDown(location, button)) return true; - if (button == MouseButton.Left && (Archetype.Flags & NodeFlags.NoCloseButton) == 0 && _closeButtonRect.Contains(ref location)) + if (button == MouseButton.Left && (Archetype.Flags & NodeFlags.NoCloseButton) == 0 && _closeButtonRect.Contains(location)) return true; if (button == MouseButton.Right) mouseDownMousePosition = Input.Mouse.Position; @@ -1115,7 +1115,7 @@ namespace FlaxEditor.Surface // Close/ delete bool canDelete = !Surface.IsConnecting && !Surface.WasSelecting && !Surface.WasMovingSelection; - if (button == MouseButton.Left && canDelete && (Archetype.Flags & NodeFlags.NoCloseButton) == 0 && _closeButtonRect.Contains(ref location)) + if (button == MouseButton.Left && canDelete && (Archetype.Flags & NodeFlags.NoCloseButton) == 0 && _closeButtonRect.Contains(location)) { Surface.Delete(this); return true; diff --git a/Source/Editor/Surface/SurfaceRootControl.cs b/Source/Editor/Surface/SurfaceRootControl.cs index eb2b4575a..c61128c84 100644 --- a/Source/Editor/Surface/SurfaceRootControl.cs +++ b/Source/Editor/Surface/SurfaceRootControl.cs @@ -74,9 +74,9 @@ namespace FlaxEditor.Surface var child = _children[i]; if (!(child is SurfaceComment) && 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(); diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 7c2cb23ad..e0b070434 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -502,7 +502,7 @@ namespace FlaxEditor.Surface /// public override bool OnMouseDown(Float2 location, MouseButton button) { - if (button == MouseButton.Left && _arrangeButtonRect.Contains(ref location)) + if (button == MouseButton.Left && _arrangeButtonRect.Contains(location)) { _arrangeButtonInUse = true; Focus(); diff --git a/Source/Editor/Tools/ClothPainting.cs b/Source/Editor/Tools/ClothPainting.cs index 223c32750..95eba02a0 100644 --- a/Source/Editor/Tools/ClothPainting.cs +++ b/Source/Editor/Tools/ClothPainting.cs @@ -191,7 +191,7 @@ namespace FlaxEngine.Tools for (int i = 0; i < clothParticles.Length; i++) { var pos = instanceTransform.LocalToWorld(clothParticles[i]); - var dst = Vector3.Distance(ref pos, ref brushSphere.Center); + var dst = Vector3.Distance(pos, brushSphere.Center); if (dst > brushSphere.Radius) continue; float strength = _gizmoMode.BrushStrength * Mathf.Lerp(1.0f, 1.0f - (float)dst / (float)brushSphere.Radius, _gizmoMode.BrushFalloff); diff --git a/Source/Editor/Tools/Foliage/EditFoliageGizmo.cs b/Source/Editor/Tools/Foliage/EditFoliageGizmo.cs index 73a0b0530..d7bd56e92 100644 --- a/Source/Editor/Tools/Foliage/EditFoliageGizmo.cs +++ b/Source/Editor/Tools/Foliage/EditFoliageGizmo.cs @@ -104,7 +104,7 @@ namespace FlaxEditor.Tools.Foliage if (foliage && instanceIndex >= 0 && instanceIndex < foliage.InstancesCount) { var instance = foliage.GetInstance(instanceIndex); - BoundingBox.FromSphere(ref instance.Bounds, out bounds); + BoundingBox.FromSphere(instance.Bounds, out bounds); } } @@ -155,8 +155,8 @@ namespace FlaxEditor.Tools.Foliage } else { - Matrix.RotationQuaternion(ref trans.Orientation, out var transWorld); - Matrix.RotationQuaternion(ref rotationDelta, out var deltaWorld); + Matrix.RotationQuaternion(trans.Orientation, out var transWorld); + Matrix.RotationQuaternion(rotationDelta, out var deltaWorld); Matrix world = transWorld * Matrix.Translation(pivotOffset) * deltaWorld * Matrix.Translation(-pivotOffset); trans.SetRotation(ref world); trans.Translation += world.TranslationVector; diff --git a/Source/Editor/Tools/Terrain/Brushes/CircleBrush.cs b/Source/Editor/Tools/Terrain/Brushes/CircleBrush.cs index 4adb2ed82..0f26ed6a2 100644 --- a/Source/Editor/Tools/Terrain/Brushes/CircleBrush.cs +++ b/Source/Editor/Tools/Terrain/Brushes/CircleBrush.cs @@ -117,7 +117,7 @@ namespace FlaxEditor.Tools.Terrain.Brushes /// public override float Sample(ref Vector3 brushPosition, ref Vector3 samplePosition) { - Vector3.DistanceXZ(ref brushPosition, ref samplePosition, out var distanceXZ); + Vector3.DistanceXZ(brushPosition, samplePosition, out var distanceXZ); float distance = (float)distanceXZ; float halfSize = Size * 0.5f; float falloff = halfSize * Falloff; diff --git a/Source/Editor/Tools/Terrain/Paint/Mode.cs b/Source/Editor/Tools/Terrain/Paint/Mode.cs index 82858467c..767593dda 100644 --- a/Source/Editor/Tools/Terrain/Paint/Mode.cs +++ b/Source/Editor/Tools/Terrain/Paint/Mode.cs @@ -93,7 +93,7 @@ namespace FlaxEditor.Tools.Terrain.Paint var brushBounds = gizmo.CursorBrushBounds; terrain.GetLocalToWorldMatrix(out p.TerrainWorld); terrain.GetWorldToLocalMatrix(out var terrainInvWorld); - BoundingBox.Transform(ref brushBounds, ref terrainInvWorld, out var brushBoundsLocal); + BoundingBox.Transform(brushBounds, terrainInvWorld, out var brushBoundsLocal); // TODO: try caching brush weights before apply to reduce complexity and batch brush sampling diff --git a/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs b/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs index 075f5e2ee..42422ec0b 100644 --- a/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs +++ b/Source/Editor/Tools/Terrain/Paint/SingleLayerMode.cs @@ -86,7 +86,7 @@ namespace FlaxEditor.Tools.Terrain.Paint var src = (Color)p.SourceData[zz * p.HeightmapSize + xx]; var samplePositionLocal = p.PatchPositionLocal + new Vector3(xx * FlaxEngine.Terrain.UnitsPerVertex, 0, zz * FlaxEngine.Terrain.UnitsPerVertex); - Vector3.Transform(ref samplePositionLocal, ref p.TerrainWorld, out Vector3 samplePositionWorld); + Vector3.Transform(samplePositionLocal, p.TerrainWorld, out Vector3 samplePositionWorld); var sample = Mathf.Saturate(p.Brush.Sample(ref brushPosition, ref samplePositionWorld)); var paintAmount = sample * strength; diff --git a/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs index 3481416e2..fdb92e195 100644 --- a/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs +++ b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs @@ -314,7 +314,7 @@ namespace FlaxEditor.Tools.Terrain for (int patchIndex = 0; patchIndex < patchesCount; patchIndex++) { terrain.GetPatchBounds(patchIndex, out BoundingBox tmp); - if (!tmp.Intersects(ref brushBounds)) + if (!tmp.Intersects(brushBounds)) continue; terrain.GetPatchCoord(patchIndex, out var patchCoord); @@ -323,7 +323,7 @@ namespace FlaxEditor.Tools.Terrain for (int chunkIndex = 0; chunkIndex < FlaxEngine.Terrain.PatchChunksCount; chunkIndex++) { terrain.GetChunkBounds(patchIndex, chunkIndex, out tmp); - if (!tmp.Intersects(ref brushBounds)) + if (!tmp.Intersects(brushBounds)) continue; var chunkCoord = new Int2(chunkIndex % FlaxEngine.Terrain.PatchEdgeChunksCount, chunkIndex / FlaxEngine.Terrain.PatchEdgeChunksCount); diff --git a/Source/Editor/Tools/Terrain/Sculpt/FlattenMode.cs b/Source/Editor/Tools/Terrain/Sculpt/FlattenMode.cs index c75b758fa..955bdeccb 100644 --- a/Source/Editor/Tools/Terrain/Sculpt/FlattenMode.cs +++ b/Source/Editor/Tools/Terrain/Sculpt/FlattenMode.cs @@ -44,7 +44,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt var sourceHeight = p.SourceHeightMap[zz * p.HeightmapSize + xx]; var samplePositionLocal = p.PatchPositionLocal + new Vector3(xx * FlaxEngine.Terrain.UnitsPerVertex, sourceHeight, zz * FlaxEngine.Terrain.UnitsPerVertex); - Vector3.Transform(ref samplePositionLocal, ref p.TerrainWorld, out Vector3 samplePositionWorld); + Vector3.Transform(samplePositionLocal, p.TerrainWorld, out Vector3 samplePositionWorld); var paintAmount = p.Brush.Sample(ref brushPosition, ref samplePositionWorld) * strength; diff --git a/Source/Editor/Tools/Terrain/Sculpt/HolesMode.cs b/Source/Editor/Tools/Terrain/Sculpt/HolesMode.cs index 0c356d84a..c00f16727 100644 --- a/Source/Editor/Tools/Terrain/Sculpt/HolesMode.cs +++ b/Source/Editor/Tools/Terrain/Sculpt/HolesMode.cs @@ -43,7 +43,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt var sourceMask = p.SourceHolesMask[zz * p.HeightmapSize + xx] != 0 ? 1.0f : 0.0f; var samplePositionLocal = p.PatchPositionLocal + new Vector3(xx * FlaxEngine.Terrain.UnitsPerVertex, 0, zz * FlaxEngine.Terrain.UnitsPerVertex); - Vector3.Transform(ref samplePositionLocal, ref p.TerrainWorld, out Vector3 samplePositionWorld); + Vector3.Transform(samplePositionLocal, p.TerrainWorld, out Vector3 samplePositionWorld); samplePositionWorld.Y = brushPosition.Y; var paintAmount = p.Brush.Sample(ref brushPosition, ref samplePositionWorld); diff --git a/Source/Editor/Tools/Terrain/Sculpt/Mode.cs b/Source/Editor/Tools/Terrain/Sculpt/Mode.cs index dc98319a6..0a801f005 100644 --- a/Source/Editor/Tools/Terrain/Sculpt/Mode.cs +++ b/Source/Editor/Tools/Terrain/Sculpt/Mode.cs @@ -80,7 +80,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt var brushBounds = gizmo.CursorBrushBounds; terrain.GetLocalToWorldMatrix(out var terrainWorld); terrain.GetWorldToLocalMatrix(out var terrainInvWorld); - BoundingBox.Transform(ref brushBounds, ref terrainInvWorld, out var brushBoundsLocal); + BoundingBox.Transform(brushBounds, terrainInvWorld, out var brushBoundsLocal); // TODO: try caching brush weights before apply to reduce complexity and batch brush sampling diff --git a/Source/Editor/Tools/Terrain/Sculpt/NoiseMode.cs b/Source/Editor/Tools/Terrain/Sculpt/NoiseMode.cs index c45e283f6..1b095c3df 100644 --- a/Source/Editor/Tools/Terrain/Sculpt/NoiseMode.cs +++ b/Source/Editor/Tools/Terrain/Sculpt/NoiseMode.cs @@ -49,7 +49,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt var sourceHeight = p.SourceHeightMap[zz * p.HeightmapSize + xx]; var samplePositionLocal = p.PatchPositionLocal + new Vector3(xx * FlaxEngine.Terrain.UnitsPerVertex, sourceHeight, zz * FlaxEngine.Terrain.UnitsPerVertex); - Vector3.Transform(ref samplePositionLocal, ref p.TerrainWorld, out Vector3 samplePositionWorld); + Vector3.Transform(samplePositionLocal, p.TerrainWorld, out Vector3 samplePositionWorld); var noiseSample = noise.Sample(xx + patchOffset.X, zz + patchOffset.Y); var paintAmount = p.Brush.Sample(ref brushPosition, ref samplePositionWorld); diff --git a/Source/Editor/Tools/Terrain/Sculpt/SculptMode.cs b/Source/Editor/Tools/Terrain/Sculpt/SculptMode.cs index 640a7b45e..e41058085 100644 --- a/Source/Editor/Tools/Terrain/Sculpt/SculptMode.cs +++ b/Source/Editor/Tools/Terrain/Sculpt/SculptMode.cs @@ -31,7 +31,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt var sourceHeight = p.SourceHeightMap[zz * p.HeightmapSize + xx]; var samplePositionLocal = p.PatchPositionLocal + new Vector3(xx * FlaxEngine.Terrain.UnitsPerVertex, sourceHeight, zz * FlaxEngine.Terrain.UnitsPerVertex); - Vector3.Transform(ref samplePositionLocal, ref p.TerrainWorld, out Vector3 samplePositionWorld); + Vector3.Transform(samplePositionLocal, p.TerrainWorld, out Vector3 samplePositionWorld); var paintAmount = p.Brush.Sample(ref brushPosition, ref samplePositionWorld); diff --git a/Source/Editor/Tools/Terrain/Sculpt/SmoothMode.cs b/Source/Editor/Tools/Terrain/Sculpt/SmoothMode.cs index 670335c21..d6872571e 100644 --- a/Source/Editor/Tools/Terrain/Sculpt/SmoothMode.cs +++ b/Source/Editor/Tools/Terrain/Sculpt/SmoothMode.cs @@ -93,7 +93,7 @@ namespace FlaxEditor.Tools.Terrain.Sculpt // Calculate brush influence at the current position var samplePositionLocal = patch.PatchPositionLocal + new Vector3(localCoordX * FlaxEngine.Terrain.UnitsPerVertex, coordHeight, localCoordY * FlaxEngine.Terrain.UnitsPerVertex); - Vector3.Transform(ref samplePositionLocal, ref patch.TerrainWorld, out Vector3 samplePositionWorld); + Vector3.Transform(samplePositionLocal, patch.TerrainWorld, out Vector3 samplePositionWorld); var paintAmount = patch.Brush.Sample(ref brushPosition, ref samplePositionWorld) * strength; if (paintAmount == 0) diff --git a/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs b/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs index a0d5d0c88..71560ada9 100644 --- a/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs +++ b/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs @@ -333,7 +333,7 @@ namespace FlaxEditor.Tools.Terrain for (int patchIndex = 0; patchIndex < patchesCount; patchIndex++) { terrain.GetPatchBounds(patchIndex, out BoundingBox tmp); - if (!tmp.Intersects(ref brushBounds)) + if (!tmp.Intersects(brushBounds)) continue; terrain.GetPatchCoord(patchIndex, out var patchCoord); @@ -342,7 +342,7 @@ namespace FlaxEditor.Tools.Terrain for (int chunkIndex = 0; chunkIndex < FlaxEngine.Terrain.PatchChunksCount; chunkIndex++) { terrain.GetChunkBounds(patchIndex, chunkIndex, out tmp); - if (!tmp.Intersects(ref brushBounds)) + if (!tmp.Intersects(brushBounds)) continue; var chunkCoord = new Int2(chunkIndex % FlaxEngine.Terrain.PatchEdgeChunksCount, chunkIndex / FlaxEngine.Terrain.PatchEdgeChunksCount); diff --git a/Source/Editor/Tools/VertexPainting.cs b/Source/Editor/Tools/VertexPainting.cs index 59dbd83c2..2fc36c7cb 100644 --- a/Source/Editor/Tools/VertexPainting.cs +++ b/Source/Editor/Tools/VertexPainting.cs @@ -440,7 +440,7 @@ namespace FlaxEditor.Tools for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) { var pos = instanceTransform.LocalToWorld(positionStream.GetFloat3(vertexIndex)); - var dst = Vector3.Distance(ref pos, ref brushSphere.Center); + var dst = Vector3.Distance(pos, brushSphere.Center); if (dst > brushSphere.Radius) continue; float strength = _gizmoMode.BrushStrength * Mathf.Lerp(1.0f, 1.0f - (float)dst / (float)brushSphere.Radius, _gizmoMode.BrushFalloff); @@ -603,7 +603,7 @@ namespace FlaxEditor.Tools for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) { var pos = instanceTransform.LocalToWorld(positionStream.GetFloat3(vertexIndex)); - if (brushSphere.Contains(ref pos) == ContainmentType.Disjoint) + if (brushSphere.Contains(pos) == ContainmentType.Disjoint) continue; Matrix transform = modelScaleMatrix * Matrix.Translation(pos - viewOrigin); _brushModel.Draw(renderContext, _verticesPreviewMaterial, transform); diff --git a/Source/Editor/Undo/Actions/TransformObjectsAction.cs b/Source/Editor/Undo/Actions/TransformObjectsAction.cs index ebed61174..f6da0ec54 100644 --- a/Source/Editor/Undo/Actions/TransformObjectsAction.cs +++ b/Source/Editor/Undo/Actions/TransformObjectsAction.cs @@ -119,7 +119,7 @@ namespace FlaxEditor if (!isPlayMode && options.General.AutoRebuildNavMesh && data.Scene != null) { // Handle simple case where objects were moved just a little and use one navmesh build request to improve performance - if (data.BeforeBounds.Intersects(ref data.AfterBounds)) + if (data.BeforeBounds.Intersects(data.AfterBounds)) { Navigation.BuildNavMesh(data.Scene, BoundingBox.Merge(data.BeforeBounds, data.AfterBounds), options.General.AutoRebuildNavMeshTimeoutMs); } diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index ea55edc0b..74aeebd6c 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1041,7 +1041,7 @@ namespace FlaxEditor.Utilities Vector3 up = Vector3.Up * orientation; Matrix world = Matrix.CreateWorld(min + vec * 0.5f, dir, up); world.Decompose(out box.Transformation); - Matrix.Invert(ref world, out Matrix invWorld); + Matrix.Invert(world, out Matrix invWorld); Vector3 vecLocal = Vector3.TransformNormal(vec * 0.5f, invWorld); box.Extents.X = margin; box.Extents.Y = margin; @@ -1062,24 +1062,24 @@ namespace FlaxEditor.Utilities var corners = stackalloc Vector3[8]; box.GetCorners(corners); - var minDistance = Vector3.DistanceSquared(ref viewPosition, ref corners[0]); + var minDistance = Vector3.DistanceSquared(viewPosition, corners[0]); for (int i = 1; i < 8; i++) - minDistance = Mathf.Min(minDistance, Vector3.DistanceSquared(ref viewPosition, ref corners[i])); + minDistance = Mathf.Min(minDistance, Vector3.DistanceSquared(viewPosition, corners[i])); minDistance = Mathf.Sqrt(minDistance); var margin = Mathf.Clamp(minDistance / 80.0f, 0.1f, 100.0f); - if (GetWriteBox(ref corners[0], ref corners[1], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[0], ref corners[3], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[0], ref corners[4], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[1], ref corners[2], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[1], ref corners[5], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[2], ref corners[3], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[2], ref corners[6], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[3], ref corners[7], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[4], ref corners[5], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[4], ref corners[7], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[5], ref corners[6], margin).Intersects(ref ray, out distance) || - GetWriteBox(ref corners[6], ref corners[7], margin).Intersects(ref ray, out distance)) + if (GetWriteBox(ref corners[0], ref corners[1], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[0], ref corners[3], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[0], ref corners[4], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[1], ref corners[2], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[1], ref corners[5], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[2], ref corners[3], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[2], ref corners[6], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[3], ref corners[7], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[4], ref corners[5], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[4], ref corners[7], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[5], ref corners[6], margin).Intersects(ray, out distance) || + GetWriteBox(ref corners[6], ref corners[7], margin).Intersects(ray, out distance)) return true; distance = 0; diff --git a/Source/Editor/Viewport/Cameras/FPSCamera.cs b/Source/Editor/Viewport/Cameras/FPSCamera.cs index 26e996c41..af13a87bc 100644 --- a/Source/Editor/Viewport/Cameras/FPSCamera.cs +++ b/Source/Editor/Viewport/Cameras/FPSCamera.cs @@ -177,7 +177,7 @@ namespace FlaxEditor.Viewport.Cameras // Dolly if (input.IsPanning || input.IsMoving || input.IsRotating) { - Vector3.Transform(ref moveDelta, ref rotation, out Vector3 move); + Vector3.Transform(moveDelta, rotation, out Vector3 move); position += move; } @@ -239,7 +239,7 @@ namespace FlaxEditor.Viewport.Cameras Viewport.Pitch = pitch; if (input.IsOrbiting) { - float orbitRadius = Mathf.Max((float)Vector3.Distance(ref position, ref TargetPoint), 0.0001f); + float orbitRadius = Mathf.Max((float)Vector3.Distance(position, TargetPoint), 0.0001f); Vector3 localPosition = Viewport.ViewDirection * (-1 * orbitRadius); Viewport.ViewPosition = TargetPoint + localPosition; } diff --git a/Source/Editor/Viewport/Cameras/ViewportCamera.cs b/Source/Editor/Viewport/Cameras/ViewportCamera.cs index 977ff2309..7cd7cebb6 100644 --- a/Source/Editor/Viewport/Cameras/ViewportCamera.cs +++ b/Source/Editor/Viewport/Cameras/ViewportCamera.cs @@ -92,7 +92,7 @@ namespace FlaxEditor.Viewport.Cameras for (int i = 0; i < selection.Count; i++) { selection[i].GetEditorSphere(out var sphere); - BoundingSphere.Merge(ref mergesSphere, ref sphere, out mergesSphere); + BoundingSphere.Merge(mergesSphere, sphere, out mergesSphere); } if (mergesSphere == BoundingSphere.Empty) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index 5fb1c4657..5303cc9ba 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -354,8 +354,8 @@ namespace FlaxEditor.Viewport Float3 position = ViewPosition - viewOrigin; CreateViewMatrix(position, out var view); CreateProjectionMatrix(out var projection); - Matrix.Multiply(ref view, ref projection, out var viewProjection); - return new BoundingFrustum(ref viewProjection); + Matrix.Multiply(view, projection, out var viewProjection); + return new BoundingFrustum(viewProjection); } } @@ -1444,7 +1444,7 @@ namespace FlaxEditor.Viewport var target = position + direction; var right = Mathf.Abs(Float3.Dot(direction, Float3.Up)) < 1.0f - Mathf.Epsilon ? Float3.Normalize(Float3.Cross(Float3.Up, direction)) : Float3.Forward; var up = Float3.Normalize(Float3.Cross(direction, right)); - Matrix.LookAt(ref position, ref target, ref up, out result); + Matrix.LookAt(position, target, up, out result); } /// @@ -1490,14 +1490,14 @@ namespace FlaxEditor.Viewport // Create view frustum CreateProjectionMatrix(out var p); CreateViewMatrix(position, out var v); - Matrix.Multiply(ref v, ref p, out var ivp); + Matrix.Multiply(v, p, out var ivp); ivp.Invert(); // Create near and far points var nearPoint = new Vector3(mousePosition, _nearPlane); var farPoint = new Vector3(mousePosition, _farPlane); - viewport.Unproject(ref nearPoint, ref ivp, out nearPoint); - viewport.Unproject(ref farPoint, ref ivp, out farPoint); + viewport.Unproject(nearPoint, ivp, out nearPoint); + viewport.Unproject(farPoint, ivp, out farPoint); return new Ray(nearPoint + viewOrigin, Vector3.Normalize(farPoint - nearPoint)); } @@ -1517,8 +1517,8 @@ namespace FlaxEditor.Viewport Float3 position = ViewPosition - viewOrigin; CreateProjectionMatrix(out var p); CreateViewMatrix(position, out var v); - Matrix.Multiply(ref v, ref p, out var vp); - viewport.Project(ref worldSpaceLocation, ref vp, out var projected); + Matrix.Multiply(v, p, out var vp); + viewport.Project(worldSpaceLocation, vp, out var projected); viewportSpaceLocation = new Float2((float)projected.X, (float)projected.Y); } diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs index 491af6fdb..86c92ac78 100644 --- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs +++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs @@ -278,7 +278,7 @@ namespace FlaxEditor.Viewport for (int i = 0; i < selection.Count; i++) { selection[i].GetEditorSphere(out var sphere); - BoundingSphere.Merge(ref selectionBounds, ref sphere, out selectionBounds); + BoundingSphere.Merge(selectionBounds, sphere, out selectionBounds); } if (ContainsFocus) @@ -470,8 +470,8 @@ namespace FlaxEditor.Viewport } else { - Matrix.RotationQuaternion(ref trans.Orientation, out var transWorld); - Matrix.RotationQuaternion(ref rotationDelta, out var deltaWorld); + Matrix.RotationQuaternion(trans.Orientation, out var transWorld); + Matrix.RotationQuaternion(rotationDelta, out var deltaWorld); Matrix world = transWorld * Matrix.Translation(pivotOffset) * deltaWorld * Matrix.Translation(-pivotOffset); trans.SetRotation(ref world); trans.Translation += world.TranslationVector; @@ -567,8 +567,8 @@ namespace FlaxEditor.Viewport } else { - Matrix.RotationQuaternion(ref trans.Orientation, out var transWorld); - Matrix.RotationQuaternion(ref rotationDelta, out var deltaWorld); + Matrix.RotationQuaternion(trans.Orientation, out var transWorld); + Matrix.RotationQuaternion(rotationDelta, out var deltaWorld); Matrix world = transWorld * Matrix.Translation(pivotOffset) * deltaWorld * Matrix.Translation(-pivotOffset); trans.SetRotation(ref world); trans.Translation += world.TranslationVector; @@ -636,7 +636,7 @@ namespace FlaxEditor.Viewport protected override void OnLeftMouseButtonUp() { // Skip if was controlling mouse or mouse is not over the area - if (_prevInput.IsControllingMouse || !Bounds.Contains(ref _viewMousePos)) + if (_prevInput.IsControllingMouse || !Bounds.Contains(_viewMousePos)) return; // Select rubberbanded rect actor nodes or pick with gizmo @@ -659,7 +659,7 @@ namespace FlaxEditor.Viewport return true; // Handle mouse going up when using rubber band with mouse capture that click up outside the view - if (button == MouseButton.Left && !new Rectangle(Float2.Zero, Size).Contains(ref location)) + if (button == MouseButton.Left && !new Rectangle(Float2.Zero, Size).Contains(location)) { _rubberBandSelector.ReleaseRubberBandSelection(); return true; diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index a4e743f8e..920e2ede0 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -517,8 +517,8 @@ namespace FlaxEditor.Viewport } else { - Matrix.RotationQuaternion(ref trans.Orientation, out var transWorld); - Matrix.RotationQuaternion(ref rotationDelta, out var deltaWorld); + Matrix.RotationQuaternion(trans.Orientation, out var transWorld); + Matrix.RotationQuaternion(rotationDelta, out var deltaWorld); Matrix world = transWorld * Matrix.Translation(pivotOffset) * deltaWorld * Matrix.Translation(-pivotOffset); trans.SetRotation(ref world); trans.Translation += world.TranslationVector; @@ -540,7 +540,7 @@ namespace FlaxEditor.Viewport protected override void OnLeftMouseButtonUp() { // Skip if was controlling mouse or mouse is not over the area - if (_prevInput.IsControllingMouse || !Bounds.Contains(ref _viewMousePos)) + if (_prevInput.IsControllingMouse || !Bounds.Contains(_viewMousePos)) return; if (TransformGizmo.IsActive) diff --git a/Source/Editor/Viewport/Previews/ModelPreview.cs b/Source/Editor/Viewport/Previews/ModelPreview.cs index ae0424da3..bc1c6e958 100644 --- a/Source/Editor/Viewport/Previews/ModelPreview.cs +++ b/Source/Editor/Viewport/Previews/ModelPreview.cs @@ -379,7 +379,7 @@ namespace FlaxEditor.Viewport.Previews float screenMultiple = 0.5f * Mathf.Max(projectionMatrix.M11, projectionMatrix.M22); var sphere = PreviewActor.Sphere; var viewOrigin = ViewPosition; - var distSqr = Vector3.DistanceSquared(ref sphere.Center, ref viewOrigin); + var distSqr = Vector3.DistanceSquared(sphere.Center, viewOrigin); var screenRadiusSquared = Mathf.Square(screenMultiple * sphere.Radius) / Mathf.Max(1.0f, distSqr); screenSize = Mathf.Sqrt((float)screenRadiusSquared) * 2.0f; diff --git a/Source/Editor/Viewport/Previews/SkinnedModelPreview.cs b/Source/Editor/Viewport/Previews/SkinnedModelPreview.cs index 3048d0c78..fc85121aa 100644 --- a/Source/Editor/Viewport/Previews/SkinnedModelPreview.cs +++ b/Source/Editor/Viewport/Previews/SkinnedModelPreview.cs @@ -95,7 +95,7 @@ namespace FlaxEditor.Viewport.Previews float screenMultiple = 0.5f * Mathf.Max(projectionMatrix.M11, projectionMatrix.M22); var sphere = PreviewActor.Sphere; var viewOrigin = ViewPosition; - var distSqr = Vector3.DistanceSquared(ref sphere.Center, ref viewOrigin); + var distSqr = Vector3.DistanceSquared(sphere.Center, viewOrigin); var screenRadiusSquared = Mathf.Square(screenMultiple * sphere.Radius) / Mathf.Max(1.0f, distSqr); screenSize = Mathf.Sqrt((float)screenRadiusSquared) * 2.0f; diff --git a/Source/Editor/Viewport/ViewportDraggingHelper.cs b/Source/Editor/Viewport/ViewportDraggingHelper.cs index ed1c3c6ea..1a4a484d9 100644 --- a/Source/Editor/Viewport/ViewportDraggingHelper.cs +++ b/Source/Editor/Viewport/ViewportDraggingHelper.cs @@ -153,7 +153,7 @@ namespace FlaxEditor.Viewport hitLocation = ray.Position + ray.Direction * closest; hitNormal = normal; } - else if (girdGizmo != null && girdGizmo.Enabled && CollisionsHelper.RayIntersectsPlane(ref ray, ref gridPlane, out closest) && closest < 4000.0f) + else if (girdGizmo != null && girdGizmo.Enabled && CollisionsHelper.RayIntersectsPlane(ray, gridPlane, out closest) && closest < 4000.0f) { // Use grid location hitLocation = ray.Position + ray.Direction * closest; diff --git a/Source/Editor/Windows/Assets/ModelBaseWindow.cs b/Source/Editor/Windows/Assets/ModelBaseWindow.cs index 09b4606c4..957f09875 100644 --- a/Source/Editor/Windows/Assets/ModelBaseWindow.cs +++ b/Source/Editor/Windows/Assets/ModelBaseWindow.cs @@ -664,7 +664,7 @@ namespace FlaxEditor.Windows.Assets Float2 uv2 = texCoordStream.GetFloat2((int)i2) * uvScale; // Don't draw too small triangles - float area = Float2.TriangleArea(ref uv0, ref uv1, ref uv2); + float area = Float2.TriangleArea(uv0, uv1, uv2); if (area > 10.0f) { // Draw triangle diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs index 9f87bc90f..20f1e5814 100644 --- a/Source/Editor/Windows/GameWindow.cs +++ b/Source/Editor/Windows/GameWindow.cs @@ -41,7 +41,7 @@ namespace FlaxEditor.Windows // Draw children with scale var scaling = new Float3(ContentScale, ContentScale, 1); - Matrix3x3.Scaling(ref scaling, out Matrix3x3 scale); + Matrix3x3.Scaling(scaling, out Matrix3x3 scale); Render2D.PushTransform(scale); if (ClipChildren) { diff --git a/Source/Engine/Animations/Curve.cs b/Source/Engine/Animations/Curve.cs index 32f8852c7..2aff9a853 100644 --- a/Source/Engine/Animations/Curve.cs +++ b/Source/Engine/Animations/Curve.cs @@ -151,17 +151,17 @@ namespace FlaxEngine public void Linear(ref Vector2 a, ref Vector2 b, float alpha, out Vector2 result) { - Vector2.Lerp(ref a, ref b, alpha, out result); + Vector2.Lerp(a, b, alpha, out result); } public void Bezier(ref Vector2 p0, ref Vector2 p1, ref Vector2 p2, ref Vector2 p3, float alpha, out Vector2 result) { - Vector2.Lerp(ref p0, ref p1, alpha, out var p01); - Vector2.Lerp(ref p1, ref p2, alpha, out var p12); - Vector2.Lerp(ref p2, ref p3, alpha, out var p23); - Vector2.Lerp(ref p01, ref p12, alpha, out var p012); - Vector2.Lerp(ref p12, ref p23, alpha, out var p123); - Vector2.Lerp(ref p012, ref p123, alpha, out result); + Vector2.Lerp(p0, p1, alpha, out var p01); + Vector2.Lerp(p1, p2, alpha, out var p12); + Vector2.Lerp(p2, p3, alpha, out var p23); + Vector2.Lerp(p01, p12, alpha, out var p012); + Vector2.Lerp(p12, p23, alpha, out var p123); + Vector2.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Vector3 value, ref Vector3 tangent, float tangentScale, out Vector3 result) @@ -171,17 +171,17 @@ namespace FlaxEngine public void Linear(ref Vector3 a, ref Vector3 b, float alpha, out Vector3 result) { - Vector3.Lerp(ref a, ref b, alpha, out result); + Vector3.Lerp(a, b, alpha, out result); } public void Bezier(ref Vector3 p0, ref Vector3 p1, ref Vector3 p2, ref Vector3 p3, float alpha, out Vector3 result) { - Vector3.Lerp(ref p0, ref p1, alpha, out var p01); - Vector3.Lerp(ref p1, ref p2, alpha, out var p12); - Vector3.Lerp(ref p2, ref p3, alpha, out var p23); - Vector3.Lerp(ref p01, ref p12, alpha, out var p012); - Vector3.Lerp(ref p12, ref p23, alpha, out var p123); - Vector3.Lerp(ref p012, ref p123, alpha, out result); + Vector3.Lerp(p0, p1, alpha, out var p01); + Vector3.Lerp(p1, p2, alpha, out var p12); + Vector3.Lerp(p2, p3, alpha, out var p23); + Vector3.Lerp(p01, p12, alpha, out var p012); + Vector3.Lerp(p12, p23, alpha, out var p123); + Vector3.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Vector4 value, ref Vector4 tangent, float tangentScale, out Vector4 result) @@ -191,17 +191,17 @@ namespace FlaxEngine public void Linear(ref Vector4 a, ref Vector4 b, float alpha, out Vector4 result) { - Vector4.Lerp(ref a, ref b, alpha, out result); + Vector4.Lerp(a, b, alpha, out result); } public void Bezier(ref Vector4 p0, ref Vector4 p1, ref Vector4 p2, ref Vector4 p3, float alpha, out Vector4 result) { - Vector4.Lerp(ref p0, ref p1, alpha, out var p01); - Vector4.Lerp(ref p1, ref p2, alpha, out var p12); - Vector4.Lerp(ref p2, ref p3, alpha, out var p23); - Vector4.Lerp(ref p01, ref p12, alpha, out var p012); - Vector4.Lerp(ref p12, ref p23, alpha, out var p123); - Vector4.Lerp(ref p012, ref p123, alpha, out result); + Vector4.Lerp(p0, p1, alpha, out var p01); + Vector4.Lerp(p1, p2, alpha, out var p12); + Vector4.Lerp(p2, p3, alpha, out var p23); + Vector4.Lerp(p01, p12, alpha, out var p012); + Vector4.Lerp(p12, p23, alpha, out var p123); + Vector4.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Float2 value, ref Float2 tangent, float tangentScale, out Float2 result) @@ -211,17 +211,17 @@ namespace FlaxEngine public void Linear(ref Float2 a, ref Float2 b, float alpha, out Float2 result) { - Float2.Lerp(ref a, ref b, alpha, out result); + Float2.Lerp(a, b, alpha, out result); } public void Bezier(ref Float2 p0, ref Float2 p1, ref Float2 p2, ref Float2 p3, float alpha, out Float2 result) { - Float2.Lerp(ref p0, ref p1, alpha, out var p01); - Float2.Lerp(ref p1, ref p2, alpha, out var p12); - Float2.Lerp(ref p2, ref p3, alpha, out var p23); - Float2.Lerp(ref p01, ref p12, alpha, out var p012); - Float2.Lerp(ref p12, ref p23, alpha, out var p123); - Float2.Lerp(ref p012, ref p123, alpha, out result); + Float2.Lerp(p0, p1, alpha, out var p01); + Float2.Lerp(p1, p2, alpha, out var p12); + Float2.Lerp(p2, p3, alpha, out var p23); + Float2.Lerp(p01, p12, alpha, out var p012); + Float2.Lerp(p12, p23, alpha, out var p123); + Float2.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Float3 value, ref Float3 tangent, float tangentScale, out Float3 result) @@ -231,17 +231,17 @@ namespace FlaxEngine public void Linear(ref Float3 a, ref Float3 b, float alpha, out Float3 result) { - Float3.Lerp(ref a, ref b, alpha, out result); + Float3.Lerp(a, b, alpha, out result); } public void Bezier(ref Float3 p0, ref Float3 p1, ref Float3 p2, ref Float3 p3, float alpha, out Float3 result) { - Float3.Lerp(ref p0, ref p1, alpha, out var p01); - Float3.Lerp(ref p1, ref p2, alpha, out var p12); - Float3.Lerp(ref p2, ref p3, alpha, out var p23); - Float3.Lerp(ref p01, ref p12, alpha, out var p012); - Float3.Lerp(ref p12, ref p23, alpha, out var p123); - Float3.Lerp(ref p012, ref p123, alpha, out result); + Float3.Lerp(p0, p1, alpha, out var p01); + Float3.Lerp(p1, p2, alpha, out var p12); + Float3.Lerp(p2, p3, alpha, out var p23); + Float3.Lerp(p01, p12, alpha, out var p012); + Float3.Lerp(p12, p23, alpha, out var p123); + Float3.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Float4 value, ref Float4 tangent, float tangentScale, out Float4 result) @@ -251,17 +251,17 @@ namespace FlaxEngine public void Linear(ref Float4 a, ref Float4 b, float alpha, out Float4 result) { - Float4.Lerp(ref a, ref b, alpha, out result); + Float4.Lerp(a, b, alpha, out result); } public void Bezier(ref Float4 p0, ref Float4 p1, ref Float4 p2, ref Float4 p3, float alpha, out Float4 result) { - Float4.Lerp(ref p0, ref p1, alpha, out var p01); - Float4.Lerp(ref p1, ref p2, alpha, out var p12); - Float4.Lerp(ref p2, ref p3, alpha, out var p23); - Float4.Lerp(ref p01, ref p12, alpha, out var p012); - Float4.Lerp(ref p12, ref p23, alpha, out var p123); - Float4.Lerp(ref p012, ref p123, alpha, out result); + Float4.Lerp(p0, p1, alpha, out var p01); + Float4.Lerp(p1, p2, alpha, out var p12); + Float4.Lerp(p2, p3, alpha, out var p23); + Float4.Lerp(p01, p12, alpha, out var p012); + Float4.Lerp(p12, p23, alpha, out var p123); + Float4.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Double2 value, ref Double2 tangent, float tangentScale, out Double2 result) @@ -271,17 +271,17 @@ namespace FlaxEngine public void Linear(ref Double2 a, ref Double2 b, float alpha, out Double2 result) { - Double2.Lerp(ref a, ref b, alpha, out result); + Double2.Lerp(a, b, alpha, out result); } public void Bezier(ref Double2 p0, ref Double2 p1, ref Double2 p2, ref Double2 p3, float alpha, out Double2 result) { - Double2.Lerp(ref p0, ref p1, alpha, out var p01); - Double2.Lerp(ref p1, ref p2, alpha, out var p12); - Double2.Lerp(ref p2, ref p3, alpha, out var p23); - Double2.Lerp(ref p01, ref p12, alpha, out var p012); - Double2.Lerp(ref p12, ref p23, alpha, out var p123); - Double2.Lerp(ref p012, ref p123, alpha, out result); + Double2.Lerp(p0, p1, alpha, out var p01); + Double2.Lerp(p1, p2, alpha, out var p12); + Double2.Lerp(p2, p3, alpha, out var p23); + Double2.Lerp(p01, p12, alpha, out var p012); + Double2.Lerp(p12, p23, alpha, out var p123); + Double2.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Double3 value, ref Double3 tangent, float tangentScale, out Double3 result) @@ -291,17 +291,17 @@ namespace FlaxEngine public void Linear(ref Double3 a, ref Double3 b, float alpha, out Double3 result) { - Double3.Lerp(ref a, ref b, alpha, out result); + Double3.Lerp(a, b, alpha, out result); } public void Bezier(ref Double3 p0, ref Double3 p1, ref Double3 p2, ref Double3 p3, float alpha, out Double3 result) { - Double3.Lerp(ref p0, ref p1, alpha, out var p01); - Double3.Lerp(ref p1, ref p2, alpha, out var p12); - Double3.Lerp(ref p2, ref p3, alpha, out var p23); - Double3.Lerp(ref p01, ref p12, alpha, out var p012); - Double3.Lerp(ref p12, ref p23, alpha, out var p123); - Double3.Lerp(ref p012, ref p123, alpha, out result); + Double3.Lerp(p0, p1, alpha, out var p01); + Double3.Lerp(p1, p2, alpha, out var p12); + Double3.Lerp(p2, p3, alpha, out var p23); + Double3.Lerp(p01, p12, alpha, out var p012); + Double3.Lerp(p12, p23, alpha, out var p123); + Double3.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Double4 value, ref Double4 tangent, float tangentScale, out Double4 result) @@ -311,37 +311,37 @@ namespace FlaxEngine public void Linear(ref Double4 a, ref Double4 b, float alpha, out Double4 result) { - Double4.Lerp(ref a, ref b, alpha, out result); + Double4.Lerp(a, b, alpha, out result); } public void Bezier(ref Double4 p0, ref Double4 p1, ref Double4 p2, ref Double4 p3, float alpha, out Double4 result) { - Double4.Lerp(ref p0, ref p1, alpha, out var p01); - Double4.Lerp(ref p1, ref p2, alpha, out var p12); - Double4.Lerp(ref p2, ref p3, alpha, out var p23); - Double4.Lerp(ref p01, ref p12, alpha, out var p012); - Double4.Lerp(ref p12, ref p23, alpha, out var p123); - Double4.Lerp(ref p012, ref p123, alpha, out result); + Double4.Lerp(p0, p1, alpha, out var p01); + Double4.Lerp(p1, p2, alpha, out var p12); + Double4.Lerp(p2, p3, alpha, out var p23); + Double4.Lerp(p01, p12, alpha, out var p012); + Double4.Lerp(p12, p23, alpha, out var p123); + Double4.Lerp(p012, p123, alpha, out result); } public void GetTangent(ref Quaternion value, ref Quaternion tangent, float tangentScale, out Quaternion result) { - Quaternion.Slerp(ref value, ref tangent, 1.0f / 3.0f, out result); + Quaternion.Slerp(value, tangent, 1.0f / 3.0f, out result); } public void Linear(ref Quaternion a, ref Quaternion b, float alpha, out Quaternion result) { - Quaternion.Slerp(ref a, ref b, alpha, out result); + Quaternion.Slerp(a, b, alpha, out result); } public void Bezier(ref Quaternion p0, ref Quaternion p1, ref Quaternion p2, ref Quaternion p3, float alpha, out Quaternion result) { - Quaternion.Slerp(ref p0, ref p1, alpha, out var p01); - Quaternion.Slerp(ref p1, ref p2, alpha, out var p12); - Quaternion.Slerp(ref p2, ref p3, alpha, out var p23); - Quaternion.Slerp(ref p01, ref p12, alpha, out var p012); - Quaternion.Slerp(ref p12, ref p23, alpha, out var p123); - Quaternion.Slerp(ref p012, ref p123, alpha, out result); + Quaternion.Slerp(p0, p1, alpha, out var p01); + Quaternion.Slerp(p1, p2, alpha, out var p12); + Quaternion.Slerp(p2, p3, alpha, out var p23); + Quaternion.Slerp(p01, p12, alpha, out var p012); + Quaternion.Slerp(p12, p23, alpha, out var p123); + Quaternion.Slerp(p012, p123, alpha, out result); } public void GetTangent(ref Color32 value, ref Color32 tangent, float tangentScale, out Color32 result) @@ -371,17 +371,17 @@ namespace FlaxEngine public void Linear(ref Color a, ref Color b, float alpha, out Color result) { - Color.Lerp(ref a, ref b, alpha, out result); + Color.Lerp(a, b, alpha, out result); } public void Bezier(ref Color p0, ref Color p1, ref Color p2, ref Color p3, float alpha, out Color result) { - Color.Lerp(ref p0, ref p1, alpha, out var p01); - Color.Lerp(ref p1, ref p2, alpha, out var p12); - Color.Lerp(ref p2, ref p3, alpha, out var p23); - Color.Lerp(ref p01, ref p12, alpha, out var p012); - Color.Lerp(ref p12, ref p23, alpha, out var p123); - Color.Lerp(ref p012, ref p123, alpha, out result); + Color.Lerp(p0, p1, alpha, out var p01); + Color.Lerp(p1, p2, alpha, out var p12); + Color.Lerp(p2, p3, alpha, out var p23); + Color.Lerp(p01, p12, alpha, out var p012); + Color.Lerp(p12, p23, alpha, out var p123); + Color.Lerp(p012, p123, alpha, out result); } } diff --git a/Source/Engine/Core/Math/BoundingBox.cs b/Source/Engine/Core/Math/BoundingBox.cs index cd702d531..e87244797 100644 --- a/Source/Engine/Core/Math/BoundingBox.cs +++ b/Source/Engine/Core/Math/BoundingBox.cs @@ -147,9 +147,9 @@ namespace FlaxEngine /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects(in Ray ray) { - return CollisionsHelper.RayIntersectsBox(ref ray, ref this, out Real _); + return CollisionsHelper.RayIntersectsBox(ray, this, out Real _); } /// @@ -158,9 +158,9 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Real distance) + public bool Intersects(in Ray ray, out Real distance) { - return CollisionsHelper.RayIntersectsBox(ref ray, ref this, out distance); + return CollisionsHelper.RayIntersectsBox(ray, this, out distance); } #if USE_LARGE_WORLDS @@ -172,9 +172,9 @@ namespace FlaxEngine /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. [Obsolete("Use Intersects with 'out Real distance' parameter instead")] - public bool Intersects(ref Ray ray, out float distance) + public bool Intersects(in Ray ray, out float distance) { - var result = CollisionsHelper.RayIntersectsBox(ref ray, ref this, out Real dst); + var result = CollisionsHelper.RayIntersectsBox(ray, this, out Real dst); distance = (float)dst; return result; } @@ -186,9 +186,9 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vector3 point) + public bool Intersects(in Ray ray, out Vector3 point) { - return CollisionsHelper.RayIntersectsBox(ref ray, ref this, out point); + return CollisionsHelper.RayIntersectsBox(ray, this, out point); } /// @@ -196,9 +196,9 @@ namespace FlaxEngine /// /// The plane to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Plane plane) + public PlaneIntersectionType Intersects(in Plane plane) { - return CollisionsHelper.PlaneIntersectsBox(ref plane, ref this); + return CollisionsHelper.PlaneIntersectsBox(plane, this); } /* This implementation is wrong @@ -209,7 +209,7 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public bool Intersects(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { return Collision.BoxIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); } @@ -220,9 +220,9 @@ namespace FlaxEngine /// /// The box to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box) + public bool Intersects(in BoundingBox box) { - return CollisionsHelper.BoxIntersectsBox(ref this, ref box); + return CollisionsHelper.BoxIntersectsBox(this, box); } /// @@ -232,7 +232,7 @@ namespace FlaxEngine /// Whether the two objects intersected. public bool Intersects(BoundingBox box) { - return Intersects(ref box); + return Intersects(in box); } /// @@ -240,9 +240,9 @@ namespace FlaxEngine /// /// The sphere to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere) + public bool Intersects(in BoundingSphere sphere) { - return CollisionsHelper.BoxIntersectsSphere(ref this, ref sphere); + return CollisionsHelper.BoxIntersectsSphere(this, sphere); } /// @@ -252,7 +252,7 @@ namespace FlaxEngine /// Whether the two objects intersected. public bool Intersects(BoundingSphere sphere) { - return Intersects(ref sphere); + return Intersects(in sphere); } /// @@ -260,9 +260,9 @@ namespace FlaxEngine /// /// The point to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vector3 point) + public ContainmentType Contains(in Vector3 point) { - return CollisionsHelper.BoxContainsPoint(ref this, ref point); + return CollisionsHelper.BoxContainsPoint(this, point); } /// @@ -272,7 +272,7 @@ namespace FlaxEngine /// The type of containment the two objects have. public ContainmentType Contains(Vector3 point) { - return Contains(ref point); + return Contains(in point); } /* This implementation is wrong @@ -283,7 +283,7 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public ContainmentType Contains(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { return Collision.BoxContainsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); } @@ -294,9 +294,9 @@ namespace FlaxEngine /// /// The box to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingBox box) + public ContainmentType Contains(in BoundingBox box) { - return CollisionsHelper.BoxContainsBox(ref this, ref box); + return CollisionsHelper.BoxContainsBox(this, box); } /// @@ -306,7 +306,7 @@ namespace FlaxEngine /// The type of containment the two objects have. public ContainmentType Contains(BoundingBox box) { - return Contains(ref box); + return Contains(in box); } /// @@ -314,9 +314,9 @@ namespace FlaxEngine /// /// The sphere to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingSphere sphere) + public ContainmentType Contains(in BoundingSphere sphere) { - return CollisionsHelper.BoxContainsSphere(ref this, ref sphere); + return CollisionsHelper.BoxContainsSphere(this, sphere); } /// @@ -326,7 +326,7 @@ namespace FlaxEngine /// The type of containment the two objects have. public ContainmentType Contains(BoundingSphere sphere) { - return Contains(ref sphere); + return Contains(in sphere); } /// @@ -343,8 +343,8 @@ namespace FlaxEngine var max = Vector3.Minimum; for (var i = 0; i < points.Length; ++i) { - Vector3.Min(ref min, ref points[i], out min); - Vector3.Max(ref max, ref points[i], out max); + Vector3.Min(min, points[i], out min); + Vector3.Max(max, points[i], out max); } result = new BoundingBox(min, max); } @@ -375,8 +375,8 @@ namespace FlaxEngine var max = Float3.Minimum; for (var i = 0; i < points.Length; ++i) { - Float3.Min(ref min, ref points[i], out min); - Float3.Max(ref max, ref points[i], out max); + Float3.Min(min, points[i], out min); + Float3.Max(max, points[i], out max); } result = new BoundingBox(min, max); } @@ -386,7 +386,7 @@ namespace FlaxEngine /// /// The sphere that will designate the extents of the box. /// When the method completes, contains the newly constructed bounding box. - public static void FromSphere(ref BoundingSphere sphere, out BoundingBox result) + public static void FromSphere(in BoundingSphere sphere, out BoundingBox result) { result.Minimum = new Vector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius); result.Maximum = new Vector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius); @@ -411,10 +411,10 @@ namespace FlaxEngine /// The first box to merge. /// The second box to merge. /// When the method completes, contains the newly constructed bounding box. - public static void Merge(ref BoundingBox value1, ref BoundingBox value2, out BoundingBox result) + public static void Merge(in BoundingBox value1, in BoundingBox value2, out BoundingBox result) { - Vector3.Min(ref value1.Minimum, ref value2.Minimum, out result.Minimum); - Vector3.Max(ref value1.Maximum, ref value2.Maximum, out result.Maximum); + Vector3.Min(value1.Minimum, value2.Minimum, out result.Minimum); + Vector3.Max(value1.Maximum, value2.Maximum, out result.Maximum); } /// @@ -426,8 +426,8 @@ namespace FlaxEngine public static BoundingBox Merge(BoundingBox value1, BoundingBox value2) { BoundingBox box; - Vector3.Min(ref value1.Minimum, ref value2.Minimum, out box.Minimum); - Vector3.Max(ref value1.Maximum, ref value2.Maximum, out box.Maximum); + Vector3.Min(value1.Minimum, value2.Minimum, out box.Minimum); + Vector3.Max(value1.Maximum, value2.Maximum, out box.Maximum); return box; } @@ -437,10 +437,10 @@ namespace FlaxEngine /// The box to merge. /// The point to merge. /// When the method completes, contains the newly constructed bounding box. - public static void Merge(ref BoundingBox value1, ref Vector3 value2, out BoundingBox result) + public static void Merge(in BoundingBox value1, in Vector3 value2, out BoundingBox result) { - Vector3.Min(ref value1.Minimum, ref value2, out result.Minimum); - Vector3.Max(ref value1.Maximum, ref value2, out result.Maximum); + Vector3.Min(value1.Minimum, value2, out result.Minimum); + Vector3.Max(value1.Maximum, value2, out result.Maximum); } /// @@ -451,8 +451,8 @@ namespace FlaxEngine public BoundingBox Merge(Vector3 value2) { BoundingBox result; - Vector3.Min(ref Minimum, ref value2, out result.Minimum); - Vector3.Max(ref Maximum, ref value2, out result.Maximum); + Vector3.Min(Minimum, value2, out result.Minimum); + Vector3.Max(Maximum, value2, out result.Maximum); return result; } @@ -464,7 +464,7 @@ namespace FlaxEngine /// The result of the transformation. public static BoundingBox Transform(BoundingBox box, Matrix transform) { - Transform(ref box, ref transform, out BoundingBox result); + Transform(box, transform, out BoundingBox result); return result; } @@ -474,7 +474,7 @@ namespace FlaxEngine /// The bounding box to transform. /// The transformation matrix. /// The result of the transformation. - public static void Transform(ref BoundingBox box, ref Matrix transform, out BoundingBox result) + public static void Transform(in BoundingBox box, in Matrix transform, out BoundingBox result) { // Reference: http://dev.theomader.com/transform-bounding-boxes/ @@ -504,7 +504,7 @@ namespace FlaxEngine /// The result of the transformation. public static BoundingBox Transform(BoundingBox box, Transform transform) { - Transform(ref box, ref transform, out BoundingBox result); + Transform(box, transform, out BoundingBox result); return result; } @@ -514,7 +514,7 @@ namespace FlaxEngine /// The bounding box to transform. /// The transformation. /// The result of the transformation. - public static void Transform(ref BoundingBox box, ref Transform transform, out BoundingBox result) + public static void Transform(in BoundingBox box, in Transform transform, out BoundingBox result) { // Reference: http://dev.theomader.com/transform-bounding-boxes/ @@ -543,8 +543,8 @@ namespace FlaxEngine public BoundingBox MakeOffsetted(Vector3 offset) { BoundingBox result; - Vector3.Add(ref Minimum, ref offset, out result.Minimum); - Vector3.Add(ref Maximum, ref offset, out result.Maximum); + Vector3.Add(Minimum, offset, out result.Minimum); + Vector3.Add(Maximum, offset, out result.Maximum); return result; } @@ -554,11 +554,11 @@ namespace FlaxEngine /// The box. /// The bounds offset. /// The offsetted bounds. - public static BoundingBox MakeOffsetted(ref BoundingBox box, ref Vector3 offset) + public static BoundingBox MakeOffsetted(in BoundingBox box, in Vector3 offset) { BoundingBox result; - Vector3.Add(ref box.Minimum, ref offset, out result.Minimum); - Vector3.Add(ref box.Maximum, ref offset, out result.Maximum); + Vector3.Add(box.Minimum, offset, out result.Minimum); + Vector3.Add(box.Maximum, offset, out result.Maximum); return result; } @@ -568,9 +568,9 @@ namespace FlaxEngine /// The box. /// The bounds scale. /// The scaled bounds. - public static BoundingBox MakeScaled(ref BoundingBox box, Real scale) + public static BoundingBox MakeScaled(in BoundingBox box, Real scale) { - Vector3.Subtract(ref box.Maximum, ref box.Minimum, out var size); + Vector3.Subtract(box.Maximum, box.Minimum, out var size); Vector3 sizeHalf = size * 0.5f; Vector3 center = box.Minimum + sizeHalf; sizeHalf *= scale; @@ -586,7 +586,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static BoundingBox operator *(BoundingBox box, Matrix transform) { - Transform(ref box, ref transform, out BoundingBox result); + Transform(box, transform, out BoundingBox result); return result; } @@ -599,7 +599,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(BoundingBox left, BoundingBox right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -611,7 +611,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(BoundingBox left, BoundingBox right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -676,7 +676,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref BoundingBox other) + public bool Equals(in BoundingBox other) { return Minimum == other.Minimum && Maximum == other.Maximum; } @@ -689,7 +689,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(BoundingBox other) { - return Equals(ref other); + return Equals(in other); } /// @@ -699,7 +699,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is BoundingBox other && Equals(ref other); + return value is BoundingBox other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/BoundingFrustum.cs b/Source/Engine/Core/Math/BoundingFrustum.cs index 4f1e27e1e..5d86bdc2a 100644 --- a/Source/Engine/Core/Math/BoundingFrustum.cs +++ b/Source/Engine/Core/Math/BoundingFrustum.cs @@ -60,7 +60,7 @@ namespace FlaxEngine set { pMatrix = value; - GetPlanesFromMatrix(ref pMatrix, out pNear, out pFar, out pLeft, out pRight, out pTop, out pBottom); + GetPlanesFromMatrix(in pMatrix, out pNear, out pFar, out pLeft, out pRight, out pTop, out pBottom); } } @@ -101,17 +101,17 @@ namespace FlaxEngine public BoundingFrustum(Matrix matrix) { pMatrix = matrix; - GetPlanesFromMatrix(ref pMatrix, out pNear, out pFar, out pLeft, out pRight, out pTop, out pBottom); + GetPlanesFromMatrix(in pMatrix, out pNear, out pFar, out pLeft, out pRight, out pTop, out pBottom); } /// /// Creates a new instance of BoundingFrustum. /// /// Combined matrix that usually takes view × projection matrix. - public BoundingFrustum(ref Matrix matrix) + public BoundingFrustum(in Matrix matrix) { pMatrix = matrix; - GetPlanesFromMatrix(ref pMatrix, out pNear, out pFar, out pLeft, out pRight, out pTop, out pBottom); + GetPlanesFromMatrix(in pMatrix, out pNear, out pFar, out pLeft, out pRight, out pTop, out pBottom); } /// @@ -129,7 +129,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref BoundingFrustum other) + public bool Equals(in BoundingFrustum other) { return pMatrix == other.pMatrix; } @@ -142,7 +142,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(BoundingFrustum other) { - return Equals(ref other); + return Equals(in other); } /// @@ -152,7 +152,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object obj) { - return obj is BoundingFrustum other && Equals(ref other); + return obj is BoundingFrustum other && Equals(in other); } /// @@ -164,7 +164,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(BoundingFrustum left, BoundingFrustum right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -176,7 +176,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(BoundingFrustum left, BoundingFrustum right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -198,7 +198,7 @@ namespace FlaxEngine } } - private static void GetPlanesFromMatrix(ref Matrix matrix, out Plane near, out Plane far, out Plane left, out Plane right, out Plane top, out Plane bottom) + private static void GetPlanesFromMatrix(in Matrix matrix, out Plane near, out Plane far, out Plane left, out Plane right, out Plane top, out Plane bottom) { //http://www.chadvernon.com/blog/resources/directx9/frustum-culling/ @@ -245,14 +245,14 @@ namespace FlaxEngine far.Normalize(); } - private static Vector3 Get3PlanesInterPoint(ref Plane p1, ref Plane p2, ref Plane p3) + private static Vector3 Get3PlanesInterPoint(in Plane p1, in Plane p2, in Plane p3) { - Vector3.Cross(ref p2.Normal, ref p3.Normal, out var n2Xn3); - Vector3.Cross(ref p3.Normal, ref p1.Normal, out var n3Xn1); - Vector3.Cross(ref p1.Normal, ref p2.Normal, out var n1Xn2); - var div1 = Vector3.Dot(ref p1.Normal, ref n2Xn3); - var div2 = Vector3.Dot(ref p2.Normal, ref n3Xn1); - var div3 = Vector3.Dot(ref p3.Normal, ref n1Xn2); + Vector3.Cross(p2.Normal, p3.Normal, out var n2Xn3); + Vector3.Cross(p3.Normal, p1.Normal, out var n3Xn1); + Vector3.Cross(p1.Normal, p2.Normal, out var n1Xn2); + var div1 = Vector3.Dot(p1.Normal, n2Xn3); + var div2 = Vector3.Dot(p2.Normal, n3Xn1); + var div3 = Vector3.Dot(p3.Normal, n1Xn2); if (Mathf.IsZero(div1 * div2 * div3)) return Vector3.Zero; return n2Xn3 * (-p1.D / div1) - n3Xn1 * (p2.D / div2) - n1Xn2 * (p3.D / div3); @@ -346,14 +346,14 @@ namespace FlaxEngine /// The 8 corners of the frustum public void GetCorners(Vector3[] corners) { - corners[0] = Get3PlanesInterPoint(ref pNear, ref pBottom, ref pRight); //Near1 - corners[1] = Get3PlanesInterPoint(ref pNear, ref pTop, ref pRight); //Near2 - corners[2] = Get3PlanesInterPoint(ref pNear, ref pTop, ref pLeft); //Near3 - corners[3] = Get3PlanesInterPoint(ref pNear, ref pBottom, ref pLeft); //Near3 - corners[4] = Get3PlanesInterPoint(ref pFar, ref pBottom, ref pRight); //Far1 - corners[5] = Get3PlanesInterPoint(ref pFar, ref pTop, ref pRight); //Far2 - corners[6] = Get3PlanesInterPoint(ref pFar, ref pTop, ref pLeft); //Far3 - corners[7] = Get3PlanesInterPoint(ref pFar, ref pBottom, ref pLeft); //Far3 + corners[0] = Get3PlanesInterPoint(in pNear, in pBottom, in pRight); //Near1 + corners[1] = Get3PlanesInterPoint(in pNear, in pTop, in pRight); //Near2 + corners[2] = Get3PlanesInterPoint(in pNear, in pTop, in pLeft); //Near3 + corners[3] = Get3PlanesInterPoint(in pNear, in pBottom, in pLeft); //Near3 + corners[4] = Get3PlanesInterPoint(in pFar, in pBottom, in pRight); //Far1 + corners[5] = Get3PlanesInterPoint(in pFar, in pTop, in pRight); //Far2 + corners[6] = Get3PlanesInterPoint(in pFar, in pTop, in pLeft); //Far3 + corners[7] = Get3PlanesInterPoint(in pFar, in pBottom, in pLeft); //Far3 } /// @@ -361,7 +361,7 @@ namespace FlaxEngine /// /// The point. /// Type of the containment - public ContainmentType Contains(ref Vector3 point) + public ContainmentType Contains(in Vector3 point) { var result = PlaneIntersectionType.Front; var planeResult = PlaneIntersectionType.Front; @@ -370,22 +370,22 @@ namespace FlaxEngine switch (i) { case 0: - planeResult = pNear.Intersects(ref point); + planeResult = pNear.Intersects(point); break; case 1: - planeResult = pFar.Intersects(ref point); + planeResult = pFar.Intersects(point); break; case 2: - planeResult = pLeft.Intersects(ref point); + planeResult = pLeft.Intersects(point); break; case 3: - planeResult = pRight.Intersects(ref point); + planeResult = pRight.Intersects(point); break; case 4: - planeResult = pTop.Intersects(ref point); + planeResult = pTop.Intersects(point); break; case 5: - planeResult = pBottom.Intersects(ref point); + planeResult = pBottom.Intersects(point); break; } switch (planeResult) @@ -410,10 +410,10 @@ namespace FlaxEngine /// Type of the containment public ContainmentType Contains(Vector3 point) { - return Contains(ref point); + return Contains(in point); } - private void GetBoxToPlanePVertexNVertex(ref BoundingBox box, ref Vector3 planeNormal, out Vector3 p, out Vector3 n) + private void GetBoxToPlanePVertexNVertex(in BoundingBox box, in Vector3 planeNormal, out Vector3 p, out Vector3 n) { p = box.Minimum; if (planeNormal.X >= 0) @@ -437,17 +437,17 @@ namespace FlaxEngine /// /// The box. /// Type of the containment - public ContainmentType Contains(ref BoundingBox box) + public ContainmentType Contains(in BoundingBox box) { var result = ContainmentType.Contains; for (var i = 0; i < 6; i++) { var plane = GetPlane(i); - GetBoxToPlanePVertexNVertex(ref box, ref plane.Normal, out var p, out var n); - if (CollisionsHelper.PlaneIntersectsPoint(ref plane, ref p) == PlaneIntersectionType.Back) + GetBoxToPlanePVertexNVertex(in box, in plane.Normal, out var p, out var n); + if (CollisionsHelper.PlaneIntersectsPoint(plane, p) == PlaneIntersectionType.Back) return ContainmentType.Disjoint; - if (CollisionsHelper.PlaneIntersectsPoint(ref plane, ref n) == PlaneIntersectionType.Back) + if (CollisionsHelper.PlaneIntersectsPoint(plane, n) == PlaneIntersectionType.Back) result = ContainmentType.Intersects; } return result; @@ -460,7 +460,7 @@ namespace FlaxEngine /// Type of the containment public ContainmentType Contains(BoundingBox box) { - return Contains(ref box); + return Contains(in box); } /// @@ -468,9 +468,9 @@ namespace FlaxEngine /// /// The box. /// Type of the containment. - public void Contains(ref BoundingBox box, out ContainmentType result) + public void Contains(in BoundingBox box, out ContainmentType result) { - result = Contains(ref box); + result = Contains(in box); } /// @@ -478,7 +478,7 @@ namespace FlaxEngine /// /// The sphere. /// Type of the containment - public ContainmentType Contains(ref BoundingSphere sphere) + public ContainmentType Contains(in BoundingSphere sphere) { var result = PlaneIntersectionType.Front; var planeResult = PlaneIntersectionType.Front; @@ -487,22 +487,22 @@ namespace FlaxEngine switch (i) { case 0: - planeResult = pNear.Intersects(ref sphere); + planeResult = pNear.Intersects(sphere); break; case 1: - planeResult = pFar.Intersects(ref sphere); + planeResult = pFar.Intersects(sphere); break; case 2: - planeResult = pLeft.Intersects(ref sphere); + planeResult = pLeft.Intersects(sphere); break; case 3: - planeResult = pRight.Intersects(ref sphere); + planeResult = pRight.Intersects(sphere); break; case 4: - planeResult = pTop.Intersects(ref sphere); + planeResult = pTop.Intersects(sphere); break; case 5: - planeResult = pBottom.Intersects(ref sphere); + planeResult = pBottom.Intersects(sphere); break; } switch (planeResult) @@ -527,7 +527,7 @@ namespace FlaxEngine /// Type of the containment public ContainmentType Contains(BoundingSphere sphere) { - return Contains(ref sphere); + return Contains(in sphere); } /// @@ -535,9 +535,9 @@ namespace FlaxEngine /// /// The sphere. /// Type of the containment. - public void Contains(ref BoundingSphere sphere, out ContainmentType result) + public void Contains(in BoundingSphere sphere, out ContainmentType result) { - result = Contains(ref sphere); + result = Contains(in sphere); } /// @@ -545,9 +545,9 @@ namespace FlaxEngine /// /// The sphere. /// Type of the containment - public bool Intersects(ref BoundingSphere sphere) + public bool Intersects(in BoundingSphere sphere) { - return Contains(ref sphere) != ContainmentType.Disjoint; + return Contains(in sphere) != ContainmentType.Disjoint; } /// @@ -555,9 +555,9 @@ namespace FlaxEngine /// /// The sphere. /// Set to true if the current BoundingFrustum intersects a BoundingSphere. - public void Intersects(ref BoundingSphere sphere, out bool result) + public void Intersects(in BoundingSphere sphere, out bool result) { - result = Contains(ref sphere) != ContainmentType.Disjoint; + result = Contains(in sphere) != ContainmentType.Disjoint; } /// @@ -565,9 +565,9 @@ namespace FlaxEngine /// /// The box. /// true if the current BoundingFrustum intersects a BoundingSphere. - public bool Intersects(ref BoundingBox box) + public bool Intersects(in BoundingBox box) { - return Contains(ref box) != ContainmentType.Disjoint; + return Contains(in box) != ContainmentType.Disjoint; } /// @@ -575,16 +575,16 @@ namespace FlaxEngine /// /// The box. /// true if the current BoundingFrustum intersects a BoundingSphere. - public void Intersects(ref BoundingBox box, out bool result) + public void Intersects(in BoundingBox box, out bool result) { - result = Contains(ref box) != ContainmentType.Disjoint; + result = Contains(in box) != ContainmentType.Disjoint; } - private PlaneIntersectionType PlaneIntersectsPoints(ref Plane plane, Vector3[] points) + private PlaneIntersectionType PlaneIntersectsPoints(in Plane plane, Vector3[] points) { - PlaneIntersectionType result = CollisionsHelper.PlaneIntersectsPoint(ref plane, ref points[0]); + PlaneIntersectionType result = CollisionsHelper.PlaneIntersectsPoint(plane, points[0]); for (var i = 1; i < points.Length; i++) - if (CollisionsHelper.PlaneIntersectsPoint(ref plane, ref points[i]) != result) + if (CollisionsHelper.PlaneIntersectsPoint(plane, points[i]) != result) return PlaneIntersectionType.Intersecting; return result; } @@ -594,9 +594,9 @@ namespace FlaxEngine /// /// The plane. /// Plane intersection type. - public PlaneIntersectionType Intersects(ref Plane plane) + public PlaneIntersectionType Intersects(in Plane plane) { - return PlaneIntersectsPoints(ref plane, GetCorners()); + return PlaneIntersectsPoints(in plane, GetCorners()); } /// @@ -604,9 +604,9 @@ namespace FlaxEngine /// /// The plane. /// Plane intersection type. - public void Intersects(ref Plane plane, out PlaneIntersectionType result) + public void Intersects(in Plane plane, out PlaneIntersectionType result) { - result = PlaneIntersectsPoints(ref plane, GetCorners()); + result = PlaneIntersectsPoints(in plane, GetCorners()); } /// @@ -648,9 +648,9 @@ namespace FlaxEngine /// /// The ray. /// true if the current BoundingFrustum intersects the specified Ray. - public bool Intersects(ref Ray ray) + public bool Intersects(in Ray ray) { - return Intersects(ref ray, out _, out _); + return Intersects(in ray, out _, out _); } /// @@ -660,7 +660,7 @@ namespace FlaxEngine /// The distance at which the ray enters the frustum if there is an intersection and the ray starts outside the frustum. /// The distance at which the ray exits the frustum if there is an intersection. /// true if the current BoundingFrustum intersects the specified Ray. - public bool Intersects(ref Ray ray, out Real? inDistance, out Real? outDistance) + public bool Intersects(in Ray ray, out Real? inDistance, out Real? outDistance) { if (Contains(ray.Position) != ContainmentType.Disjoint) { @@ -668,7 +668,7 @@ namespace FlaxEngine for (var i = 0; i < 6; i++) { Plane plane = GetPlane(i); - if (CollisionsHelper.RayIntersectsPlane(ref ray, ref plane, out Real distance) && (distance < nearstPlaneDistance)) + if (CollisionsHelper.RayIntersectsPlane(ray, plane, out Real distance) && (distance < nearstPlaneDistance)) nearstPlaneDistance = distance; } @@ -684,7 +684,7 @@ namespace FlaxEngine for (var i = 0; i < 6; i++) { Plane plane = GetPlane(i); - if (CollisionsHelper.RayIntersectsPlane(ref ray, ref plane, out Real distance)) + if (CollisionsHelper.RayIntersectsPlane(ray, plane, out Real distance)) { minDist = Mathf.Min(minDist, distance); maxDist = Mathf.Max(maxDist, distance); @@ -694,7 +694,7 @@ namespace FlaxEngine Vector3 minPoint = ray.Position + ray.Direction * minDist; Vector3 maxPoint = ray.Position + ray.Direction * maxDist; Vector3 center = (minPoint + maxPoint) / 2f; - if (Contains(ref center) != ContainmentType.Disjoint) + if (Contains(in center) != ContainmentType.Disjoint) { inDistance = minDist; outDistance = maxDist; @@ -725,10 +725,10 @@ namespace FlaxEngine var maxPointDist = Real.MinValue; for (var i = 0; i < points.Length; i++) { - var pointDist = CollisionsHelper.DistancePlanePoint(ref ioFrustrum.pTop, ref points[i]); - pointDist = Mathf.Max(pointDist, CollisionsHelper.DistancePlanePoint(ref ioFrustrum.pBottom, ref points[i])); - pointDist = Mathf.Max(pointDist, CollisionsHelper.DistancePlanePoint(ref ioFrustrum.pLeft, ref points[i]) * horizontalToVerticalMapping); - pointDist = Mathf.Max(pointDist, CollisionsHelper.DistancePlanePoint(ref ioFrustrum.pRight, ref points[i]) * horizontalToVerticalMapping); + var pointDist = CollisionsHelper.DistancePlanePoint(ioFrustrum.pTop, points[i]); + pointDist = Mathf.Max(pointDist, CollisionsHelper.DistancePlanePoint(ioFrustrum.pBottom, points[i])); + pointDist = Mathf.Max(pointDist, CollisionsHelper.DistancePlanePoint(ioFrustrum.pLeft, points[i]) * horizontalToVerticalMapping); + pointDist = Mathf.Max(pointDist, CollisionsHelper.DistancePlanePoint(ioFrustrum.pRight, points[i]) * horizontalToVerticalMapping); maxPointDist = Mathf.Max(maxPointDist, pointDist); } return -maxPointDist / vSin; @@ -741,7 +741,7 @@ namespace FlaxEngine /// /// The bounding box. /// The zoom to fit distance - public Real GetZoomToExtentsShiftDistance(ref BoundingBox boundingBox) + public Real GetZoomToExtentsShiftDistance(in BoundingBox boundingBox) { return GetZoomToExtentsShiftDistance(boundingBox.GetCorners()); } @@ -760,7 +760,7 @@ namespace FlaxEngine /// Get the vector shift which when added to camera position will do the effect of zoom to extents (zoom to fit) operation, so all the passed points will fit in the current view. /// The bounding box. /// The zoom to fit vector - public Vector3 GetZoomToExtentsShiftVector(ref BoundingBox boundingBox) + public Vector3 GetZoomToExtentsShiftVector(in BoundingBox boundingBox) { return GetZoomToExtentsShiftDistance(boundingBox.GetCorners()) * pNear.Normal; } diff --git a/Source/Engine/Core/Math/BoundingSphere.cs b/Source/Engine/Core/Math/BoundingSphere.cs index b57177d77..a618da5a6 100644 --- a/Source/Engine/Core/Math/BoundingSphere.cs +++ b/Source/Engine/Core/Math/BoundingSphere.cs @@ -85,9 +85,9 @@ namespace FlaxEngine /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects(in Ray ray) { - return CollisionsHelper.RayIntersectsSphere(ref ray, ref this, out Real _); + return CollisionsHelper.RayIntersectsSphere(ray, this, out Real _); } /// @@ -96,9 +96,9 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Real distance) + public bool Intersects(in Ray ray, out Real distance) { - return CollisionsHelper.RayIntersectsSphere(ref ray, ref this, out distance); + return CollisionsHelper.RayIntersectsSphere(ray, this, out distance); } /// @@ -107,9 +107,9 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vector3 point) + public bool Intersects(in Ray ray, out Vector3 point) { - return CollisionsHelper.RayIntersectsSphere(ref ray, ref this, out point); + return CollisionsHelper.RayIntersectsSphere(ray, this, out point); } /// @@ -117,9 +117,9 @@ namespace FlaxEngine /// /// The plane to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Plane plane) + public PlaneIntersectionType Intersects(in Plane plane) { - return CollisionsHelper.PlaneIntersectsSphere(ref plane, ref this); + return CollisionsHelper.PlaneIntersectsSphere(plane, this); } /// @@ -129,9 +129,9 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public bool Intersects(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { - return CollisionsHelper.SphereIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); + return CollisionsHelper.SphereIntersectsTriangle(this, vertex1, vertex2, vertex3); } /// @@ -139,9 +139,9 @@ namespace FlaxEngine /// /// The box to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box) + public bool Intersects(in BoundingBox box) { - return CollisionsHelper.BoxIntersectsSphere(ref box, ref this); + return CollisionsHelper.BoxIntersectsSphere(box, this); } /// @@ -151,7 +151,7 @@ namespace FlaxEngine /// Whether the two objects intersected. public bool Intersects(BoundingBox box) { - return Intersects(ref box); + return Intersects(in box); } /// @@ -159,9 +159,9 @@ namespace FlaxEngine /// /// The sphere to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere) + public bool Intersects(in BoundingSphere sphere) { - return CollisionsHelper.SphereIntersectsSphere(ref this, ref sphere); + return CollisionsHelper.SphereIntersectsSphere(this, sphere); } /// @@ -171,7 +171,7 @@ namespace FlaxEngine /// Whether the two objects intersected. public bool Intersects(BoundingSphere sphere) { - return Intersects(ref sphere); + return Intersects(in sphere); } /// @@ -179,9 +179,9 @@ namespace FlaxEngine /// /// The point to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vector3 point) + public ContainmentType Contains(in Vector3 point) { - return CollisionsHelper.SphereContainsPoint(ref this, ref point); + return CollisionsHelper.SphereContainsPoint(this, point); } /// @@ -191,9 +191,9 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public ContainmentType Contains(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { - return CollisionsHelper.SphereContainsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); + return CollisionsHelper.SphereContainsTriangle(this, vertex1, vertex2, vertex3); } /// @@ -201,9 +201,9 @@ namespace FlaxEngine /// /// The box to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingBox box) + public ContainmentType Contains(in BoundingBox box) { - return CollisionsHelper.SphereContainsBox(ref this, ref box); + return CollisionsHelper.SphereContainsBox(this, box); } /// @@ -211,9 +211,9 @@ namespace FlaxEngine /// /// The sphere to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingSphere sphere) + public ContainmentType Contains(in BoundingSphere sphere) { - return CollisionsHelper.SphereContainsSphere(ref this, ref sphere); + return CollisionsHelper.SphereContainsSphere(this, sphere); } /// @@ -239,7 +239,7 @@ namespace FlaxEngine // Find the center of all points Vector3 center = Vector3.Zero; for (int i = start; i < upperEnd; ++i) - Vector3.Add(ref points[i], ref center, out center); + Vector3.Add(points[i], center, out center); center /= (Real)count; // Find the radius of the sphere @@ -247,7 +247,7 @@ namespace FlaxEngine for (int i = start; i < upperEnd; ++i) { // We are doing a relative distance comparison to find the maximum distance from the center of our sphere - Vector3.DistanceSquared(ref center, ref points[i], out Real distance); + Vector3.DistanceSquared(center, points[i], out Real distance); if (distance > radius) radius = distance; } @@ -285,7 +285,7 @@ namespace FlaxEngine /// /// The box that will designate the extents of the sphere. /// When the method completes, the newly constructed bounding sphere. - public static void FromBox(ref BoundingBox box, out BoundingSphere result) + public static void FromBox(in BoundingBox box, out BoundingSphere result) { var x = box.Maximum.X - box.Minimum.X; var y = box.Maximum.Y - box.Minimum.Y; @@ -303,7 +303,7 @@ namespace FlaxEngine /// The newly constructed bounding sphere. public static BoundingSphere FromBox(BoundingBox box) { - FromBox(ref box, out var result); + FromBox(in box, out var result); return result; } @@ -314,7 +314,7 @@ namespace FlaxEngine /// The first sphere to merge. /// The second sphere to merge. /// When the method completes, contains the newly constructed bounding sphere. - public static void Merge(ref BoundingSphere value1, ref BoundingSphere value2, out BoundingSphere result) + public static void Merge(in BoundingSphere value1, in BoundingSphere value2, out BoundingSphere result) { // Pre-exit if one of the bounding sphere by assuming that a merge with an empty sphere is equivalent at taking the non-empty sphere if (value1 == Empty) @@ -365,7 +365,7 @@ namespace FlaxEngine /// The newly constructed bounding sphere. public static BoundingSphere Merge(BoundingSphere value1, BoundingSphere value2) { - Merge(ref value1, ref value2, out var result); + Merge(in value1, in value2, out var result); return result; } @@ -377,7 +377,7 @@ namespace FlaxEngine /// The result transformed sphere. public static BoundingSphere Transform(BoundingSphere sphere, Matrix matrix) { - Transform(ref sphere, ref matrix, out var result); + Transform(in sphere, in matrix, out var result); return result; } @@ -387,9 +387,9 @@ namespace FlaxEngine /// The sphere. /// The matrix. /// The result transformed sphere. - public static void Transform(ref BoundingSphere sphere, ref Matrix matrix, out BoundingSphere result) + public static void Transform(in BoundingSphere sphere, in Matrix matrix, out BoundingSphere result) { - Vector3.Transform(ref sphere.Center, ref matrix, out result.Center); + Vector3.Transform(sphere.Center, matrix, out result.Center); result.Radius = sphere.Radius * matrix.ScaleVector.Absolute.MaxValue; } @@ -402,7 +402,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(BoundingSphere left, BoundingSphere right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -414,7 +414,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(BoundingSphere left, BoundingSphere right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -490,7 +490,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref BoundingSphere other) + public bool Equals(in BoundingSphere other) { return Center == other.Center && Radius == other.Radius; } @@ -503,7 +503,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(BoundingSphere other) { - return Equals(ref other); + return Equals(in other); } /// @@ -513,7 +513,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is BoundingSphere other && Equals(ref other); + return value is BoundingSphere other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/CollisionsHelper.cs b/Source/Engine/Core/Math/CollisionsHelper.cs index a693bdae3..f7b260b86 100644 --- a/Source/Engine/Core/Math/CollisionsHelper.cs +++ b/Source/Engine/Core/Math/CollisionsHelper.cs @@ -136,7 +136,7 @@ namespace FlaxEngine /// The line first point. /// The line second point. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointPointLine(ref Float2 point, ref Float2 p0, ref Float2 p1, out Float2 result) + public static void ClosestPointPointLine(in Float2 point, in Float2 p0, in Float2 p1, out Float2 result) { var p = point - p0; var n = p1 - p0; @@ -175,7 +175,7 @@ namespace FlaxEngine /// The line first point. /// The line second point. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointPointLine(ref Vector3 point, ref Vector3 p0, ref Vector3 p1, out Vector3 result) + public static void ClosestPointPointLine(in Vector3 point, in Vector3 p0, in Vector3 p1, out Vector3 result) { Vector3 p = point - p0; Vector3 n = p1 - p0; @@ -186,7 +186,7 @@ namespace FlaxEngine return; } n /= length; - Real dot = Vector3.Dot(ref n, ref p); + Real dot = Vector3.Dot(n, p); if (dot <= 0.0f) { result = p0; @@ -208,7 +208,7 @@ namespace FlaxEngine /// The second vertex to test. /// The third vertex to test. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointPointTriangle(ref Vector3 point, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 result) + public static void ClosestPointPointTriangle(in Vector3 point, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3, out Vector3 result) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 136 @@ -286,12 +286,12 @@ namespace FlaxEngine /// The plane to test. /// The point to test. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointPlanePoint(ref Plane plane, ref Vector3 point, out Vector3 result) + public static void ClosestPointPlanePoint(in Plane plane, in Vector3 point, out Vector3 result) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 126 - Vector3.Dot(ref plane.Normal, ref point, out Real dot); + Vector3.Dot(plane.Normal, point, out Real dot); Real t = dot - plane.D; result = point - t * plane.Normal; @@ -303,13 +303,13 @@ namespace FlaxEngine /// The box to test. /// The point to test. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointBoxPoint(ref BoundingBox box, ref Vector3 point, out Vector3 result) + public static void ClosestPointBoxPoint(in BoundingBox box, in Vector3 point, out Vector3 result) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 130 - Vector3.Max(ref point, ref box.Minimum, out Vector3 temp); - Vector3.Min(ref temp, ref box.Maximum, out result); + Vector3.Max(point, box.Minimum, out Vector3 temp); + Vector3.Min(temp, box.Maximum, out result); } /// @@ -318,11 +318,11 @@ namespace FlaxEngine /// The rectangle to test. /// The point to test. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointRectanglePoint(ref Rectangle rect, ref Float2 point, out Float2 result) + public static void ClosestPointRectanglePoint(in Rectangle rect, in Float2 point, out Float2 result) { Float2 end = rect.Location + rect.Size; - Float2.Max(ref point, ref rect.Location, out var temp); - Float2.Min(ref temp, ref end, out result); + Float2.Max(point, rect.Location, out var temp); + Float2.Min(temp, end, out result); } /// @@ -332,13 +332,13 @@ namespace FlaxEngine /// The point to test. /// When the method completes, contains the closest point between the two objects; or, if the point is directly in the center of the sphere, contains . /// - public static void ClosestPointSpherePoint(ref BoundingSphere sphere, ref Vector3 point, out Vector3 result) + public static void ClosestPointSpherePoint(in BoundingSphere sphere, in Vector3 point, out Vector3 result) { //Source: Jorgy343 //Reference: None //Get the unit direction from the sphere's center to the point. - Vector3.Subtract(ref point, ref sphere.Center, out result); + Vector3.Subtract(point, sphere.Center, out result); result.Normalize(); //Multiply the unit direction by the sphere's radius to get a vector @@ -360,13 +360,13 @@ namespace FlaxEngine /// is the 'closest' point of intersection. This can also be considered is the deepest point of /// intersection. /// - public static void ClosestPointSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2, out Vector3 result) + public static void ClosestPointSphereSphere(in BoundingSphere sphere1, in BoundingSphere sphere2, out Vector3 result) { //Source: Jorgy343 //Reference: None //Get the unit direction from the first sphere's center to the second sphere's center. - Vector3.Subtract(ref sphere2.Center, ref sphere1.Center, out result); + Vector3.Subtract(sphere2.Center, sphere1.Center, out result); result.Normalize(); //Multiply the unit direction by the first sphere's radius to get a vector @@ -383,12 +383,12 @@ namespace FlaxEngine /// The plane to test. /// The point to test. /// The distance between the two objects. - public static Real DistancePlanePoint(ref Plane plane, ref Vector3 point) + public static Real DistancePlanePoint(in Plane plane, in Vector3 point) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 127 - Vector3.Dot(ref plane.Normal, ref point, out Real dot); + Vector3.Dot(plane.Normal, point, out Real dot); return dot - plane.D; } @@ -398,7 +398,7 @@ namespace FlaxEngine /// The box to test. /// The point to test. /// The distance between the two objects. - public static Real DistanceBoxPoint(ref BoundingBox box, ref Vector3 point) + public static Real DistanceBoxPoint(in BoundingBox box, in Vector3 point) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 131 @@ -428,7 +428,7 @@ namespace FlaxEngine /// The first box to test. /// The second box to test. /// The distance between the two objects. - public static Real DistanceBoxBox(ref BoundingBox box1, ref BoundingBox box2) + public static Real DistanceBoxBox(in BoundingBox box1, in BoundingBox box2) { //Source: //Reference: @@ -480,12 +480,12 @@ namespace FlaxEngine /// The sphere to test. /// The point to test. /// The distance between the two objects. - public static Real DistanceSpherePoint(ref BoundingSphere sphere, ref Vector3 point) + public static Real DistanceSpherePoint(in BoundingSphere sphere, in Vector3 point) { //Source: Jorgy343 //Reference: None - Vector3.Distance(ref sphere.Center, ref point, out Real distance); + Vector3.Distance(sphere.Center, point, out Real distance); distance -= sphere.Radius; return Math.Max(distance, 0f); } @@ -496,12 +496,12 @@ namespace FlaxEngine /// The first sphere to test. /// The second sphere to test. /// The distance between the two objects. - public static Real DistanceSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2) + public static Real DistanceSphereSphere(in BoundingSphere sphere1, in BoundingSphere sphere2) { //Source: Jorgy343 //Reference: None - Vector3.Distance(ref sphere1.Center, ref sphere2.Center, out Real distance); + Vector3.Distance(sphere1.Center, sphere2.Center, out Real distance); distance -= sphere1.Radius + sphere2.Radius; return Math.Max(distance, 0f); } @@ -512,12 +512,12 @@ namespace FlaxEngine /// The ray to test. /// The point to test. /// Whether the two objects intersect. - public static bool RayIntersectsPoint(ref Ray ray, ref Vector3 point) + public static bool RayIntersectsPoint(in Ray ray, in Vector3 point) { //Source: RayIntersectsSphere //Reference: None - Vector3.Subtract(ref ray.Position, ref point, out Vector3 m); + Vector3.Subtract(ray.Position, point, out Vector3 m); //Same thing as RayIntersectsSphere except that the radius of the sphere (point) is the epsilon for zero. Real b = Vector3.Dot(m, ray.Direction); @@ -547,12 +547,12 @@ namespace FlaxEngine /// of the second ray, det denotes the determinant of a matrix, x denotes the cross /// product, [ ] denotes a matrix, and || || denotes the length or magnitude of a vector. /// - public static bool RayIntersectsRay(ref Ray ray1, ref Ray ray2, out Vector3 point) + public static bool RayIntersectsRay(in Ray ray1, in Ray ray2, out Vector3 point) { //Source: Real-Time Rendering, Third Edition //Reference: Page 780 - Vector3.Cross(ref ray1.Direction, ref ray2.Direction, out Vector3 cross); + Vector3.Cross(ray1.Direction, ray2.Direction, out Vector3 cross); Real denominator = cross.Length; //Lines are parallel. @@ -629,18 +629,18 @@ namespace FlaxEngine /// The plane to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersect. - public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out Real distance) + public static bool RayIntersectsPlane(in Ray ray, in Plane plane, out Real distance) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 175 - Vector3.Dot(ref plane.Normal, ref ray.Direction, out Real direction); + Vector3.Dot(plane.Normal, ray.Direction, out Real direction); if (Mathf.IsZero(direction)) { distance = 0f; return false; } - Vector3.Dot(ref plane.Normal, ref ray.Position, out Real position); + Vector3.Dot(plane.Normal, ray.Position, out Real position); distance = (-plane.D - position) / direction; if (distance < 0f) { @@ -660,18 +660,18 @@ namespace FlaxEngine /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersect. [Obsolete("Use RayIntersectsPlane with 'out Real distance' parameter instead")] - public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out float distance) + public static bool RayIntersectsPlane(in Ray ray, in Plane plane, out float distance) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 175 - Vector3.Dot(ref plane.Normal, ref ray.Direction, out Real direction); + Vector3.Dot(plane.Normal, ray.Direction, out Real direction); if (Mathf.IsZero(direction)) { distance = 0f; return false; } - Vector3.Dot(ref plane.Normal, ref ray.Position, out Real position); + Vector3.Dot(plane.Normal, ray.Position, out Real position); distance = (float)((-plane.D - position) / direction); if (distance < 0f) { @@ -689,11 +689,11 @@ namespace FlaxEngine /// The plane to test /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out Vector3 point) + public static bool RayIntersectsPlane(in Ray ray, in Plane plane, out Vector3 point) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 175 - if (!RayIntersectsPlane(ref ray, ref plane, out Real distance)) + if (!RayIntersectsPlane(ray, plane, out Real distance)) { point = Vector3.Zero; return false; @@ -718,7 +718,7 @@ namespace FlaxEngine /// the ray, no intersection is assumed to have happened. In both cases of assumptions, /// this method returns false. /// - public static bool RayIntersectsTriangle(ref Ray ray, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Real distance) + public static bool RayIntersectsTriangle(in Ray ray, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3, out Real distance) { //Source: Fast Minimum Storage Ray / Triangle Intersection //Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf @@ -818,9 +818,9 @@ namespace FlaxEngine /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsTriangle(ref Ray ray, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 point) + public static bool RayIntersectsTriangle(in Ray ray, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3, out Vector3 point) { - if (!RayIntersectsTriangle(ref ray, ref vertex1, ref vertex2, ref vertex3, out Real distance)) + if (!RayIntersectsTriangle(ray, vertex1, vertex2, vertex3, out Real distance)) { point = Vector3.Zero; return false; @@ -837,7 +837,7 @@ namespace FlaxEngine /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// /// Whether the two objects intersected. - public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out Real distance) + public static bool RayIntersectsBox(in Ray ray, in BoundingBox box, out Real distance) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 179 @@ -948,9 +948,9 @@ namespace FlaxEngine /// The box to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out Vector3 point) + public static bool RayIntersectsBox(in Ray ray, in BoundingBox box, out Vector3 point) { - if (!RayIntersectsBox(ref ray, ref box, out Real distance)) + if (!RayIntersectsBox(ray, box, out Real distance)) { point = Vector3.Zero; return false; @@ -967,12 +967,12 @@ namespace FlaxEngine /// The sphere to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out Real distance) + public static bool RayIntersectsSphere(in Ray ray, in BoundingSphere sphere, out Real distance) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 177 - Vector3.Subtract(ref ray.Position, ref sphere.Center, out Vector3 m); + Vector3.Subtract(ray.Position, sphere.Center, out Vector3 m); Real b = Vector3.Dot(m, ray.Direction); Real c = Vector3.Dot(m, m) - sphere.Radius * sphere.Radius; @@ -1006,9 +1006,9 @@ namespace FlaxEngine /// The sphere to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out Vector3 point) + public static bool RayIntersectsSphere(in Ray ray, in BoundingSphere sphere, out Vector3 point) { - if (!RayIntersectsSphere(ref ray, ref sphere, out Real distance)) + if (!RayIntersectsSphere(ray, sphere, out Real distance)) { point = Vector3.Zero; return false; @@ -1024,9 +1024,9 @@ namespace FlaxEngine /// The plane to test. /// The point to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsPoint(ref Plane plane, ref Vector3 point) + public static PlaneIntersectionType PlaneIntersectsPoint(in Plane plane, in Vector3 point) { - Vector3.Dot(ref plane.Normal, ref point, out Real distance); + Vector3.Dot(plane.Normal, point, out Real distance); distance += plane.D; if (distance > 0f) @@ -1044,13 +1044,13 @@ namespace FlaxEngine /// The first plane to test. /// The second plane to test. /// Whether the two objects intersected. - public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2) + public static bool PlaneIntersectsPlane(in Plane plane1, in Plane plane2) { - Vector3.Cross(ref plane1.Normal, ref plane2.Normal, out Vector3 direction); + Vector3.Cross(plane1.Normal, plane2.Normal, out Vector3 direction); //If direction is the zero vector, the planes are parallel and possibly //coincident. It is not an intersection. The dot product will tell us. - Vector3.Dot(ref direction, ref direction, out Real denominator); + Vector3.Dot(direction, direction, out Real denominator); if (Mathf.IsZero(denominator)) return false; @@ -1070,16 +1070,16 @@ namespace FlaxEngine /// a line in three dimensions which has no real origin. The ray is considered valid when /// both the positive direction is used and when the negative direction is used. /// - public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2, out Ray line) + public static bool PlaneIntersectsPlane(in Plane plane1, in Plane plane2, out Ray line) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 207 - Vector3.Cross(ref plane1.Normal, ref plane2.Normal, out Vector3 direction); + Vector3.Cross(plane1.Normal, plane2.Normal, out Vector3 direction); //If direction is the zero vector, the planes are parallel and possibly //coincident. It is not an intersection. The dot product will tell us. - Vector3.Dot(ref direction, ref direction, out Real denominator); + Vector3.Dot(direction, direction, out Real denominator); //We assume the planes are normalized, therefore the denominator //only serves as a parallel and coincident check. Otherwise we need @@ -1091,7 +1091,7 @@ namespace FlaxEngine } Vector3 temp = plane1.D * plane2.Normal - plane2.D * plane1.Normal; - Vector3.Cross(ref temp, ref direction, out Vector3 point); + Vector3.Cross(temp, direction, out Vector3 point); line.Position = point; line.Direction = direction; @@ -1108,14 +1108,14 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsTriangle(ref Plane plane, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public static PlaneIntersectionType PlaneIntersectsTriangle(in Plane plane, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 207 - PlaneIntersectionType test1 = PlaneIntersectsPoint(ref plane, ref vertex1); - PlaneIntersectionType test2 = PlaneIntersectsPoint(ref plane, ref vertex2); - PlaneIntersectionType test3 = PlaneIntersectsPoint(ref plane, ref vertex3); + PlaneIntersectionType test1 = PlaneIntersectsPoint(plane, vertex1); + PlaneIntersectionType test2 = PlaneIntersectsPoint(plane, vertex2); + PlaneIntersectionType test3 = PlaneIntersectsPoint(plane, vertex3); if ((test1 == PlaneIntersectionType.Front) && (test2 == PlaneIntersectionType.Front) && (test3 == PlaneIntersectionType.Front)) return PlaneIntersectionType.Front; @@ -1132,7 +1132,7 @@ namespace FlaxEngine /// The plane to test. /// The box to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsBox(ref Plane plane, ref BoundingBox box) + public static PlaneIntersectionType PlaneIntersectsBox(in Plane plane, in BoundingBox box) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 161 @@ -1147,7 +1147,7 @@ namespace FlaxEngine min.Y = plane.Normal.Y >= 0.0f ? box.Maximum.Y : box.Minimum.Y; min.Z = plane.Normal.Z >= 0.0f ? box.Maximum.Z : box.Minimum.Z; - Vector3.Dot(ref plane.Normal, ref max, out Real distance); + Vector3.Dot(plane.Normal, max, out Real distance); if (distance + plane.D > 0.0f) return PlaneIntersectionType.Front; @@ -1166,12 +1166,12 @@ namespace FlaxEngine /// The plane to test. /// The sphere to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsSphere(ref Plane plane, ref BoundingSphere sphere) + public static PlaneIntersectionType PlaneIntersectsSphere(in Plane plane, in BoundingSphere sphere) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 160 - Vector3.Dot(ref plane.Normal, ref sphere.Center, out Real distance); + Vector3.Dot(plane.Normal, sphere.Center, out Real distance); distance += plane.D; if (distance > sphere.Radius) @@ -1192,7 +1192,7 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public static bool BoxIntersectsTriangle(ref BoundingBox box, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public static bool BoxIntersectsTriangle(in BoundingBox box, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { if (BoxContainsPoint(ref box, ref vertex1) == ContainmentType.Contains) return true; @@ -1213,7 +1213,7 @@ namespace FlaxEngine /// The first box to test. /// The second box to test. /// Whether the two objects intersected. - public static bool BoxIntersectsBox(ref BoundingBox box1, ref BoundingBox box2) + public static bool BoxIntersectsBox(in BoundingBox box1, in BoundingBox box2) { if ((box1.Minimum.X > box2.Maximum.X) || (box2.Minimum.X > box1.Maximum.X)) return false; @@ -1233,13 +1233,13 @@ namespace FlaxEngine /// The box to test. /// The sphere to test. /// Whether the two objects intersected. - public static bool BoxIntersectsSphere(ref BoundingBox box, ref BoundingSphere sphere) + public static bool BoxIntersectsSphere(in BoundingBox box, in BoundingSphere sphere) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 166 - Vector3.Clamp(ref sphere.Center, ref box.Minimum, ref box.Maximum, out Vector3 vector); - Real distance = Vector3.DistanceSquared(ref sphere.Center, ref vector); + Vector3.Clamp(sphere.Center, box.Minimum, box.Maximum, out Vector3 vector); + Real distance = Vector3.DistanceSquared(sphere.Center, vector); return distance <= sphere.Radius * sphere.Radius; } @@ -1251,15 +1251,15 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public static bool SphereIntersectsTriangle(ref BoundingSphere sphere, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public static bool SphereIntersectsTriangle(in BoundingSphere sphere, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 167 - ClosestPointPointTriangle(ref sphere.Center, ref vertex1, ref vertex2, ref vertex3, out Vector3 point); + ClosestPointPointTriangle(sphere.Center, vertex1, vertex2, vertex3, out Vector3 point); Vector3 v = point - sphere.Center; - Vector3.Dot(ref v, ref v, out Real dot); + Vector3.Dot(v, v, out Real dot); return dot <= sphere.Radius * sphere.Radius; } @@ -1271,10 +1271,10 @@ namespace FlaxEngine /// First sphere to test. /// Second sphere to test. /// Whether the two objects intersected. - public static bool SphereIntersectsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2) + public static bool SphereIntersectsSphere(in BoundingSphere sphere1, in BoundingSphere sphere2) { Real radiisum = sphere1.Radius + sphere2.Radius; - return Vector3.DistanceSquared(ref sphere1.Center, ref sphere2.Center) <= radiisum * radiisum; + return Vector3.DistanceSquared(sphere1.Center, sphere2.Center) <= radiisum * radiisum; } /// @@ -1283,7 +1283,7 @@ namespace FlaxEngine /// The box to test. /// The point to test. /// The type of containment the two objects have. - public static ContainmentType BoxContainsPoint(ref BoundingBox box, ref Vector3 point) + public static ContainmentType BoxContainsPoint(in BoundingBox box, in Vector3 point) { if ((box.Minimum.X <= point.X) && (box.Maximum.X >= point.X) && (box.Minimum.Y <= point.Y) && (box.Maximum.Y >= point.Y) && @@ -1302,7 +1302,7 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// The type of containment the two objects have. - public static ContainmentType BoxContainsTriangle(ref BoundingBox box, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public static ContainmentType BoxContainsTriangle(in BoundingBox box, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { ContainmentType test1 = BoxContainsPoint(ref box, ref vertex1); ContainmentType test2 = BoxContainsPoint(ref box, ref vertex2); @@ -1324,7 +1324,7 @@ namespace FlaxEngine /// The first box to test. /// The second box to test. /// The type of containment the two objects have. - public static ContainmentType BoxContainsBox(ref BoundingBox box1, ref BoundingBox box2) + public static ContainmentType BoxContainsBox(in BoundingBox box1, in BoundingBox box2) { if ((box1.Maximum.X < box2.Minimum.X) || (box1.Minimum.X > box2.Maximum.X)) return ContainmentType.Disjoint; @@ -1347,10 +1347,10 @@ namespace FlaxEngine /// The box to test. /// The sphere to test. /// The type of containment the two objects have. - public static ContainmentType BoxContainsSphere(ref BoundingBox box, ref BoundingSphere sphere) + public static ContainmentType BoxContainsSphere(in BoundingBox box, in BoundingSphere sphere) { - Vector3.Clamp(ref sphere.Center, ref box.Minimum, ref box.Maximum, out Vector3 vector); - Real distance = Vector3.DistanceSquared(ref sphere.Center, ref vector); + Vector3.Clamp(sphere.Center, box.Minimum, box.Maximum, out Vector3 vector); + Real distance = Vector3.DistanceSquared(sphere.Center, vector); if (distance > sphere.Radius * sphere.Radius) return ContainmentType.Disjoint; @@ -1367,9 +1367,9 @@ namespace FlaxEngine /// The sphere to test. /// The point to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsPoint(ref BoundingSphere sphere, ref Vector3 point) + public static ContainmentType SphereContainsPoint(in BoundingSphere sphere, in Vector3 point) { - if (Vector3.DistanceSquared(ref point, ref sphere.Center) <= sphere.Radius * sphere.Radius) + if (Vector3.DistanceSquared(point, sphere.Center) <= sphere.Radius * sphere.Radius) return ContainmentType.Contains; return ContainmentType.Disjoint; @@ -1383,19 +1383,19 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsTriangle(ref BoundingSphere sphere, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public static ContainmentType SphereContainsTriangle(in BoundingSphere sphere, in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { //Source: Jorgy343 //Reference: None - ContainmentType test1 = SphereContainsPoint(ref sphere, ref vertex1); - ContainmentType test2 = SphereContainsPoint(ref sphere, ref vertex2); - ContainmentType test3 = SphereContainsPoint(ref sphere, ref vertex3); + ContainmentType test1 = SphereContainsPoint(sphere, vertex1); + ContainmentType test2 = SphereContainsPoint(sphere, vertex2); + ContainmentType test3 = SphereContainsPoint(sphere, vertex3); if ((test1 == ContainmentType.Contains) && (test2 == ContainmentType.Contains) && (test3 == ContainmentType.Contains)) return ContainmentType.Contains; - if (SphereIntersectsTriangle(ref sphere, ref vertex1, ref vertex2, ref vertex3)) + if (SphereIntersectsTriangle(sphere, vertex1, vertex2, vertex3)) return ContainmentType.Intersects; return ContainmentType.Disjoint; @@ -1407,11 +1407,11 @@ namespace FlaxEngine /// The sphere to test. /// The box to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsBox(ref BoundingSphere sphere, ref BoundingBox box) + public static ContainmentType SphereContainsBox(in BoundingSphere sphere, in BoundingBox box) { Vector3 vector; - if (!BoxIntersectsSphere(ref box, ref sphere)) + if (!BoxIntersectsSphere(box, sphere)) return ContainmentType.Disjoint; Real radiusSquared = sphere.Radius * sphere.Radius; @@ -1473,9 +1473,9 @@ namespace FlaxEngine /// The first sphere to test. /// The second sphere to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2) + public static ContainmentType SphereContainsSphere(in BoundingSphere sphere1, in BoundingSphere sphere2) { - Real distance = Vector3.Distance(ref sphere1.Center, ref sphere2.Center); + Real distance = Vector3.Distance(sphere1.Center, sphere2.Center); if (sphere1.Radius + sphere2.Radius < distance) return ContainmentType.Disjoint; @@ -1494,7 +1494,7 @@ namespace FlaxEngine /// The second line point 0. /// The second line point 1. /// True if line intersects with the other line - public static bool LineIntersectsLine(ref Float2 l1p1, ref Float2 l1p2, ref Float2 l2p1, ref Float2 l2p2) + public static bool LineIntersectsLine(in Float2 l1p1, in Float2 l1p2, in Float2 l2p1, in Float2 l2p2) { float q = (l1p1.Y - l2p1.Y) * (l2p2.X - l2p1.X) - (l1p1.X - l2p1.X) * (l2p2.Y - l2p1.Y); float d = (l1p2.X - l1p1.X) * (l2p2.Y - l2p1.Y) - (l1p2.Y - l1p1.Y) * (l2p2.X - l2p1.X); @@ -1513,17 +1513,17 @@ namespace FlaxEngine /// The line point 1. /// The rectangle. /// True if line intersects with the rectangle - public static bool LineIntersectsRect(ref Float2 p1, ref Float2 p2, ref Rectangle rect) + public static bool LineIntersectsRect(in Float2 p1, in Float2 p2, in Rectangle rect) { // TODO: optimize it var pA = new Float2(rect.Right, rect.Y); var pB = new Float2(rect.Right, rect.Bottom); var pC = new Float2(rect.X, rect.Bottom); - return LineIntersectsLine(ref p1, ref p2, ref rect.Location, ref pA) || - LineIntersectsLine(ref p1, ref p2, ref pA, ref pB) || - LineIntersectsLine(ref p1, ref p2, ref pB, ref pC) || - LineIntersectsLine(ref p1, ref p2, ref pC, ref rect.Location) || - (rect.Contains(ref p1) && rect.Contains(ref p2)); + return LineIntersectsLine(in p1, in p2, in rect.Location, in pA) || + LineIntersectsLine(in p1, in p2, in pA, in pB) || + LineIntersectsLine(in p1, in p2, in pB, in pC) || + LineIntersectsLine(in p1, in p2, in pC, in rect.Location) || + (rect.Contains(p1) && rect.Contains(p2)); } /// @@ -1534,7 +1534,7 @@ namespace FlaxEngine /// The second vertex of the triangle. /// The third vertex of the triangle. /// true if point is inside the triangle; otherwise, false. - public static bool IsPointInTriangle(ref Float2 point, ref Float2 a, ref Float2 b, ref Float2 c) + public static bool IsPointInTriangle(in Float2 point, in Float2 a, in Float2 b, in Float2 c) { var an = a - point; var bn = b - point; diff --git a/Source/Engine/Core/Math/Color.cs b/Source/Engine/Core/Math/Color.cs index 2d779dcfa..7d9071b4c 100644 --- a/Source/Engine/Core/Math/Color.cs +++ b/Source/Engine/Core/Math/Color.cs @@ -199,7 +199,7 @@ namespace FlaxEngine /// public override bool Equals(object value) { - return value is Color other && Equals(ref other); + return value is Color other && Equals(in other); } /// @@ -208,7 +208,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Color other) + public bool Equals(in Color other) { return R == other.R && G == other.G && B == other.B && A == other.A; } @@ -628,7 +628,7 @@ namespace FlaxEngine /// Color b /// Float for combining a and b /// The result. - public static void Lerp(ref Color a, ref Color b, float t, out Color result) + public static void Lerp(in Color a, in Color b, float t, out Color result) { result = new Color(a.R + (b.R - a.R) * t, a.G + (b.G - a.G) * t, a.B + (b.B - a.B) * t, a.A + (b.A - a.A) * t); } @@ -663,7 +663,7 @@ namespace FlaxEngine /// True if colors are equal, otherwise false. public static bool operator ==(Color left, Color right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -674,7 +674,7 @@ namespace FlaxEngine /// True if colors are not equal, otherwise false. public static bool operator !=(Color left, Color right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -910,7 +910,7 @@ namespace FlaxEngine /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// When the method completes, contains the adjusted color. - public static void AdjustContrast(ref Color value, float contrast, out Color result) + public static void AdjustContrast(in Color value, float contrast, out Color result) { result.A = value.A; result.R = 0.5f + contrast * (value.R - 0.5f); @@ -939,7 +939,7 @@ namespace FlaxEngine /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// When the method completes, contains the adjusted color. - public static void AdjustSaturation(ref Color value, float saturation, out Color result) + public static void AdjustSaturation(in Color value, float saturation, out Color result) { float grey = value.R * 0.2125f + value.G * 0.7154f + value.B * 0.0721f; @@ -982,7 +982,7 @@ namespace FlaxEngine /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the largest components of the source colors. - public static void Max(ref Color left, ref Color right, out Color result) + public static void Max(in Color left, in Color right, out Color result) { result = new Color( Mathf.Max(left.R, right.R), @@ -1000,7 +1000,7 @@ namespace FlaxEngine /// A color containing the largest components of the source colors. public static Color Max(Color left, Color right) { - Max(ref left, ref right, out var result); + Max(in left, in right, out var result); return result; } @@ -1010,7 +1010,7 @@ namespace FlaxEngine /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the smallest components of the source colors. - public static void Min(ref Color left, ref Color right, out Color result) + public static void Min(in Color left, in Color right, out Color result) { result = new Color( Mathf.Min(left.R, right.R), @@ -1028,7 +1028,7 @@ namespace FlaxEngine /// A color containing the smallest components of the source colors. public static Color Min(Color left, Color right) { - Min(ref left, ref right, out var result); + Min(in left, in right, out var result); return result; } @@ -1039,7 +1039,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Color value, ref Color min, ref Color max, out Color result) + public static void Clamp(in Color value, in Color min, in Color max, out Color result) { result = new Color( Mathf.Clamp(value.R, min.R, max.R), @@ -1058,7 +1058,7 @@ namespace FlaxEngine /// The clamped value. public static Color Clamp(Color value, Color min, Color max) { - Clamp(ref value, ref min, ref max, out Color result); + Clamp(in value, in min, in max, out Color result); return result; } diff --git a/Source/Engine/Core/Math/Double2.cs b/Source/Engine/Core/Math/Double2.cs index 9594b22cb..248cae252 100644 --- a/Source/Engine/Core/Math/Double2.cs +++ b/Source/Engine/Core/Math/Double2.cs @@ -291,7 +291,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Double2 left, ref Double2 right, out Double2 result) + public static void Add(in Double2 left, in Double2 right, out Double2 result) { result = new Double2(left.X + right.X, left.Y + right.Y); } @@ -313,7 +313,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Double2 left, ref double right, out Double2 result) + public static void Add(in Double2 left, double right, out Double2 result) { result = new Double2(left.X + right, left.Y + right); } @@ -335,7 +335,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Double2 left, ref Double2 right, out Double2 result) + public static void Subtract(in Double2 left, in Double2 right, out Double2 result) { result = new Double2(left.X - right.X, left.Y - right.Y); } @@ -357,7 +357,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Double2 left, ref double right, out Double2 result) + public static void Subtract(in Double2 left, double right, out Double2 result) { result = new Double2(left.X - right, left.Y - right); } @@ -379,7 +379,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector /// The vector with subtracted scalar for each element. - public static void Subtract(ref double left, ref Double2 right, out Double2 result) + public static void Subtract(double left, in Double2 right, out Double2 result) { result = new Double2(left - right.X, left - right.Y); } @@ -401,7 +401,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Double2 value, double scale, out Double2 result) + public static void Multiply(in Double2 value, double scale, out Double2 result) { result = new Double2(value.X * scale, value.Y * scale); } @@ -423,7 +423,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Double2 left, ref Double2 right, out Double2 result) + public static void Multiply(in Double2 left, in Double2 right, out Double2 result) { result = new Double2(left.X * right.X, left.Y * right.Y); } @@ -445,7 +445,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Double2 value, double scale, out Double2 result) + public static void Divide(in Double2 value, double scale, out Double2 result) { result = new Double2(value.X / scale, value.Y / scale); } @@ -467,7 +467,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(double scale, ref Double2 value, out Double2 result) + public static void Divide(double scale, in Double2 value, out Double2 result) { result = new Double2(scale / value.X, scale / value.Y); } @@ -488,7 +488,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Double2 value, out Double2 result) + public static void Negate(in Double2 value, out Double2 result) { result = new Double2(-value.X, -value.Y); } @@ -513,7 +513,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 2D Cartesian coordinates of the specified point. - public static void Barycentric(ref Double2 value1, ref Double2 value2, ref Double2 value3, double amount1, double amount2, out Double2 result) + public static void Barycentric(in Double2 value1, in Double2 value2, in Double2 value3, double amount1, double amount2, out Double2 result) { result = new Double2(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y)); @@ -531,7 +531,7 @@ namespace FlaxEngine /// A new containing the 2D Cartesian coordinates of the specified point. public static Double2 Barycentric(Double2 value1, Double2 value2, Double2 value3, double amount1, double amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out Double2 result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out Double2 result); return result; } @@ -542,7 +542,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Double2 value, ref Double2 min, ref Double2 max, out Double2 result) + public static void Clamp(in Double2 value, in Double2 min, in Double2 max, out Double2 result) { double x = value.X; x = x > max.X ? max.X : x; @@ -562,7 +562,7 @@ namespace FlaxEngine /// The clamped value. public static Double2 Clamp(Double2 value, Double2 min, Double2 max) { - Clamp(ref value, ref min, ref max, out Double2 result); + Clamp(in value, in min, in max, out Double2 result); return result; } @@ -582,7 +582,7 @@ namespace FlaxEngine /// The second triangle vertex. /// The third triangle vertex. /// The triangle area. - public static double TriangleArea(ref Double2 v0, ref Double2 v1, ref Double2 v2) + public static double TriangleArea(in Double2 v0, in Double2 v1, in Double2 v2) { return Math.Abs((v0.X * (v1.Y - v2.Y) + v1.X * (v2.Y - v0.Y) + v2.X * (v0.Y - v1.Y)) / 2); } @@ -593,8 +593,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Double2 value1, ref Double2 value2, out double result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Double2 value1, in Double2 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -621,8 +621,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static double Distance(ref Double2 value1, ref Double2 value2) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static double Distance(in Double2 value1, in Double2 value2) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -635,7 +635,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Double2 value1, ref Double2 value2, out double result) + public static void DistanceSquared(in Double2 value1, in Double2 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -648,7 +648,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// The squared distance between the two vectors. - public static double DistanceSquared(ref Double2 value1, ref Double2 value2) + public static double DistanceSquared(in Double2 value1, in Double2 value2) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -677,7 +677,7 @@ namespace FlaxEngine /// true if left and right are near, false otherwise public static bool NearEqual(Double2 left, Double2 right, double epsilon = Mathd.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -687,7 +687,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Double2 left, ref Double2 right, double epsilon = Mathd.Epsilon) + public static bool NearEqual(in Double2 left, in Double2 right, double epsilon = Mathd.Epsilon) { return Mathd.WithinEpsilon(left.X, right.X, epsilon) && Mathd.WithinEpsilon(left.Y, right.Y, epsilon); } @@ -698,7 +698,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Double2 left, ref Double2 right, out double result) + public static void Dot(in Double2 left, in Double2 right, out double result) { result = left.X * right.X + left.Y * right.Y; } @@ -709,7 +709,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The dot product of the two vectors. - public static double Dot(ref Double2 left, ref Double2 right) + public static double Dot(in Double2 left, in Double2 right) { return left.X * right.X + left.Y * right.Y; } @@ -731,7 +731,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the cross product of the two vectors. - public static void Cross(ref Double2 left, ref Double2 right, out double result) + public static void Cross(in Double2 left, in Double2 right, out double result) { result = left.X * right.Y - left.Y * right.X; } @@ -742,7 +742,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The cross product of the two vectors. - public static double Cross(ref Double2 left, ref Double2 right) + public static double Cross(in Double2 left, in Double2 right) { return left.X * right.Y - left.Y * right.X; } @@ -763,7 +763,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Double2 value, out Double2 result) + public static void Normalize(in Double2 value, out Double2 result) { result = value; result.Normalize(); @@ -865,7 +865,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Double2 start, ref Double2 end, double amount, out Double2 result) + public static void Lerp(in Double2 start, in Double2 end, double amount, out Double2 result) { result.X = Mathd.Lerp(start.X, end.X, amount); result.Y = Mathd.Lerp(start.Y, end.Y, amount); @@ -881,7 +881,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Double2 Lerp(Double2 start, Double2 end, double amount) { - Lerp(ref start, ref end, amount, out Double2 result); + Lerp(in start, in end, amount, out Double2 result); return result; } @@ -893,7 +893,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Double2 start, ref Double2 end, ref Double2 amount, out Double2 result) + public static void Lerp(in Double2 start, in Double2 end, in Double2 amount, out Double2 result) { result.X = Mathd.Lerp(start.X, end.X, amount.X); result.Y = Mathd.Lerp(start.Y, end.Y, amount.Y); @@ -909,7 +909,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Double2 Lerp(Double2 start, Double2 end, Double2 amount) { - Lerp(ref start, ref end, ref amount, out Double2 result); + Lerp(in start, in end, in amount, out Double2 result); return result; } @@ -920,10 +920,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Double2 start, ref Double2 end, double amount, out Double2 result) + public static void SmoothStep(in Double2 start, in Double2 end, double amount, out Double2 result) { amount = Mathd.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -935,7 +935,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Double2 SmoothStep(Double2 start, Double2 end, double amount) { - SmoothStep(ref start, ref end, amount, out Double2 result); + SmoothStep(in start, in end, amount, out Double2 result); return result; } @@ -948,7 +948,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Double2 value1, ref Double2 tangent1, ref Double2 value2, ref Double2 tangent2, double amount, out Double2 result) + public static void Hermite(in Double2 value1, in Double2 tangent1, in Double2 value2, in Double2 tangent2, double amount, out Double2 result) { double squared = amount * amount; double cubed = amount * squared; @@ -971,7 +971,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Double2 Hermite(Double2 value1, Double2 tangent1, Double2 value2, Double2 tangent2, double amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out Double2 result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out Double2 result); return result; } @@ -990,7 +990,7 @@ namespace FlaxEngine /// /// The in direction. /// When the method completes, contains the result of the calculation. - public static void Perpendicular(ref Double2 inDirection, out Double2 result) + public static void Perpendicular(in Double2 inDirection, out Double2 result) { result = new Double2(-inDirection.Y, inDirection.X); } @@ -1004,7 +1004,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Double2 value1, ref Double2 value2, ref Double2 value3, ref Double2 value4, double amount, out Double2 result) + public static void CatmullRom(in Double2 value1, in Double2 value2, in Double2 value3, in Double2 value4, double amount, out Double2 result) { double squared = amount * amount; double cubed = amount * squared; @@ -1027,7 +1027,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Double2 CatmullRom(Double2 value1, Double2 value2, Double2 value3, Double2 value4, double amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out Double2 result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out Double2 result); return result; } @@ -1037,7 +1037,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Double2 left, ref Double2 right, out Double2 result) + public static void Max(in Double2 left, in Double2 right, out Double2 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -1051,7 +1051,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Double2 Max(Double2 left, Double2 right) { - Max(ref left, ref right, out Double2 result); + Max(in left, in right, out Double2 result); return result; } @@ -1061,7 +1061,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Double2 left, ref Double2 right, out Double2 result) + public static void Min(in Double2 left, in Double2 right, out Double2 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -1075,7 +1075,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Double2 Min(Double2 left, Double2 right) { - Min(ref left, ref right, out Double2 result); + Min(in left, in right, out Double2 result); return result; } @@ -1096,7 +1096,7 @@ namespace FlaxEngine /// Normal of the surface. /// When the method completes, contains the reflected vector. /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Double2 vector, ref Double2 normal, out Double2 result) + public static void Reflect(in Double2 vector, in Double2 normal, out Double2 result) { double dot = vector.X * normal.X + vector.Y * normal.Y; result.X = vector.X - 2.0 * dot * normal.X; @@ -1112,7 +1112,7 @@ namespace FlaxEngine /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. public static Double2 Reflect(Double2 vector, Double2 normal) { - Reflect(ref vector, ref normal, out Double2 result); + Reflect(in vector, in normal, out Double2 result); return result; } @@ -1122,7 +1122,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Double2 vector, ref Quaternion rotation, out Double2 result) + public static void Transform(in Double2 vector, in Quaternion rotation, out Double2 result) { double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -1143,7 +1143,7 @@ namespace FlaxEngine /// The transformed . public static Double2 Transform(Double2 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out Double2 result); + Transform(in vector, in rotation, out Double2 result); return result; } @@ -1153,7 +1153,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double2 vector, ref Matrix transform, out Double4 result) + public static void Transform(in Double2 vector, in Matrix transform, out Double4 result) { result = new Double4(vector.X * transform.M11 + vector.Y * transform.M21 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + transform.M42, @@ -1169,7 +1169,7 @@ namespace FlaxEngine /// The transformed . public static Double4 Transform(Double2 vector, Matrix transform) { - Transform(ref vector, ref transform, out Double4 result); + Transform(in vector, in transform, out Double4 result); return result; } @@ -1186,7 +1186,7 @@ namespace FlaxEngine /// therefore makes the vector homogeneous. The homogeneous vector is often preferred when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Double2 coordinate, ref Matrix transform, out Double2 result) + public static void TransformCoordinate(in Double2 coordinate, in Matrix transform, out Double2 result) { var vector = new Double4 { @@ -1213,7 +1213,7 @@ namespace FlaxEngine /// public static Double2 TransformCoordinate(Double2 coordinate, Matrix transform) { - TransformCoordinate(ref coordinate, ref transform, out Double2 result); + TransformCoordinate(in coordinate, in transform, out Double2 result); return result; } @@ -1230,7 +1230,7 @@ namespace FlaxEngine /// apply. This is often preferred for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Double2 normal, ref Matrix transform, out Double2 result) + public static void TransformNormal(in Double2 normal, in Matrix transform, out Double2 result) { result = new Double2(normal.X * transform.M11 + normal.Y * transform.M21, normal.X * transform.M12 + normal.Y * transform.M22); @@ -1251,7 +1251,7 @@ namespace FlaxEngine /// public static Double2 TransformNormal(Double2 normal, Matrix transform) { - TransformNormal(ref normal, ref transform, out Double2 result); + TransformNormal(in normal, in transform, out Double2 result); return result; } @@ -1282,7 +1282,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1464,7 +1464,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Double2 left, Double2 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1476,7 +1476,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Double2 left, Double2 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1580,7 +1580,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Double2 other) + public bool Equals(in Double2 other) { return X == other.X && Y == other.Y; } @@ -1588,9 +1588,9 @@ namespace FlaxEngine /// /// Determines whether the specified are equal. /// - public static bool Equals(ref Double2 a, ref Double2 b) + public static bool Equals(in Double2 a, in Double2 b) { - return a.Equals(ref b); + return a.Equals(in b); } /// @@ -1601,7 +1601,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Double2 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1611,7 +1611,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Double2 other && Equals(ref other); + return value is Double2 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Double3.cs b/Source/Engine/Core/Math/Double3.cs index cb26cf071..375366ab5 100644 --- a/Source/Engine/Core/Math/Double3.cs +++ b/Source/Engine/Core/Math/Double3.cs @@ -380,7 +380,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Double3 left, ref Double3 right, out Double3 result) + public static void Add(in Double3 left, in Double3 right, out Double3 result) { result = new Double3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); } @@ -402,7 +402,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Double3 left, ref double right, out Double3 result) + public static void Add(in Double3 left, double right, out Double3 result) { result = new Double3(left.X + right, left.Y + right, left.Z + right); } @@ -424,7 +424,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Double3 left, ref Double3 right, out Double3 result) + public static void Subtract(in Double3 left, in Double3 right, out Double3 result) { result = new Double3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); } @@ -446,7 +446,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Double3 left, ref double right, out Double3 result) + public static void Subtract(in Double3 left, double right, out Double3 result) { result = new Double3(left.X - right, left.Y - right, left.Z - right); } @@ -468,7 +468,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref double left, ref Double3 right, out Double3 result) + public static void Subtract(double left, in Double3 right, out Double3 result) { result = new Double3(left - right.X, left - right.Y, left - right.Z); } @@ -490,7 +490,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Double3 value, double scale, out Double3 result) + public static void Multiply(in Double3 value, double scale, out Double3 result) { result = new Double3(value.X * scale, value.Y * scale, value.Z * scale); } @@ -512,7 +512,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Double3 left, ref Double3 right, out Double3 result) + public static void Multiply(in Double3 left, in Double3 right, out Double3 result) { result = new Double3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); } @@ -534,7 +534,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector (per component). /// When the method completes, contains the divided vector. - public static void Divide(ref Double3 value, ref Double3 scale, out Double3 result) + public static void Divide(in Double3 value, in Double3 scale, out Double3 result) { result = new Double3(value.X / scale.X, value.Y / scale.Y, value.Z / scale.Z); } @@ -556,7 +556,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Double3 value, double scale, out Double3 result) + public static void Divide(in Double3 value, double scale, out Double3 result) { result = new Double3(value.X / scale, value.Y / scale, value.Z / scale); } @@ -578,7 +578,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(double scale, ref Double3 value, out Double3 result) + public static void Divide(double scale, in Double3 value, out Double3 result) { result = new Double3(scale / value.X, scale / value.Y, scale / value.Z); } @@ -599,7 +599,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Double3 value, out Double3 result) + public static void Negate(in Double3 value, out Double3 result) { result = new Double3(-value.X, -value.Y, -value.Z); } @@ -623,7 +623,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 3D Cartesian coordinates of the specified point. - public static void Barycentric(ref Double3 value1, ref Double3 value2, ref Double3 value3, double amount1, double amount2, out Double3 result) + public static void Barycentric(in Double3 value1, in Double3 value2, in Double3 value3, double amount1, double amount2, out Double3 result) { result = new Double3(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y), @@ -641,7 +641,7 @@ namespace FlaxEngine /// A new containing the 3D Cartesian coordinates of the specified point. public static Double3 Barycentric(Double3 value1, Double3 value2, Double3 value3, double amount1, double amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out var result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out var result); return result; } @@ -652,7 +652,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Double3 value, ref Double3 min, ref Double3 max, out Double3 result) + public static void Clamp(in Double3 value, in Double3 min, in Double3 max, out Double3 result) { double x = value.X; x = x > max.X ? max.X : x; @@ -675,7 +675,7 @@ namespace FlaxEngine /// The clamped value. public static Double3 Clamp(Double3 value, Double3 min, Double3 max) { - Clamp(ref value, ref min, ref max, out var result); + Clamp(in value, in min, in max, out var result); return result; } @@ -685,7 +685,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains he cross product of the two vectors. - public static void Cross(ref Double3 left, ref Double3 right, out Double3 result) + public static void Cross(in Double3 left, in Double3 right, out Double3 result) { result = new Double3(left.Y * right.Z - left.Z * right.Y, left.Z * right.X - left.X * right.Z, @@ -700,7 +700,7 @@ namespace FlaxEngine /// The cross product of the two vectors. public static Double3 Cross(Double3 left, Double3 right) { - Cross(ref left, ref right, out var result); + Cross(in left, in right, out var result); return result; } @@ -710,8 +710,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Double3 value1, ref Double3 value2, out double result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Double3 value1, in Double3 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -725,8 +725,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static double Distance(ref Double3 value1, ref Double3 value2) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static double Distance(in Double3 value1, in Double3 value2) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -755,7 +755,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceSquared(in Double3 value1, in Double3 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -769,7 +769,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The squared distance between the two vectors. - public static double DistanceSquared(ref Double3 value1, ref Double3 value2) + public static double DistanceSquared(in Double3 value1, in Double3 value2) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -797,7 +797,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the XY plane. - public static void DistanceXY(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceXY(in Double3 value1, in Double3 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -810,7 +810,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the XY plane. - public static void DistanceXYSquared(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceXYSquared(in Double3 value1, in Double3 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -823,7 +823,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the XY plane. - public static void DistanceXZ(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceXZ(in Double3 value1, in Double3 value2, out double result) { double x = value1.X - value2.X; double z = value1.Z - value2.Z; @@ -836,7 +836,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the XY plane. - public static void DistanceXZSquared(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceXZSquared(in Double3 value1, in Double3 value2, out double result) { double x = value1.X - value2.X; double z = value1.Z - value2.Z; @@ -849,7 +849,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the YZ plane. - public static void DistanceYZ(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceYZ(in Double3 value1, in Double3 value2, out double result) { double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; @@ -862,7 +862,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the YZ plane. - public static void DistanceYZSquared(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceYZSquared(in Double3 value1, in Double3 value2, out double result) { double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; @@ -878,7 +878,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Double3 left, Double3 right, double epsilon = Mathd.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -888,7 +888,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Double3 left, ref Double3 right, double epsilon = Mathd.Epsilon) + public static bool NearEqual(in Double3 left, in Double3 right, double epsilon = Mathd.Epsilon) { return Mathd.WithinEpsilon(left.X, right.X, epsilon) && Mathd.WithinEpsilon(left.Y, right.Y, epsilon) && Mathd.WithinEpsilon(left.Z, right.Z, epsilon); } @@ -899,7 +899,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Double3 left, ref Double3 right, out double result) + public static void Dot(in Double3 left, in Double3 right, out double result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z; } @@ -910,7 +910,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The dot product of the two vectors. - public static double Dot(ref Double3 left, ref Double3 right) + public static double Dot(in Double3 left, in Double3 right) { return left.X * right.X + left.Y * right.Y + left.Z * right.Z; } @@ -931,7 +931,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Double3 value, out Double3 result) + public static void Normalize(in Double3 value, out Double3 result) { result = value; result.Normalize(); @@ -1007,7 +1007,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Double3 start, ref Double3 end, double amount, out Double3 result) + public static void Lerp(in Double3 start, in Double3 end, double amount, out Double3 result) { result.X = Mathd.Lerp(start.X, end.X, amount); result.Y = Mathd.Lerp(start.Y, end.Y, amount); @@ -1024,7 +1024,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Double3 Lerp(Double3 start, Double3 end, double amount) { - Lerp(ref start, ref end, amount, out var result); + Lerp(in start, in end, amount, out var result); return result; } @@ -1035,10 +1035,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Double3 start, ref Double3 end, double amount, out Double3 result) + public static void SmoothStep(in Double3 start, in Double3 end, double amount, out Double3 result) { amount = Mathd.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -1050,7 +1050,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Double3 SmoothStep(Double3 start, Double3 end, double amount) { - SmoothStep(ref start, ref end, amount, out var result); + SmoothStep(in start, in end, amount, out var result); return result; } @@ -1080,7 +1080,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Double3 value1, ref Double3 tangent1, ref Double3 value2, ref Double3 tangent2, double amount, out Double3 result) + public static void Hermite(in Double3 value1, in Double3 tangent1, in Double3 value2, in Double3 tangent2, double amount, out Double3 result) { double squared = amount * amount; double cubed = amount * squared; @@ -1104,7 +1104,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Double3 Hermite(Double3 value1, Double3 tangent1, Double3 value2, Double3 tangent2, double amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out var result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out var result); return result; } @@ -1117,7 +1117,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Double3 value1, ref Double3 value2, ref Double3 value3, ref Double3 value4, double amount, out Double3 result) + public static void CatmullRom(in Double3 value1, in Double3 value2, in Double3 value3, in Double3 value4, double amount, out Double3 result) { double squared = amount * amount; double cubed = amount * squared; @@ -1143,7 +1143,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Double3 CatmullRom(Double3 value1, Double3 value2, Double3 value3, Double3 value4, double amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out var result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out var result); return result; } @@ -1153,7 +1153,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Double3 left, ref Double3 right, out Double3 result) + public static void Max(in Double3 left, in Double3 right, out Double3 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -1168,7 +1168,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Double3 Max(Double3 left, Double3 right) { - Max(ref left, ref right, out var result); + Max(in left, in right, out var result); return result; } @@ -1178,7 +1178,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Double3 left, ref Double3 right, out Double3 result) + public static void Min(in Double3 left, in Double3 right, out Double3 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -1193,7 +1193,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Double3 Min(Double3 left, Double3 right) { - Min(ref left, ref right, out var result); + Min(in left, in right, out var result); return result; } @@ -1258,9 +1258,9 @@ namespace FlaxEngine /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in screen space. - public static void Project(ref Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result) + public static void Project(in Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result) { - TransformCoordinate(ref vector, ref worldViewProjection, out var v); + TransformCoordinate(in vector, in worldViewProjection, out var v); result = new Double3((1.0 + v.X) * 0.5f * width + x, (1.0 - v.Y) * 0.5f * height + y, v.Z * (maxZ - minZ) + minZ); } @@ -1278,7 +1278,7 @@ namespace FlaxEngine /// The vector in screen space. public static Double3 Project(Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, Matrix worldViewProjection) { - Project(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); + Project(in vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); return result; } @@ -1294,16 +1294,16 @@ namespace FlaxEngine /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in object space. - public static void Unproject(ref Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result) + public static void Unproject(in Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result) { - Matrix.Invert(ref worldViewProjection, out var matrix); + Matrix.Invert(worldViewProjection, out var matrix); var v = new Double3 { X = (vector.X - x) / width * 2.0 - 1.0, Y = -((vector.Y - y) / height * 2.0 - 1.0), Z = (vector.Z - minZ) / (maxZ - minZ) }; - TransformCoordinate(ref v, ref matrix, out result); + TransformCoordinate(in v, in matrix, out result); } /// @@ -1320,7 +1320,7 @@ namespace FlaxEngine /// The vector in object space. public static Double3 Unproject(Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, Matrix worldViewProjection) { - Unproject(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); + Unproject(in vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); return result; } @@ -1331,7 +1331,7 @@ namespace FlaxEngine /// Normal of the surface. /// When the method completes, contains the reflected vector. /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Double3 vector, ref Double3 normal, out Double3 result) + public static void Reflect(in Double3 vector, in Double3 normal, out Double3 result) { double dot = vector.X * normal.X + vector.Y * normal.Y + vector.Z * normal.Z; result.X = vector.X - 2.0 * dot * normal.X; @@ -1348,7 +1348,7 @@ namespace FlaxEngine /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. public static Double3 Reflect(Double3 vector, Double3 normal) { - Reflect(ref vector, ref normal, out var result); + Reflect(in vector, in normal, out var result); return result; } @@ -1358,7 +1358,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Double3 vector, ref Quaternion rotation, out Double3 result) + public static void Transform(in Double3 vector, in Quaternion rotation, out Double3 result) { double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -1385,7 +1385,7 @@ namespace FlaxEngine /// The transformed . public static Double3 Transform(Double3 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out var result); + Transform(in vector, in rotation, out var result); return result; } @@ -1395,7 +1395,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double3 vector, ref Matrix3x3 transform, out Double3 result) + public static void Transform(in Double3 vector, in Matrix3x3 transform, out Double3 result) { result = new Double3((vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31), (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32), @@ -1410,7 +1410,7 @@ namespace FlaxEngine /// The transformed . public static Double3 Transform(Double3 vector, Matrix3x3 transform) { - Transform(ref vector, ref transform, out var result); + Transform(in vector, in transform, out var result); return result; } @@ -1420,7 +1420,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double3 vector, ref Matrix transform, out Double3 result) + public static void Transform(in Double3 vector, in Matrix transform, out Double3 result) { result = new Double3(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + transform.M42, @@ -1433,7 +1433,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double3 vector, ref Matrix transform, out Double4 result) + public static void Transform(in Double3 vector, in Matrix transform, out Double4 result) { result = new Double4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + transform.M42, @@ -1449,7 +1449,7 @@ namespace FlaxEngine /// The transformed . public static Double3 Transform(Double3 vector, Matrix transform) { - Transform(ref vector, ref transform, out Double3 result); + Transform(in vector, in transform, out Double3 result); return result; } @@ -1466,7 +1466,7 @@ namespace FlaxEngine /// therefore makes the vector homogeneous. The homogeneous vector is often preferred when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Double3 coordinate, ref Matrix transform, out Double3 result) + public static void TransformCoordinate(in Double3 coordinate, in Matrix transform, out Double3 result) { var vector = new Double4 { @@ -1493,7 +1493,7 @@ namespace FlaxEngine /// public static Double3 TransformCoordinate(Double3 coordinate, Matrix transform) { - TransformCoordinate(ref coordinate, ref transform, out var result); + TransformCoordinate(in coordinate, in transform, out var result); return result; } @@ -1510,7 +1510,7 @@ namespace FlaxEngine /// apply. This is often preferred for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Double3 normal, ref Matrix transform, out Double3 result) + public static void TransformNormal(in Double3 normal, in Matrix transform, out Double3 result) { result = new Double3(normal.X * transform.M11 + normal.Y * transform.M21 + normal.Z * transform.M31, normal.X * transform.M12 + normal.Y * transform.M22 + normal.Z * transform.M32, @@ -1532,7 +1532,7 @@ namespace FlaxEngine /// public static Double3 TransformNormal(Double3 normal, Matrix transform) { - TransformNormal(ref normal, ref transform, out var result); + TransformNormal(in normal, in transform, out var result); return result; } @@ -1565,7 +1565,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1614,7 +1614,7 @@ namespace FlaxEngine /// The scaled vector. public static Double3 operator *(Double3 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out var result); + Transform(in vector, in rotation, out var result); return result; } @@ -1759,7 +1759,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Double3 left, Double3 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1771,7 +1771,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Double3 left, Double3 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1878,7 +1878,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Double3 other) + public bool Equals(in Double3 other) { return X == other.X && Y == other.Y && Z == other.Z; } @@ -1891,7 +1891,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Double3 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1901,7 +1901,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Double3 other && Equals(ref other); + return value is Double3 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Double4.cs b/Source/Engine/Core/Math/Double4.cs index 70d27cb28..e376f6c11 100644 --- a/Source/Engine/Core/Math/Double4.cs +++ b/Source/Engine/Core/Math/Double4.cs @@ -348,7 +348,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Double4 left, ref Double4 right, out Double4 result) + public static void Add(in Double4 left, in Double4 right, out Double4 result) { result = new Double4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); } @@ -370,7 +370,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Double4 left, ref double right, out Double4 result) + public static void Add(in Double4 left, double right, out Double4 result) { result = new Double4(left.X + right, left.Y + right, left.Z + right, left.W + right); } @@ -392,7 +392,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Double4 left, ref Double4 right, out Double4 result) + public static void Subtract(in Double4 left, in Double4 right, out Double4 result) { result = new Double4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); } @@ -414,7 +414,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Double4 left, ref double right, out Double4 result) + public static void Subtract(in Double4 left, double right, out Double4 result) { result = new Double4(left.X - right, left.Y - right, left.Z - right, left.W - right); } @@ -436,7 +436,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref double left, ref Double4 right, out Double4 result) + public static void Subtract(double left, in Double4 right, out Double4 result) { result = new Double4(left - right.X, left - right.Y, left - right.Z, left - right.W); } @@ -458,7 +458,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Double4 value, double scale, out Double4 result) + public static void Multiply(in Double4 value, double scale, out Double4 result) { result = new Double4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); } @@ -480,7 +480,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Double4 left, ref Double4 right, out Double4 result) + public static void Multiply(in Double4 left, in Double4 right, out Double4 result) { result = new Double4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); } @@ -502,7 +502,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Double4 value, double scale, out Double4 result) + public static void Divide(in Double4 value, double scale, out Double4 result) { result = new Double4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); } @@ -524,7 +524,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(double scale, ref Double4 value, out Double4 result) + public static void Divide(double scale, in Double4 value, out Double4 result) { result = new Double4(scale / value.X, scale / value.Y, scale / value.Z, scale / value.W); } @@ -545,7 +545,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Double4 value, out Double4 result) + public static void Negate(in Double4 value, out Double4 result) { result = new Double4(-value.X, -value.Y, -value.Z, -value.W); } @@ -569,7 +569,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 4D Cartesian coordinates of the specified point. - public static void Barycentric(ref Double4 value1, ref Double4 value2, ref Double4 value3, double amount1, double amount2, out Double4 result) + public static void Barycentric(in Double4 value1, in Double4 value2, in Double4 value3, double amount1, double amount2, out Double4 result) { result = new Double4(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y), @@ -588,7 +588,7 @@ namespace FlaxEngine /// A new containing the 4D Cartesian coordinates of the specified point. public static Double4 Barycentric(Double4 value1, Double4 value2, Double4 value3, double amount1, double amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out Double4 result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out Double4 result); return result; } @@ -599,7 +599,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Double4 value, ref Double4 min, ref Double4 max, out Double4 result) + public static void Clamp(in Double4 value, in Double4 min, in Double4 max, out Double4 result) { double x = value.X; x = x > max.X ? max.X : x; @@ -625,7 +625,7 @@ namespace FlaxEngine /// The clamped value. public static Double4 Clamp(Double4 value, Double4 min, Double4 max) { - Clamp(ref value, ref min, ref max, out Double4 result); + Clamp(in value, in min, in max, out Double4 result); return result; } @@ -635,8 +635,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Double4 value1, ref Double4 value2, out double result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Double4 value1, in Double4 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -667,7 +667,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Double4 value1, ref Double4 value2, out double result) + public static void DistanceSquared(in Double4 value1, in Double4 value2, out double result) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; @@ -700,7 +700,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Double4 left, Double4 right, double epsilon = Mathd.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -710,7 +710,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Double4 left, ref Double4 right, double epsilon = Mathd.Epsilon) + public static bool NearEqual(in Double4 left, in Double4 right, double epsilon = Mathd.Epsilon) { return Mathd.WithinEpsilon(left.X, right.X, epsilon) && Mathd.WithinEpsilon(left.Y, right.Y, epsilon) && Mathd.WithinEpsilon(left.Z, right.Z, epsilon) && Mathd.WithinEpsilon(left.W, right.W, epsilon); } @@ -721,7 +721,7 @@ namespace FlaxEngine /// First source vector /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Double4 left, ref Double4 right, out double result) + public static void Dot(in Double4 left, in Double4 right, out double result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } @@ -742,7 +742,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Double4 value, out Double4 result) + public static void Normalize(in Double4 value, out Double4 result) { result = value; result.Normalize(); @@ -818,7 +818,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Double4 start, ref Double4 end, double amount, out Double4 result) + public static void Lerp(in Double4 start, in Double4 end, double amount, out Double4 result) { result.X = Mathd.Lerp(start.X, end.X, amount); result.Y = Mathd.Lerp(start.Y, end.Y, amount); @@ -836,7 +836,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Double4 Lerp(Double4 start, Double4 end, double amount) { - Lerp(ref start, ref end, amount, out Double4 result); + Lerp(in start, in end, amount, out Double4 result); return result; } @@ -847,10 +847,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Double4 start, ref Double4 end, double amount, out Double4 result) + public static void SmoothStep(in Double4 start, in Double4 end, double amount, out Double4 result) { amount = Mathd.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -862,7 +862,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Double4 SmoothStep(Double4 start, Double4 end, double amount) { - SmoothStep(ref start, ref end, amount, out Double4 result); + SmoothStep(in start, in end, amount, out Double4 result); return result; } @@ -875,7 +875,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Double4 value1, ref Double4 tangent1, ref Double4 value2, ref Double4 tangent2, double amount, out Double4 result) + public static void Hermite(in Double4 value1, in Double4 tangent1, in Double4 value2, in Double4 tangent2, double amount, out Double4 result) { double squared = amount * amount; double cubed = amount * squared; @@ -900,7 +900,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Double4 Hermite(Double4 value1, Double4 tangent1, Double4 value2, Double4 tangent2, double amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out Double4 result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out Double4 result); return result; } @@ -913,7 +913,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Double4 value1, ref Double4 value2, ref Double4 value3, ref Double4 value4, double amount, out Double4 result) + public static void CatmullRom(in Double4 value1, in Double4 value2, in Double4 value3, in Double4 value4, double amount, out Double4 result) { double squared = amount * amount; double cubed = amount * squared; @@ -934,7 +934,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Double4 CatmullRom(Double4 value1, Double4 value2, Double4 value3, Double4 value4, double amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out Double4 result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out Double4 result); return result; } @@ -944,7 +944,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Double4 left, ref Double4 right, out Double4 result) + public static void Max(in Double4 left, in Double4 right, out Double4 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -960,7 +960,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Double4 Max(Double4 left, Double4 right) { - Max(ref left, ref right, out Double4 result); + Max(in left, in right, out Double4 result); return result; } @@ -970,7 +970,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Double4 left, ref Double4 right, out Double4 result) + public static void Min(in Double4 left, in Double4 right, out Double4 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -986,7 +986,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Double4 Min(Double4 left, Double4 right) { - Min(ref left, ref right, out Double4 result); + Min(in left, in right, out Double4 result); return result; } @@ -1006,7 +1006,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Double4 vector, ref Quaternion rotation, out Double4 result) + public static void Transform(in Double4 vector, in Quaternion rotation, out Double4 result) { double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -1034,7 +1034,7 @@ namespace FlaxEngine /// The transformed . public static Double4 Transform(Double4 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out Double4 result); + Transform(in vector, in rotation, out Double4 result); return result; } @@ -1044,7 +1044,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double4 vector, ref Matrix transform, out Double4 result) + public static void Transform(in Double4 vector, in Matrix transform, out Double4 result) { result = new Double4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + vector.W * transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + vector.W * transform.M42, @@ -1060,7 +1060,7 @@ namespace FlaxEngine /// The transformed . public static Double4 Transform(Double4 vector, Matrix transform) { - Transform(ref vector, ref transform, out Double4 result); + Transform(in vector, in transform, out Double4 result); return result; } @@ -1076,7 +1076,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1258,7 +1258,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Double4 left, Double4 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1270,7 +1270,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Double4 left, Double4 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1377,7 +1377,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Double4 other) + public bool Equals(in Double4 other) { return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } @@ -1390,7 +1390,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Double4 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1400,7 +1400,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Double4 other && Equals(ref other); + return value is Double4 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Float2.cs b/Source/Engine/Core/Math/Float2.cs index 1b70dd0a6..efb00b8d7 100644 --- a/Source/Engine/Core/Math/Float2.cs +++ b/Source/Engine/Core/Math/Float2.cs @@ -309,7 +309,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Float2 left, ref Float2 right, out Float2 result) + public static void Add(in Float2 left, in Float2 right, out Float2 result) { result = new Float2(left.X + right.X, left.Y + right.Y); } @@ -331,7 +331,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Float2 left, ref float right, out Float2 result) + public static void Add(in Float2 left, float right, out Float2 result) { result = new Float2(left.X + right, left.Y + right); } @@ -353,7 +353,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Float2 left, ref Float2 right, out Float2 result) + public static void Subtract(in Float2 left, in Float2 right, out Float2 result) { result = new Float2(left.X - right.X, left.Y - right.Y); } @@ -375,7 +375,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Float2 left, ref float right, out Float2 result) + public static void Subtract(in Float2 left, float right, out Float2 result) { result = new Float2(left.X - right, left.Y - right); } @@ -397,7 +397,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector /// The vector with subtracted scalar for each element. - public static void Subtract(ref float left, ref Float2 right, out Float2 result) + public static void Subtract(float left, in Float2 right, out Float2 result) { result = new Float2(left - right.X, left - right.Y); } @@ -419,7 +419,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Float2 value, float scale, out Float2 result) + public static void Multiply(in Float2 value, float scale, out Float2 result) { result = new Float2(value.X * scale, value.Y * scale); } @@ -441,7 +441,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Float2 left, ref Float2 right, out Float2 result) + public static void Multiply(in Float2 left, in Float2 right, out Float2 result) { result = new Float2(left.X * right.X, left.Y * right.Y); } @@ -463,7 +463,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Float2 value, float scale, out Float2 result) + public static void Divide(in Float2 value, float scale, out Float2 result) { result = new Float2(value.X / scale, value.Y / scale); } @@ -485,7 +485,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(float scale, ref Float2 value, out Float2 result) + public static void Divide(float scale, in Float2 value, out Float2 result) { result = new Float2(scale / value.X, scale / value.Y); } @@ -506,7 +506,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Float2 value, out Float2 result) + public static void Negate(in Float2 value, out Float2 result) { result = new Float2(-value.X, -value.Y); } @@ -531,7 +531,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 2D Cartesian coordinates of the specified point. - public static void Barycentric(ref Float2 value1, ref Float2 value2, ref Float2 value3, float amount1, float amount2, out Float2 result) + public static void Barycentric(in Float2 value1, in Float2 value2, in Float2 value3, float amount1, float amount2, out Float2 result) { result = new Float2(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y)); @@ -549,7 +549,7 @@ namespace FlaxEngine /// A new containing the 2D Cartesian coordinates of the specified point. public static Float2 Barycentric(Float2 value1, Float2 value2, Float2 value3, float amount1, float amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out Float2 result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out Float2 result); return result; } @@ -560,7 +560,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Float2 value, ref Float2 min, ref Float2 max, out Float2 result) + public static void Clamp(in Float2 value, in Float2 min, in Float2 max, out Float2 result) { float x = value.X; x = x > max.X ? max.X : x; @@ -580,7 +580,7 @@ namespace FlaxEngine /// The clamped value. public static Float2 Clamp(Float2 value, Float2 min, Float2 max) { - Clamp(ref value, ref min, ref max, out Float2 result); + Clamp(in value, in min, in max, out Float2 result); return result; } @@ -600,7 +600,7 @@ namespace FlaxEngine /// The second triangle vertex. /// The third triangle vertex. /// The triangle area. - public static float TriangleArea(ref Float2 v0, ref Float2 v1, ref Float2 v2) + public static float TriangleArea(in Float2 v0, in Float2 v1, in Float2 v2) { return Mathf.Abs((v0.X * (v1.Y - v2.Y) + v1.X * (v2.Y - v0.Y) + v2.X * (v0.Y - v1.Y)) / 2); } @@ -611,8 +611,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Float2 value1, ref Float2 value2, out float result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Float2 value1, in Float2 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -639,8 +639,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static float Distance(ref Float2 value1, ref Float2 value2) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static float Distance(in Float2 value1, in Float2 value2) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -653,7 +653,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Float2 value1, ref Float2 value2, out float result) + public static void DistanceSquared(in Float2 value1, in Float2 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -666,7 +666,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// The squared distance between the two vectors. - public static float DistanceSquared(ref Float2 value1, ref Float2 value2) + public static float DistanceSquared(in Float2 value1, in Float2 value2) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -695,7 +695,7 @@ namespace FlaxEngine /// true if left and right are near, false otherwise public static bool NearEqual(Float2 left, Float2 right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -705,7 +705,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Float2 left, ref Float2 right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Float2 left, in Float2 right, float epsilon = Mathf.Epsilon) { return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon); } @@ -716,7 +716,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Float2 left, ref Float2 right, out float result) + public static void Dot(in Float2 left, in Float2 right, out float result) { result = left.X * right.X + left.Y * right.Y; } @@ -727,7 +727,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The dot product of the two vectors. - public static float Dot(ref Float2 left, ref Float2 right) + public static float Dot(in Float2 left, in Float2 right) { return left.X * right.X + left.Y * right.Y; } @@ -749,7 +749,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the cross product of the two vectors. - public static void Cross(ref Float2 left, ref Float2 right, out float result) + public static void Cross(in Float2 left, in Float2 right, out float result) { result = left.X * right.Y - left.Y * right.X; } @@ -760,7 +760,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The cross product of the two vectors. - public static float Cross(ref Float2 left, ref Float2 right) + public static float Cross(in Float2 left, in Float2 right) { return left.X * right.Y - left.Y * right.X; } @@ -781,7 +781,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Float2 value, out Float2 result) + public static void Normalize(in Float2 value, out Float2 result) { result = value; result.Normalize(); @@ -893,7 +893,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Float2 start, ref Float2 end, float amount, out Float2 result) + public static void Lerp(in Float2 start, in Float2 end, float amount, out Float2 result) { result.X = Mathf.Lerp(start.X, end.X, amount); result.Y = Mathf.Lerp(start.Y, end.Y, amount); @@ -909,7 +909,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Float2 Lerp(Float2 start, Float2 end, float amount) { - Lerp(ref start, ref end, amount, out Float2 result); + Lerp(in start, in end, amount, out Float2 result); return result; } @@ -921,7 +921,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Float2 start, ref Float2 end, ref Float2 amount, out Float2 result) + public static void Lerp(in Float2 start, in Float2 end, in Float2 amount, out Float2 result) { result.X = Mathf.Lerp(start.X, end.X, amount.X); result.Y = Mathf.Lerp(start.Y, end.Y, amount.Y); @@ -937,7 +937,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Float2 Lerp(Float2 start, Float2 end, Float2 amount) { - Lerp(ref start, ref end, ref amount, out Float2 result); + Lerp(in start, in end, in amount, out Float2 result); return result; } @@ -948,10 +948,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Float2 start, ref Float2 end, float amount, out Float2 result) + public static void SmoothStep(in Float2 start, in Float2 end, float amount, out Float2 result) { amount = Mathf.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -963,7 +963,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Float2 SmoothStep(Float2 start, Float2 end, float amount) { - SmoothStep(ref start, ref end, amount, out Float2 result); + SmoothStep(in start, in end, amount, out Float2 result); return result; } @@ -976,7 +976,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Float2 value1, ref Float2 tangent1, ref Float2 value2, ref Float2 tangent2, float amount, out Float2 result) + public static void Hermite(in Float2 value1, in Float2 tangent1, in Float2 value2, in Float2 tangent2, float amount, out Float2 result) { float squared = amount * amount; float cubed = amount * squared; @@ -999,7 +999,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Float2 Hermite(Float2 value1, Float2 tangent1, Float2 value2, Float2 tangent2, float amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out Float2 result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out Float2 result); return result; } @@ -1018,7 +1018,7 @@ namespace FlaxEngine /// /// The in direction. /// When the method completes, contains the result of the calculation. - public static void Perpendicular(ref Float2 inDirection, out Float2 result) + public static void Perpendicular(in Float2 inDirection, out Float2 result) { result = new Float2(-inDirection.Y, inDirection.X); } @@ -1032,7 +1032,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Float2 value1, ref Float2 value2, ref Float2 value3, ref Float2 value4, float amount, out Float2 result) + public static void CatmullRom(in Float2 value1, in Float2 value2, in Float2 value3, in Float2 value4, float amount, out Float2 result) { float squared = amount * amount; float cubed = amount * squared; @@ -1055,7 +1055,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Float2 CatmullRom(Float2 value1, Float2 value2, Float2 value3, Float2 value4, float amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out Float2 result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out Float2 result); return result; } @@ -1065,7 +1065,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Float2 left, ref Float2 right, out Float2 result) + public static void Max(in Float2 left, in Float2 right, out Float2 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -1079,7 +1079,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Float2 Max(Float2 left, Float2 right) { - Max(ref left, ref right, out Float2 result); + Max(in left, in right, out Float2 result); return result; } @@ -1089,7 +1089,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Float2 left, ref Float2 right, out Float2 result) + public static void Min(in Float2 left, in Float2 right, out Float2 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -1103,7 +1103,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Float2 Min(Float2 left, Float2 right) { - Min(ref left, ref right, out Float2 result); + Min(in left, in right, out Float2 result); return result; } @@ -1124,7 +1124,7 @@ namespace FlaxEngine /// Normal of the surface. /// When the method completes, contains the reflected vector. /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Float2 vector, ref Float2 normal, out Float2 result) + public static void Reflect(in Float2 vector, in Float2 normal, out Float2 result) { float dot = vector.X * normal.X + vector.Y * normal.Y; result.X = vector.X - 2.0f * dot * normal.X; @@ -1140,7 +1140,7 @@ namespace FlaxEngine /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. public static Float2 Reflect(Float2 vector, Float2 normal) { - Reflect(ref vector, ref normal, out Float2 result); + Reflect(in vector, in normal, out Float2 result); return result; } @@ -1150,7 +1150,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Float2 vector, ref Quaternion rotation, out Float2 result) + public static void Transform(in Float2 vector, in Quaternion rotation, out Float2 result) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1171,7 +1171,7 @@ namespace FlaxEngine /// The transformed . public static Float2 Transform(Float2 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out Float2 result); + Transform(in vector, in rotation, out Float2 result); return result; } @@ -1181,7 +1181,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Float2 vector, ref Matrix transform, out Float4 result) + public static void Transform(in Float2 vector, in Matrix transform, out Float4 result) { result = new Float4(vector.X * transform.M11 + vector.Y * transform.M21 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + transform.M42, @@ -1197,7 +1197,7 @@ namespace FlaxEngine /// The transformed . public static Float4 Transform(Float2 vector, Matrix transform) { - Transform(ref vector, ref transform, out Float4 result); + Transform(in vector, in transform, out Float4 result); return result; } @@ -1214,7 +1214,7 @@ namespace FlaxEngine /// therefore makes the vector homogeneous. The homogeneous vector is often preferred when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Float2 coordinate, ref Matrix transform, out Float2 result) + public static void TransformCoordinate(in Float2 coordinate, in Matrix transform, out Float2 result) { var vector = new Float4 { @@ -1241,7 +1241,7 @@ namespace FlaxEngine /// public static Float2 TransformCoordinate(Float2 coordinate, Matrix transform) { - TransformCoordinate(ref coordinate, ref transform, out Float2 result); + TransformCoordinate(in coordinate, in transform, out Float2 result); return result; } @@ -1258,7 +1258,7 @@ namespace FlaxEngine /// apply. This is often preferred for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Float2 normal, ref Matrix transform, out Float2 result) + public static void TransformNormal(in Float2 normal, in Matrix transform, out Float2 result) { result = new Float2(normal.X * transform.M11 + normal.Y * transform.M21, normal.X * transform.M12 + normal.Y * transform.M22); @@ -1279,7 +1279,7 @@ namespace FlaxEngine /// public static Float2 TransformNormal(Float2 normal, Matrix transform) { - TransformNormal(ref normal, ref transform, out Float2 result); + TransformNormal(in normal, in transform, out Float2 result); return result; } @@ -1310,7 +1310,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1540,7 +1540,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Float2 left, Float2 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1552,7 +1552,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Float2 left, Float2 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1656,7 +1656,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Float2 other) + public bool Equals(in Float2 other) { return X == other.X && Y == other.Y; } @@ -1664,9 +1664,9 @@ namespace FlaxEngine /// /// Determines whether the specified are equal. /// - public static bool Equals(ref Float2 a, ref Float2 b) + public static bool Equals(in Float2 a, in Float2 b) { - return a.Equals(ref b); + return a.Equals(in b); } /// @@ -1677,7 +1677,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Float2 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1687,7 +1687,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Float2 other && Equals(ref other); + return value is Float2 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Float3.cs b/Source/Engine/Core/Math/Float3.cs index 5e8dceed6..470765f8c 100644 --- a/Source/Engine/Core/Math/Float3.cs +++ b/Source/Engine/Core/Math/Float3.cs @@ -364,7 +364,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Float3 left, ref Float3 right, out Float3 result) + public static void Add(in Float3 left, in Float3 right, out Float3 result) { result = new Float3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); } @@ -386,7 +386,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Float3 left, ref float right, out Float3 result) + public static void Add(in Float3 left, float right, out Float3 result) { result = new Float3(left.X + right, left.Y + right, left.Z + right); } @@ -408,7 +408,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Float3 left, ref Float3 right, out Float3 result) + public static void Subtract(in Float3 left, in Float3 right, out Float3 result) { result = new Float3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); } @@ -430,7 +430,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Float3 left, ref float right, out Float3 result) + public static void Subtract(in Float3 left, float right, out Float3 result) { result = new Float3(left.X - right, left.Y - right, left.Z - right); } @@ -452,7 +452,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref float left, ref Float3 right, out Float3 result) + public static void Subtract(float left, in Float3 right, out Float3 result) { result = new Float3(left - right.X, left - right.Y, left - right.Z); } @@ -474,7 +474,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Float3 value, float scale, out Float3 result) + public static void Multiply(in Float3 value, float scale, out Float3 result) { result = new Float3(value.X * scale, value.Y * scale, value.Z * scale); } @@ -496,7 +496,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Float3 left, ref Float3 right, out Float3 result) + public static void Multiply(in Float3 left, in Float3 right, out Float3 result) { result = new Float3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); } @@ -518,7 +518,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector (per component). /// When the method completes, contains the divided vector. - public static void Divide(ref Float3 value, ref Float3 scale, out Float3 result) + public static void Divide(in Float3 value, in Float3 scale, out Float3 result) { result = new Float3(value.X / scale.X, value.Y / scale.Y, value.Z / scale.Z); } @@ -540,7 +540,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Float3 value, float scale, out Float3 result) + public static void Divide(in Float3 value, float scale, out Float3 result) { result = new Float3(value.X / scale, value.Y / scale, value.Z / scale); } @@ -562,7 +562,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(float scale, ref Float3 value, out Float3 result) + public static void Divide(float scale, in Float3 value, out Float3 result) { result = new Float3(scale / value.X, scale / value.Y, scale / value.Z); } @@ -583,7 +583,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Float3 value, out Float3 result) + public static void Negate(in Float3 value, out Float3 result) { result = new Float3(-value.X, -value.Y, -value.Z); } @@ -607,7 +607,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 3D Cartesian coordinates of the specified point. - public static void Barycentric(ref Float3 value1, ref Float3 value2, ref Float3 value3, float amount1, float amount2, out Float3 result) + public static void Barycentric(in Float3 value1, in Float3 value2, in Float3 value3, float amount1, float amount2, out Float3 result) { result = new Float3(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y), @@ -625,7 +625,7 @@ namespace FlaxEngine /// A new containing the 3D Cartesian coordinates of the specified point. public static Float3 Barycentric(Float3 value1, Float3 value2, Float3 value3, float amount1, float amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out var result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out var result); return result; } @@ -636,7 +636,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Float3 value, ref Float3 min, ref Float3 max, out Float3 result) + public static void Clamp(in Float3 value, in Float3 min, in Float3 max, out Float3 result) { float x = value.X; x = x > max.X ? max.X : x; @@ -659,7 +659,7 @@ namespace FlaxEngine /// The clamped value. public static Float3 Clamp(Float3 value, Float3 min, Float3 max) { - Clamp(ref value, ref min, ref max, out var result); + Clamp(in value, in min, in max, out var result); return result; } @@ -669,7 +669,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains he cross product of the two vectors. - public static void Cross(ref Float3 left, ref Float3 right, out Float3 result) + public static void Cross(in Float3 left, in Float3 right, out Float3 result) { result = new Float3(left.Y * right.Z - left.Z * right.Y, left.Z * right.X - left.X * right.Z, @@ -684,7 +684,7 @@ namespace FlaxEngine /// The cross product of the two vectors. public static Float3 Cross(Float3 left, Float3 right) { - Cross(ref left, ref right, out var result); + Cross(left, right, out var result); return result; } @@ -694,8 +694,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Float3 value1, ref Float3 value2, out float result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Float3 value1, in Float3 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -709,8 +709,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static float Distance(ref Float3 value1, ref Float3 value2) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static float Distance(in Float3 value1, in Float3 value2) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -739,7 +739,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Float3 value1, ref Float3 value2, out float result) + public static void DistanceSquared(in Float3 value1, in Float3 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -753,7 +753,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The squared distance between the two vectors. - public static float DistanceSquared(ref Float3 value1, ref Float3 value2) + public static float DistanceSquared(in Float3 value1, in Float3 value2) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -781,7 +781,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the XY plane. - public static void DistanceXY(ref Float3 value1, ref Float3 value2, out float result) + public static void DistanceXY(in Float3 value1, in Float3 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -794,7 +794,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the XY plane. - public static void DistanceXYSquared(ref Float3 value1, ref Float3 value2, out float result) + public static void DistanceXYSquared(in Float3 value1, in Float3 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -807,7 +807,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the XY plane. - public static void DistanceXZ(ref Float3 value1, ref Float3 value2, out float result) + public static void DistanceXZ(in Float3 value1, in Float3 value2, out float result) { float x = value1.X - value2.X; float z = value1.Z - value2.Z; @@ -820,7 +820,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the XY plane. - public static void DistanceXZSquared(ref Float3 value1, ref Float3 value2, out float result) + public static void DistanceXZSquared(in Float3 value1, in Float3 value2, out float result) { float x = value1.X - value2.X; float z = value1.Z - value2.Z; @@ -833,7 +833,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the YZ plane. - public static void DistanceYZ(ref Float3 value1, ref Float3 value2, out float result) + public static void DistanceYZ(in Float3 value1, in Float3 value2, out float result) { float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; @@ -846,7 +846,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the YZ plane. - public static void DistanceYZSquared(ref Float3 value1, ref Float3 value2, out float result) + public static void DistanceYZSquared(in Float3 value1, in Float3 value2, out float result) { float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; @@ -862,7 +862,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Float3 left, Float3 right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -872,7 +872,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Float3 left, ref Float3 right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Float3 left, in Float3 right, float epsilon = Mathf.Epsilon) { return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon) && Mathf.WithinEpsilon(left.Z, right.Z, epsilon); } @@ -883,7 +883,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Float3 left, ref Float3 right, out float result) + public static void Dot(in Float3 left, in Float3 right, out float result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z; } @@ -894,7 +894,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The dot product of the two vectors. - public static float Dot(ref Float3 left, ref Float3 right) + public static float Dot(in Float3 left, in Float3 right) { return left.X * right.X + left.Y * right.Y + left.Z * right.Z; } @@ -915,7 +915,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Float3 value, out Float3 result) + public static void Normalize(in Float3 value, out Float3 result) { result = value; result.Normalize(); @@ -991,7 +991,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Float3 start, ref Float3 end, float amount, out Float3 result) + public static void Lerp(in Float3 start, in Float3 end, float amount, out Float3 result) { result.X = Mathf.Lerp(start.X, end.X, amount); result.Y = Mathf.Lerp(start.Y, end.Y, amount); @@ -1008,7 +1008,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Float3 Lerp(Float3 start, Float3 end, float amount) { - Lerp(ref start, ref end, amount, out var result); + Lerp(in start, in end, amount, out var result); return result; } @@ -1019,10 +1019,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Float3 start, ref Float3 end, float amount, out Float3 result) + public static void SmoothStep(in Float3 start, in Float3 end, float amount, out Float3 result) { amount = Mathf.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -1034,7 +1034,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Float3 SmoothStep(Float3 start, Float3 end, float amount) { - SmoothStep(ref start, ref end, amount, out var result); + SmoothStep(in start, in end, amount, out var result); return result; } @@ -1064,7 +1064,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Float3 value1, ref Float3 tangent1, ref Float3 value2, ref Float3 tangent2, float amount, out Float3 result) + public static void Hermite(in Float3 value1, in Float3 tangent1, in Float3 value2, in Float3 tangent2, float amount, out Float3 result) { float squared = amount * amount; float cubed = amount * squared; @@ -1088,7 +1088,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Float3 Hermite(Float3 value1, Float3 tangent1, Float3 value2, Float3 tangent2, float amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out var result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out var result); return result; } @@ -1101,7 +1101,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Float3 value1, ref Float3 value2, ref Float3 value3, ref Float3 value4, float amount, out Float3 result) + public static void CatmullRom(in Float3 value1, in Float3 value2, in Float3 value3, in Float3 value4, float amount, out Float3 result) { float squared = amount * amount; float cubed = amount * squared; @@ -1127,7 +1127,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Float3 CatmullRom(Float3 value1, Float3 value2, Float3 value3, Float3 value4, float amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out var result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out var result); return result; } @@ -1137,7 +1137,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Float3 left, ref Float3 right, out Float3 result) + public static void Max(in Float3 left, in Float3 right, out Float3 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -1152,7 +1152,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Float3 Max(Float3 left, Float3 right) { - Max(ref left, ref right, out var result); + Max(in left, in right, out var result); return result; } @@ -1162,7 +1162,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Float3 left, ref Float3 right, out Float3 result) + public static void Min(in Float3 left, in Float3 right, out Float3 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -1177,7 +1177,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Float3 Min(Float3 left, Float3 right) { - Min(ref left, ref right, out var result); + Min(in left, in right, out var result); return result; } @@ -1242,9 +1242,9 @@ namespace FlaxEngine /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in screen space. - public static void Project(ref Float3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Float3 result) + public static void Project(in Float3 vector, float x, float y, float width, float height, float minZ, float maxZ, in Matrix worldViewProjection, out Float3 result) { - TransformCoordinate(ref vector, ref worldViewProjection, out var v); + TransformCoordinate(in vector, in worldViewProjection, out var v); result = new Float3((1.0f + v.X) * 0.5f * width + x, (1.0f - v.Y) * 0.5f * height + y, v.Z * (maxZ - minZ) + minZ); } @@ -1262,7 +1262,7 @@ namespace FlaxEngine /// The vector in screen space. public static Float3 Project(Float3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection) { - Project(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); + Project(in vector, x, y, width, height, minZ, maxZ, in worldViewProjection, out var result); return result; } @@ -1278,16 +1278,16 @@ namespace FlaxEngine /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in object space. - public static void Unproject(ref Float3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Float3 result) + public static void Unproject(in Float3 vector, float x, float y, float width, float height, float minZ, float maxZ, in Matrix worldViewProjection, out Float3 result) { - Matrix.Invert(ref worldViewProjection, out var matrix); + Matrix.Invert(worldViewProjection, out var matrix); var v = new Float3 { X = (vector.X - x) / width * 2.0f - 1.0f, Y = -((vector.Y - y) / height * 2.0f - 1.0f), Z = (vector.Z - minZ) / (maxZ - minZ) }; - TransformCoordinate(ref v, ref matrix, out result); + TransformCoordinate(in v, in matrix, out result); } /// @@ -1304,7 +1304,7 @@ namespace FlaxEngine /// The vector in object space. public static Float3 Unproject(Float3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection) { - Unproject(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); + Unproject(in vector, x, y, width, height, minZ, maxZ, in worldViewProjection, out var result); return result; } @@ -1315,7 +1315,7 @@ namespace FlaxEngine /// Normal of the surface. /// When the method completes, contains the reflected vector. /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Float3 vector, ref Float3 normal, out Float3 result) + public static void Reflect(in Float3 vector, in Float3 normal, out Float3 result) { float dot = vector.X * normal.X + vector.Y * normal.Y + vector.Z * normal.Z; result.X = vector.X - 2.0f * dot * normal.X; @@ -1332,7 +1332,7 @@ namespace FlaxEngine /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. public static Float3 Reflect(Float3 vector, Float3 normal) { - Reflect(ref vector, ref normal, out var result); + Reflect(in vector, in normal, out var result); return result; } @@ -1342,7 +1342,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Float3 vector, ref Quaternion rotation, out Float3 result) + public static void Transform(in Float3 vector, in Quaternion rotation, out Float3 result) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1369,7 +1369,7 @@ namespace FlaxEngine /// The transformed . public static Float3 Transform(Float3 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out var result); + Transform(in vector, in rotation, out var result); return result; } @@ -1379,7 +1379,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Float3 vector, ref Matrix3x3 transform, out Float3 result) + public static void Transform(in Float3 vector, in Matrix3x3 transform, out Float3 result) { result = new Float3((vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31), (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32), @@ -1394,7 +1394,7 @@ namespace FlaxEngine /// The transformed . public static Float3 Transform(Float3 vector, Matrix3x3 transform) { - Transform(ref vector, ref transform, out var result); + Transform(in vector, in transform, out var result); return result; } @@ -1404,7 +1404,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Float3 vector, ref Matrix transform, out Float3 result) + public static void Transform(in Float3 vector, in Matrix transform, out Float3 result) { result = new Float3(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + transform.M42, @@ -1417,7 +1417,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Float3 vector, ref Matrix transform, out Float4 result) + public static void Transform(in Float3 vector, in Matrix transform, out Float4 result) { result = new Float4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + transform.M42, @@ -1433,7 +1433,7 @@ namespace FlaxEngine /// The transformed . public static Float3 Transform(Float3 vector, Matrix transform) { - Transform(ref vector, ref transform, out Float3 result); + Transform(in vector, in transform, out Float3 result); return result; } @@ -1450,7 +1450,7 @@ namespace FlaxEngine /// therefore makes the vector homogeneous. The homogeneous vector is often preferred when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Float3 coordinate, ref Matrix transform, out Float3 result) + public static void TransformCoordinate(in Float3 coordinate, in Matrix transform, out Float3 result) { var vector = new Float4 { @@ -1477,7 +1477,7 @@ namespace FlaxEngine /// public static Float3 TransformCoordinate(Float3 coordinate, Matrix transform) { - TransformCoordinate(ref coordinate, ref transform, out var result); + TransformCoordinate(in coordinate, in transform, out var result); return result; } @@ -1494,7 +1494,7 @@ namespace FlaxEngine /// apply. This is often preferred for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Float3 normal, ref Matrix transform, out Float3 result) + public static void TransformNormal(in Float3 normal, in Matrix transform, out Float3 result) { result = new Float3(normal.X * transform.M11 + normal.Y * transform.M21 + normal.Z * transform.M31, normal.X * transform.M12 + normal.Y * transform.M22 + normal.Z * transform.M32, @@ -1516,7 +1516,7 @@ namespace FlaxEngine /// public static Float3 TransformNormal(Float3 normal, Matrix transform) { - TransformNormal(ref normal, ref transform, out var result); + TransformNormal(in normal, in transform, out var result); return result; } @@ -1549,7 +1549,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1598,7 +1598,7 @@ namespace FlaxEngine /// The scaled vector. public static Float3 operator *(Float3 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out var result); + Transform(in vector, in rotation, out var result); return result; } @@ -1791,7 +1791,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Float3 left, Float3 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1803,7 +1803,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Float3 left, Float3 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1910,7 +1910,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Float3 other) + public bool Equals(in Float3 other) { return X == other.X && Y == other.Y && Z == other.Z; } @@ -1923,7 +1923,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Float3 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1933,7 +1933,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Float3 other && Equals(ref other); + return value is Float3 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Float4.cs b/Source/Engine/Core/Math/Float4.cs index b6eb6dd9e..e6c22fa5c 100644 --- a/Source/Engine/Core/Math/Float4.cs +++ b/Source/Engine/Core/Math/Float4.cs @@ -330,7 +330,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Float4 left, ref Float4 right, out Float4 result) + public static void Add(in Float4 left, in Float4 right, out Float4 result) { result = new Float4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); } @@ -352,7 +352,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Float4 left, ref float right, out Float4 result) + public static void Add(in Float4 left, float right, out Float4 result) { result = new Float4(left.X + right, left.Y + right, left.Z + right, left.W + right); } @@ -374,7 +374,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Float4 left, ref Float4 right, out Float4 result) + public static void Subtract(in Float4 left, in Float4 right, out Float4 result) { result = new Float4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); } @@ -396,7 +396,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Float4 left, ref float right, out Float4 result) + public static void Subtract(in Float4 left, float right, out Float4 result) { result = new Float4(left.X - right, left.Y - right, left.Z - right, left.W - right); } @@ -418,7 +418,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref float left, ref Float4 right, out Float4 result) + public static void Subtract(float left, in Float4 right, out Float4 result) { result = new Float4(left - right.X, left - right.Y, left - right.Z, left - right.W); } @@ -440,7 +440,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Float4 value, float scale, out Float4 result) + public static void Multiply(in Float4 value, float scale, out Float4 result) { result = new Float4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); } @@ -462,7 +462,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Float4 left, ref Float4 right, out Float4 result) + public static void Multiply(in Float4 left, in Float4 right, out Float4 result) { result = new Float4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); } @@ -484,7 +484,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Float4 value, float scale, out Float4 result) + public static void Divide(in Float4 value, float scale, out Float4 result) { result = new Float4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); } @@ -506,7 +506,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(float scale, ref Float4 value, out Float4 result) + public static void Divide(float scale, in Float4 value, out Float4 result) { result = new Float4(scale / value.X, scale / value.Y, scale / value.Z, scale / value.W); } @@ -527,7 +527,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Float4 value, out Float4 result) + public static void Negate(in Float4 value, out Float4 result) { result = new Float4(-value.X, -value.Y, -value.Z, -value.W); } @@ -551,7 +551,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 4D Cartesian coordinates of the specified point. - public static void Barycentric(ref Float4 value1, ref Float4 value2, ref Float4 value3, float amount1, float amount2, out Float4 result) + public static void Barycentric(in Float4 value1, in Float4 value2, in Float4 value3, float amount1, float amount2, out Float4 result) { result = new Float4(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y), @@ -570,7 +570,7 @@ namespace FlaxEngine /// A new containing the 4D Cartesian coordinates of the specified point. public static Float4 Barycentric(Float4 value1, Float4 value2, Float4 value3, float amount1, float amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out Float4 result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out Float4 result); return result; } @@ -581,7 +581,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Float4 value, ref Float4 min, ref Float4 max, out Float4 result) + public static void Clamp(in Float4 value, in Float4 min, in Float4 max, out Float4 result) { float x = value.X; x = x > max.X ? max.X : x; @@ -607,7 +607,7 @@ namespace FlaxEngine /// The clamped value. public static Float4 Clamp(Float4 value, Float4 min, Float4 max) { - Clamp(ref value, ref min, ref max, out Float4 result); + Clamp(in value, in min, in max, out Float4 result); return result; } @@ -617,8 +617,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Float4 value1, ref Float4 value2, out float result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Float4 value1, in Float4 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -649,7 +649,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Float4 value1, ref Float4 value2, out float result) + public static void DistanceSquared(in Float4 value1, in Float4 value2, out float result) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; @@ -682,7 +682,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Float4 left, Float4 right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -692,7 +692,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Float4 left, ref Float4 right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Float4 left, in Float4 right, float epsilon = Mathf.Epsilon) { return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon) && Mathf.WithinEpsilon(left.Z, right.Z, epsilon) && Mathf.WithinEpsilon(left.W, right.W, epsilon); } @@ -703,7 +703,7 @@ namespace FlaxEngine /// First source vector /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Float4 left, ref Float4 right, out float result) + public static void Dot(in Float4 left, in Float4 right, out float result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } @@ -724,7 +724,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Float4 value, out Float4 result) + public static void Normalize(in Float4 value, out Float4 result) { result = value; result.Normalize(); @@ -800,7 +800,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Float4 start, ref Float4 end, float amount, out Float4 result) + public static void Lerp(in Float4 start, in Float4 end, float amount, out Float4 result) { result.X = Mathf.Lerp(start.X, end.X, amount); result.Y = Mathf.Lerp(start.Y, end.Y, amount); @@ -818,7 +818,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Float4 Lerp(Float4 start, Float4 end, float amount) { - Lerp(ref start, ref end, amount, out Float4 result); + Lerp(in start, in end, amount, out Float4 result); return result; } @@ -829,10 +829,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Float4 start, ref Float4 end, float amount, out Float4 result) + public static void SmoothStep(in Float4 start, in Float4 end, float amount, out Float4 result) { amount = Mathf.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -844,7 +844,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Float4 SmoothStep(Float4 start, Float4 end, float amount) { - SmoothStep(ref start, ref end, amount, out Float4 result); + SmoothStep(in start, in end, amount, out Float4 result); return result; } @@ -857,7 +857,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Float4 value1, ref Float4 tangent1, ref Float4 value2, ref Float4 tangent2, float amount, out Float4 result) + public static void Hermite(in Float4 value1, in Float4 tangent1, in Float4 value2, in Float4 tangent2, float amount, out Float4 result) { float squared = amount * amount; float cubed = amount * squared; @@ -882,7 +882,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Float4 Hermite(Float4 value1, Float4 tangent1, Float4 value2, Float4 tangent2, float amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out Float4 result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out Float4 result); return result; } @@ -895,7 +895,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Float4 value1, ref Float4 value2, ref Float4 value3, ref Float4 value4, float amount, out Float4 result) + public static void CatmullRom(in Float4 value1, in Float4 value2, in Float4 value3, in Float4 value4, float amount, out Float4 result) { float squared = amount * amount; float cubed = amount * squared; @@ -916,7 +916,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Float4 CatmullRom(Float4 value1, Float4 value2, Float4 value3, Float4 value4, float amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out Float4 result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out Float4 result); return result; } @@ -926,7 +926,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Float4 left, ref Float4 right, out Float4 result) + public static void Max(in Float4 left, in Float4 right, out Float4 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -942,7 +942,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Float4 Max(Float4 left, Float4 right) { - Max(ref left, ref right, out Float4 result); + Max(in left, in right, out Float4 result); return result; } @@ -952,7 +952,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Float4 left, ref Float4 right, out Float4 result) + public static void Min(in Float4 left, in Float4 right, out Float4 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -968,7 +968,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Float4 Min(Float4 left, Float4 right) { - Min(ref left, ref right, out Float4 result); + Min(in left, in right, out Float4 result); return result; } @@ -988,7 +988,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Float4 vector, ref Quaternion rotation, out Float4 result) + public static void Transform(in Float4 vector, in Quaternion rotation, out Float4 result) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1016,7 +1016,7 @@ namespace FlaxEngine /// The transformed . public static Float4 Transform(Float4 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out Float4 result); + Transform(in vector, in rotation, out Float4 result); return result; } @@ -1026,7 +1026,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Float4 vector, ref Matrix transform, out Float4 result) + public static void Transform(in Float4 vector, in Matrix transform, out Float4 result) { result = new Float4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + vector.W * transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + vector.W * transform.M42, @@ -1042,7 +1042,7 @@ namespace FlaxEngine /// The transformed . public static Float4 Transform(Float4 vector, Matrix transform) { - Transform(ref vector, ref transform, out Float4 result); + Transform(in vector, in transform, out Float4 result); return result; } @@ -1058,7 +1058,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1288,7 +1288,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Float4 left, Float4 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1300,7 +1300,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Float4 left, Float4 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1417,7 +1417,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Float4 other) + public bool Equals(in Float4 other) { return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } @@ -1430,7 +1430,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Float4 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1440,7 +1440,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Float4 other && Equals(ref other); + return value is Float4 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/FloatR10G10B10A2.cs b/Source/Engine/Core/Math/FloatR10G10B10A2.cs index d75aeea7e..f93d74c1d 100644 --- a/Source/Engine/Core/Math/FloatR10G10B10A2.cs +++ b/Source/Engine/Core/Math/FloatR10G10B10A2.cs @@ -136,7 +136,7 @@ namespace FlaxEngine /// /// /// true if is the same instance as or if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref FloatR10G10B10A2 value1, ref FloatR10G10B10A2 value2) + public static bool Equals(in FloatR10G10B10A2 value1, in FloatR10G10B10A2 value2) { return value1.rawValue == value2.rawValue; } diff --git a/Source/Engine/Core/Math/FloatR11G11B10.cs b/Source/Engine/Core/Math/FloatR11G11B10.cs index 16ce25b6a..5389cec14 100644 --- a/Source/Engine/Core/Math/FloatR11G11B10.cs +++ b/Source/Engine/Core/Math/FloatR11G11B10.cs @@ -114,7 +114,7 @@ namespace FlaxEngine /// /// /// true if is the same instance as or if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref FloatR11G11B10 value1, ref FloatR11G11B10 value2) + public static bool Equals(in FloatR11G11B10 value1, in FloatR11G11B10 value2) { return value1.rawValue == value2.rawValue; } diff --git a/Source/Engine/Core/Math/Half.cs b/Source/Engine/Core/Math/Half.cs index 29afcf1ee..5188e5b1d 100644 --- a/Source/Engine/Core/Math/Half.cs +++ b/Source/Engine/Core/Math/Half.cs @@ -213,7 +213,7 @@ namespace FlaxEngine /// /// /// true if is the same instance as or if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half value1, ref Half value2) + public static bool Equals(in Half value1, in Half value2) { return value1.rawValue == value2.rawValue; } diff --git a/Source/Engine/Core/Math/Half2.cs b/Source/Engine/Core/Math/Half2.cs index 68e055104..a3ddc5d6d 100644 --- a/Source/Engine/Core/Math/Half2.cs +++ b/Source/Engine/Core/Math/Half2.cs @@ -100,7 +100,7 @@ namespace FlaxEngine /// true if has the same value as ; otherwise, false. public static bool operator ==(Half2 left, Half2 right) { - return Equals(ref left, ref right); + return Equals(in left, in right); } /// @@ -113,7 +113,7 @@ namespace FlaxEngine [return: MarshalAs(UnmanagedType.U1)] public static bool operator !=(Half2 left, Half2 right) { - return !Equals(ref left, ref right); + return !Equals(in left, in right); } /// @@ -133,7 +133,7 @@ namespace FlaxEngine /// /// true if is the same instance as or /// if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half2 value1, ref Half2 value2) + public static bool Equals(in Half2 value1, in Half2 value2) { return ((value1.X == value2.X) && (value1.Y == value2.Y)); } diff --git a/Source/Engine/Core/Math/Half3.cs b/Source/Engine/Core/Math/Half3.cs index 8a05e454b..466010411 100644 --- a/Source/Engine/Core/Math/Half3.cs +++ b/Source/Engine/Core/Math/Half3.cs @@ -112,7 +112,7 @@ namespace FlaxEngine /// true if has the same value as ; otherwise, false. public static bool operator ==(Half3 left, Half3 right) { - return Equals(ref left, ref right); + return Equals(in left, in right); } /// @@ -125,7 +125,7 @@ namespace FlaxEngine [return: MarshalAs(UnmanagedType.U1)] public static bool operator !=(Half3 left, Half3 right) { - return !Equals(ref left, ref right); + return !Equals(in left, in right); } /// @@ -146,7 +146,7 @@ namespace FlaxEngine /// /// true if is the same instance as or /// if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half3 value1, ref Half3 value2) + public static bool Equals(in Half3 value1, in Half3 value2) { return (((value1.X == value2.X) && (value1.Y == value2.Y)) && (value1.Z == value2.Z)); } diff --git a/Source/Engine/Core/Math/Half4.cs b/Source/Engine/Core/Math/Half4.cs index fdd57f7e7..d79502743 100644 --- a/Source/Engine/Core/Math/Half4.cs +++ b/Source/Engine/Core/Math/Half4.cs @@ -97,7 +97,7 @@ namespace FlaxEngine /// true if has the same value as ; otherwise, false. public static bool operator ==(Half4 left, Half4 right) { - return Equals(ref left, ref right); + return Equals(in left, in right); } /// @@ -109,7 +109,7 @@ namespace FlaxEngine /// true if has a different value than ; otherwise, false. public static bool operator !=(Half4 left, Half4 right) { - return !Equals(ref left, ref right); + return !Equals(in left, in right); } /// @@ -131,7 +131,7 @@ namespace FlaxEngine /// /// true if is the same instance as or /// if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half4 value1, ref Half4 value2) + public static bool Equals(in Half4 value1, in Half4 value2) { return (((value1.X == value2.X) && (value1.Y == value2.Y)) && ((value1.Z == value2.Z) && (value1.W == value2.W))); } diff --git a/Source/Engine/Core/Math/Int2.cs b/Source/Engine/Core/Math/Int2.cs index 4a4107252..befd3557c 100644 --- a/Source/Engine/Core/Math/Int2.cs +++ b/Source/Engine/Core/Math/Int2.cs @@ -198,7 +198,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Int2 left, ref Int2 right, out Int2 result) + public static void Add(in Int2 left, in Int2 right, out Int2 result) { result = new Int2(left.X + right.X, left.Y + right.Y); } @@ -220,7 +220,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Int2 left, ref int right, out Int2 result) + public static void Add(in Int2 left, int right, out Int2 result) { result = new Int2(left.X + right, left.Y + right); } @@ -242,7 +242,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Int2 left, ref Int2 right, out Int2 result) + public static void Subtract(in Int2 left, in Int2 right, out Int2 result) { result = new Int2(left.X - right.X, left.Y - right.Y); } @@ -264,7 +264,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Int2 left, ref int right, out Int2 result) + public static void Subtract(in Int2 left, int right, out Int2 result) { result = new Int2(left.X - right, left.Y - right); } @@ -286,7 +286,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector /// The vector with subtracted scalar for each element. - public static void Subtract(ref int left, ref Int2 right, out Int2 result) + public static void Subtract(int left, in Int2 right, out Int2 result) { result = new Int2(left - right.X, left - right.Y); } @@ -308,7 +308,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Int2 value, int scale, out Int2 result) + public static void Multiply(in Int2 value, int scale, out Int2 result) { result = new Int2(value.X * scale, value.Y * scale); } @@ -330,7 +330,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Int2 left, ref Int2 right, out Int2 result) + public static void Multiply(in Int2 left, in Int2 right, out Int2 result) { result = new Int2(left.X * right.X, left.Y * right.Y); } @@ -352,7 +352,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Int2 value, int scale, out Int2 result) + public static void Divide(in Int2 value, int scale, out Int2 result) { result = new Int2(value.X / scale, value.Y / scale); } @@ -374,7 +374,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(int scale, ref Int2 value, out Int2 result) + public static void Divide(int scale, in Int2 value, out Int2 result) { result = new Int2(scale / value.X, scale / value.Y); } @@ -395,7 +395,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Int2 value, out Int2 result) + public static void Negate(in Int2 value, out Int2 result) { result = new Int2(-value.X, -value.Y); } @@ -417,7 +417,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Int2 value, ref Int2 min, ref Int2 max, out Int2 result) + public static void Clamp(in Int2 value, in Int2 min, in Int2 max, out Int2 result) { int x = value.X; x = x > max.X ? max.X : x; @@ -439,7 +439,7 @@ namespace FlaxEngine /// The clamped value. public static Int2 Clamp(Int2 value, Int2 min, Int2 max) { - Clamp(ref value, ref min, ref max, out Int2 result); + Clamp(in value, in min, in max, out Int2 result); return result; } @@ -449,8 +449,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Int2 value1, ref Int2 value2, out float result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Int2 value1, in Int2 value2, out float result) { int x = value1.X - value2.X; int y = value1.Y - value2.Y; @@ -485,7 +485,7 @@ namespace FlaxEngine /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Int2 value1, ref Int2 value2, out int result) + public static void DistanceSquared(in Int2 value1, in Int2 value2, out int result) { int x = value1.X - value2.X; int y = value1.Y - value2.Y; @@ -520,7 +520,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Int2 left, ref Int2 right, out int result) + public static void Dot(in Int2 left, in Int2 right, out int result) { result = left.X * right.X + left.Y * right.Y; } @@ -542,7 +542,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Int2 left, ref Int2 right, out Int2 result) + public static void Max(in Int2 left, in Int2 right, out Int2 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -556,7 +556,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Int2 Max(Int2 left, Int2 right) { - Max(ref left, ref right, out Int2 result); + Max(in left, in right, out Int2 result); return result; } @@ -566,7 +566,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Int2 left, ref Int2 right, out Int2 result) + public static void Min(in Int2 left, in Int2 right, out Int2 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -580,7 +580,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Int2 Min(Int2 left, Int2 right) { - Min(ref left, ref right, out Int2 result); + Min(in left, in right, out Int2 result); return result; } @@ -607,7 +607,7 @@ namespace FlaxEngine /// /// Multiplies a vector with another by performing component-wise multiplication equivalent to - /// . + /// . /// /// The first vector to multiply. /// The second vector to multiply. @@ -789,7 +789,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Int2 left, Int2 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -801,7 +801,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Int2 left, Int2 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -946,7 +946,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Int2 other) + public bool Equals(in Int2 other) { return other.X == X && other.Y == Y; } @@ -954,7 +954,7 @@ namespace FlaxEngine /// /// Determines whether the specified are equal. /// - public static bool Equals(ref Int2 a, ref Int2 b) + public static bool Equals(in Int2 a, in Int2 b) { return a.X == b.X && a.Y == b.Y; } @@ -967,7 +967,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Int2 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -977,7 +977,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Int2 other && Equals(ref other); + return value is Int2 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Int3.cs b/Source/Engine/Core/Math/Int3.cs index 78e4600c3..a13b4b90f 100644 --- a/Source/Engine/Core/Math/Int3.cs +++ b/Source/Engine/Core/Math/Int3.cs @@ -215,7 +215,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Int3 left, ref Int3 right, out Int3 result) + public static void Add(in Int3 left, in Int3 right, out Int3 result) { result = new Int3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); } @@ -237,7 +237,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Int3 left, ref int right, out Int3 result) + public static void Add(in Int3 left, int right, out Int3 result) { result = new Int3(left.X + right, left.Y + right, left.Z + right); } @@ -259,7 +259,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Int3 left, ref Int3 right, out Int3 result) + public static void Subtract(in Int3 left, in Int3 right, out Int3 result) { result = new Int3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); } @@ -281,7 +281,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Int3 left, ref int right, out Int3 result) + public static void Subtract(in Int3 left, int right, out Int3 result) { result = new Int3(left.X - right, left.Y - right, left.Z - right); } @@ -303,7 +303,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref int left, ref Int3 right, out Int3 result) + public static void Subtract(int left, in Int3 right, out Int3 result) { result = new Int3(left - right.X, left - right.Y, left - right.Z); } @@ -325,7 +325,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Int3 value, int scale, out Int3 result) + public static void Multiply(in Int3 value, int scale, out Int3 result) { result = new Int3(value.X * scale, value.Y * scale, value.Z * scale); } @@ -347,7 +347,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Int3 left, ref Int3 right, out Int3 result) + public static void Multiply(in Int3 left, in Int3 right, out Int3 result) { result = new Int3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); } @@ -369,7 +369,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector (per component). /// When the method completes, contains the divided vector. - public static void Divide(ref Int3 value, ref Int3 scale, out Int3 result) + public static void Divide(in Int3 value, in Int3 scale, out Int3 result) { result = new Int3(value.X / scale.X, value.Y / scale.Y, value.Z / scale.Z); } @@ -391,7 +391,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Int3 value, int scale, out Int3 result) + public static void Divide(in Int3 value, int scale, out Int3 result) { result = new Int3(value.X / scale, value.Y / scale, value.Z / scale); } @@ -413,7 +413,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(int scale, ref Int3 value, out Int3 result) + public static void Divide(int scale, in Int3 value, out Int3 result) { result = new Int3(scale / value.X, scale / value.Y, scale / value.Z); } @@ -434,7 +434,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Int3 value, out Int3 result) + public static void Negate(in Int3 value, out Int3 result) { result = new Int3(-value.X, -value.Y, -value.Z); } @@ -456,7 +456,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Int3 value, ref Int3 min, ref Int3 max, out Int3 result) + public static void Clamp(in Int3 value, in Int3 min, in Int3 max, out Int3 result) { int x = value.X; x = x > max.X ? max.X : x; @@ -482,7 +482,7 @@ namespace FlaxEngine /// The clamped value. public static Int3 Clamp(Int3 value, Int3 min, Int3 max) { - Clamp(ref value, ref min, ref max, out Int3 result); + Clamp(in value, in min, in max, out Int3 result); return result; } @@ -492,8 +492,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Int3 value1, ref Int3 value2, out float result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Int3 value1, in Int3 value2, out float result) { int x = value1.X - value2.X; int y = value1.Y - value2.Y; @@ -530,7 +530,7 @@ namespace FlaxEngine /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Int3 value1, ref Int3 value2, out int result) + public static void DistanceSquared(in Int3 value1, in Int3 value2, out int result) { int x = value1.X - value2.X; int y = value1.Y - value2.Y; @@ -566,7 +566,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the XZ plane. - public static void Distance2D(ref Int2 value1, ref Int2 value2, out float result) + public static void Distance2D(in Int2 value1, in Int2 value2, out float result) { int x = value1.X - value2.X; int y = value1.Y - value2.Y; @@ -592,7 +592,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the XZ plane. - public static void Distance2DSquared(ref Int2 value1, ref Int2 value2, out int result) + public static void Distance2DSquared(in Int2 value1, in Int2 value2, out int result) { int x = value1.X - value2.X; int y = value1.Y - value2.Y; @@ -620,7 +620,7 @@ namespace FlaxEngine /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. /// - public static void Max(ref Int3 left, ref Int3 right, out Int3 result) + public static void Max(in Int3 left, in Int3 right, out Int3 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -635,7 +635,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Int3 Max(Int3 left, Int3 right) { - Max(ref left, ref right, out Int3 result); + Max(in left, in right, out Int3 result); return result; } @@ -645,7 +645,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Int3 left, ref Int3 right, out Int3 result) + public static void Min(in Int3 left, in Int3 right, out Int3 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -660,7 +660,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Int3 Min(Int3 left, Int3 right) { - Min(ref left, ref right, out Int3 result); + Min(in left, in right, out Int3 result); return result; } @@ -687,7 +687,7 @@ namespace FlaxEngine /// /// Multiplies a vector with another by performing component-wise multiplication equivalent to - /// . + /// . /// /// The first vector to multiply. /// The second vector to multiply. @@ -869,7 +869,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Int3 left, Int3 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -881,7 +881,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Int3 left, Int3 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1029,7 +1029,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Int3 other) + public bool Equals(in Int3 other) { return other.X == X && other.Y == Y && other.Z == Z; } @@ -1042,7 +1042,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Int3 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1052,7 +1052,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Int3 other && Equals(ref other); + return value is Int3 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Int4.cs b/Source/Engine/Core/Math/Int4.cs index e180ccb31..850085097 100644 --- a/Source/Engine/Core/Math/Int4.cs +++ b/Source/Engine/Core/Math/Int4.cs @@ -216,7 +216,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Int4 left, ref Int4 right, out Int4 result) + public static void Add(in Int4 left, in Int4 right, out Int4 result) { result = new Int4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); } @@ -238,7 +238,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Int4 left, ref int right, out Int4 result) + public static void Add(in Int4 left, int right, out Int4 result) { result = new Int4(left.X + right, left.Y + right, left.Z + right, left.W + right); } @@ -260,7 +260,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Int4 left, ref Int4 right, out Int4 result) + public static void Subtract(in Int4 left, in Int4 right, out Int4 result) { result = new Int4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); } @@ -282,7 +282,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Int4 left, ref int right, out Int4 result) + public static void Subtract(in Int4 left, int right, out Int4 result) { result = new Int4(left.X - right, left.Y - right, left.Z - right, left.W - right); } @@ -304,7 +304,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref int left, ref Int4 right, out Int4 result) + public static void Subtract(int left, in Int4 right, out Int4 result) { result = new Int4(left - right.X, left - right.Y, left - right.Z, left - right.W); } @@ -326,7 +326,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Int4 value, int scale, out Int4 result) + public static void Multiply(in Int4 value, int scale, out Int4 result) { result = new Int4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); } @@ -348,7 +348,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Int4 left, ref Int4 right, out Int4 result) + public static void Multiply(in Int4 left, in Int4 right, out Int4 result) { result = new Int4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); } @@ -370,7 +370,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Int4 value, int scale, out Int4 result) + public static void Divide(in Int4 value, int scale, out Int4 result) { result = new Int4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); } @@ -392,7 +392,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(int scale, ref Int4 value, out Int4 result) + public static void Divide(int scale, in Int4 value, out Int4 result) { result = new Int4(scale / value.X, scale / value.Y, scale / value.Z, scale / value.W); } @@ -413,7 +413,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Int4 value, out Int4 result) + public static void Negate(in Int4 value, out Int4 result) { result = new Int4(-value.X, -value.Y, -value.Z, -value.W); } @@ -435,7 +435,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Int4 value, ref Int4 min, ref Int4 max, out Int4 result) + public static void Clamp(in Int4 value, in Int4 min, in Int4 max, out Int4 result) { int x = value.X; x = x > max.X ? max.X : x; @@ -465,7 +465,7 @@ namespace FlaxEngine /// The clamped value. public static Int4 Clamp(Int4 value, Int4 min, Int4 max) { - Clamp(ref value, ref min, ref max, out Int4 result); + Clamp(in value, in min, in max, out Int4 result); return result; } @@ -475,7 +475,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Int4 left, ref Int4 right, out Int4 result) + public static void Max(in Int4 left, in Int4 right, out Int4 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -491,7 +491,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Int4 Max(Int4 left, Int4 right) { - Max(ref left, ref right, out Int4 result); + Max(in left, in right, out Int4 result); return result; } @@ -501,7 +501,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Int4 left, ref Int4 right, out Int4 result) + public static void Min(in Int4 left, in Int4 right, out Int4 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -517,7 +517,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Int4 Min(Int4 left, Int4 right) { - Min(ref left, ref right, out Int4 result); + Min(in left, in right, out Int4 result); return result; } @@ -544,7 +544,7 @@ namespace FlaxEngine /// /// Multiplies a vector with another by performing component-wise multiplication equivalent to - /// . + /// . /// /// The first vector to multiply. /// The second vector to multiply. @@ -726,7 +726,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Int4 left, Int4 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -738,7 +738,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Int4 left, Int4 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -886,7 +886,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Int4 other) + public bool Equals(in Int4 other) { return other.X == X && other.Y == Y && other.Z == Z && other.W == W; } @@ -899,7 +899,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Int4 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -909,7 +909,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Int4 other && Equals(ref other); + return value is Int4 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Matrix.cs b/Source/Engine/Core/Math/Matrix.cs index 07ab2dea9..e442541c3 100644 --- a/Source/Engine/Core/Math/Matrix.cs +++ b/Source/Engine/Core/Math/Matrix.cs @@ -644,7 +644,7 @@ namespace FlaxEngine /// public void Invert() { - Invert(ref this, out this); + Invert(this, out this); } /// @@ -652,7 +652,7 @@ namespace FlaxEngine /// public void Transpose() { - Transpose(ref this, out this); + Transpose(this, out this); } /// @@ -677,7 +677,7 @@ namespace FlaxEngine /// public void Orthogonalize() { - Orthogonalize(ref this, out this); + Orthogonalize(this, out this); } /// @@ -704,7 +704,7 @@ namespace FlaxEngine /// public void Orthonormalize() { - Orthonormalize(ref this, out this); + Orthonormalize(this, out this); } /// @@ -716,7 +716,7 @@ namespace FlaxEngine { Matrix temp = this; temp.Transpose(); - Orthonormalize(ref temp, out Q); + Orthonormalize(temp, out Q); Q.Transpose(); R = new Matrix @@ -744,7 +744,7 @@ namespace FlaxEngine /// When the method completes, contains the orthonormalized matrix of the decomposition. public void DecomposeLQ(out Matrix L, out Matrix Q) { - Orthonormalize(ref this, out Q); + Orthonormalize(this, out Q); L = new Matrix { @@ -772,7 +772,7 @@ namespace FlaxEngine public void Decompose(out Transform transform) { Decompose(out transform.Scale, out Matrix3x3 rotationMatrix, out Float3 translation); - Quaternion.RotationMatrix(ref rotationMatrix, out transform.Orientation); + Quaternion.RotationMatrix(rotationMatrix, out transform.Orientation); transform.Translation = translation; } @@ -842,7 +842,7 @@ namespace FlaxEngine public void Decompose(out Float3 scale, out Quaternion rotation, out Float3 translation) { Decompose(out scale, out Matrix3x3 rotationMatrix, out translation); - Quaternion.RotationMatrix(ref rotationMatrix, out rotation); + Quaternion.RotationMatrix(rotationMatrix, out rotation); } /// @@ -885,7 +885,7 @@ namespace FlaxEngine M33 = M33 * invScale, M44 = 1f }; - Quaternion.RotationMatrix(ref rotationMatrix, out rotation); + Quaternion.RotationMatrix(rotationMatrix, out rotation); } /// @@ -989,7 +989,7 @@ namespace FlaxEngine /// The first matrix to add. /// The second matrix to add. /// When the method completes, contains the sum of the two matrices. - public static void Add(ref Matrix left, ref Matrix right, out Matrix result) + public static void Add(in Matrix left, in Matrix right, out Matrix result) { result.M11 = left.M11 + right.M11; result.M12 = left.M12 + right.M12; @@ -1017,7 +1017,7 @@ namespace FlaxEngine /// The sum of the two matrices. public static Matrix Add(Matrix left, Matrix right) { - Add(ref left, ref right, out var result); + Add(left, right, out var result); return result; } @@ -1027,7 +1027,7 @@ namespace FlaxEngine /// The first matrix to subtract. /// The second matrix to subtract. /// When the method completes, contains the difference between the two matrices. - public static void Subtract(ref Matrix left, ref Matrix right, out Matrix result) + public static void Subtract(in Matrix left, in Matrix right, out Matrix result) { result.M11 = left.M11 - right.M11; result.M12 = left.M12 - right.M12; @@ -1055,7 +1055,7 @@ namespace FlaxEngine /// The difference between the two matrices. public static Matrix Subtract(Matrix left, Matrix right) { - Subtract(ref left, ref right, out var result); + Subtract(left, right, out var result); return result; } @@ -1065,7 +1065,7 @@ namespace FlaxEngine /// The matrix to scale. /// The amount by which to scale. /// When the method completes, contains the scaled matrix. - public static void Multiply(ref Matrix left, float right, out Matrix result) + public static void Multiply(in Matrix left, float right, out Matrix result) { result.M11 = left.M11 * right; result.M12 = left.M12 * right; @@ -1093,7 +1093,7 @@ namespace FlaxEngine /// The scaled matrix. public static Matrix Multiply(Matrix left, float right) { - Multiply(ref left, right, out var result); + Multiply(left, right, out var result); return result; } @@ -1103,7 +1103,7 @@ namespace FlaxEngine /// The first matrix to multiply. /// The second matrix to multiply. /// The product of the two matrices. - public static void Multiply(ref Matrix left, ref Matrix right, out Matrix result) + public static void Multiply(in Matrix left, in Matrix right, out Matrix result) { result = new Matrix { @@ -1134,7 +1134,7 @@ namespace FlaxEngine /// The product of the two matrices. public static Matrix Multiply(Matrix left, Matrix right) { - Multiply(ref left, ref right, out var result); + Multiply(left, right, out var result); return result; } @@ -1144,7 +1144,7 @@ namespace FlaxEngine /// The matrix to scale. /// The amount by which to scale. /// When the method completes, contains the scaled matrix. - public static void Divide(ref Matrix left, float right, out Matrix result) + public static void Divide(in Matrix left, float right, out Matrix result) { float inv = 1.0f / right; result.M11 = left.M11 * inv; @@ -1173,7 +1173,7 @@ namespace FlaxEngine /// The scaled matrix. public static Matrix Divide(Matrix left, float right) { - Divide(ref left, right, out var result); + Divide(left, right, out var result); return result; } @@ -1183,7 +1183,7 @@ namespace FlaxEngine /// The first matrix to divide. /// The second matrix to divide. /// When the method completes, contains the quotient of the two matrices. - public static void Divide(ref Matrix left, ref Matrix right, out Matrix result) + public static void Divide(in Matrix left, in Matrix right, out Matrix result) { result.M11 = left.M11 / right.M11; result.M12 = left.M12 / right.M12; @@ -1211,7 +1211,7 @@ namespace FlaxEngine /// The quotient of the two matrices. public static Matrix Divide(Matrix left, Matrix right) { - Divide(ref left, ref right, out var result); + Divide(left, right, out var result); return result; } @@ -1222,7 +1222,7 @@ namespace FlaxEngine /// The exponent to raise the matrix to. /// When the method completes, contains the exponential matrix. /// Thrown when the is negative. - public static void Exponent(ref Matrix value, int exponent, out Matrix result) + public static void Exponent(in Matrix value, int exponent, out Matrix result) { // Source: http://rosettacode.org // Reference: http://rosettacode.org/wiki/Matrix-exponentiation_operator @@ -1268,7 +1268,7 @@ namespace FlaxEngine /// Thrown when the is negative. public static Matrix Exponent(Matrix value, int exponent) { - Exponent(ref value, exponent, out var result); + Exponent(value, exponent, out var result); return result; } @@ -1277,7 +1277,7 @@ namespace FlaxEngine /// /// The matrix to be negated. /// When the method completes, contains the negated matrix. - public static void Negate(ref Matrix value, out Matrix result) + public static void Negate(in Matrix value, out Matrix result) { result.M11 = -value.M11; result.M12 = -value.M12; @@ -1304,7 +1304,7 @@ namespace FlaxEngine /// The negated matrix. public static Matrix Negate(Matrix value) { - Negate(ref value, out var result); + Negate(value, out var result); return result; } @@ -1319,7 +1319,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 /// will cause to be returned. /// - public static void Lerp(ref Matrix start, ref Matrix end, float amount, out Matrix result) + public static void Lerp(in Matrix start, in Matrix end, float amount, out Matrix result) { result.M11 = Mathf.Lerp(start.M11, end.M11, amount); result.M12 = Mathf.Lerp(start.M12, end.M12, amount); @@ -1352,7 +1352,7 @@ namespace FlaxEngine /// public static Matrix Lerp(Matrix start, Matrix end, float amount) { - Lerp(ref start, ref end, amount, out var result); + Lerp(start, end, amount, out var result); return result; } @@ -1363,10 +1363,10 @@ namespace FlaxEngine /// End matrix. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two matrices. - public static void SmoothStep(ref Matrix start, ref Matrix end, float amount, out Matrix result) + public static void SmoothStep(in Matrix start, in Matrix end, float amount, out Matrix result) { amount = Mathf.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(start, end, amount, out result); } /// @@ -1378,7 +1378,7 @@ namespace FlaxEngine /// The cubic interpolation of the two matrices. public static Matrix SmoothStep(Matrix start, Matrix end, float amount) { - SmoothStep(ref start, ref end, amount, out var result); + SmoothStep(start, end, amount, out var result); return result; } @@ -1387,7 +1387,7 @@ namespace FlaxEngine /// /// The matrix whose transpose is to be calculated. /// When the method completes, contains the transpose of the specified matrix. - public static void Transpose(ref Matrix value, out Matrix result) + public static void Transpose(in Matrix value, out Matrix result) { result = new Matrix { @@ -1415,7 +1415,7 @@ namespace FlaxEngine /// /// The matrix whose transpose is to be calculated. /// When the method completes, contains the transpose of the specified matrix. - public static void TransposeByRef(ref Matrix value, ref Matrix result) + public static void TransposeByRef(in Matrix value, out Matrix result) { result.M11 = value.M11; result.M12 = value.M21; @@ -1442,7 +1442,7 @@ namespace FlaxEngine /// The transpose of the specified matrix. public static Matrix Transpose(Matrix value) { - Transpose(ref value, out var result); + Transpose(value, out var result); return result; } @@ -1451,7 +1451,7 @@ namespace FlaxEngine /// /// The matrix whose inverse is to be calculated. /// When the method completes, contains the inverse of the specified matrix. - public static void Invert(ref Matrix value, out Matrix result) + public static void Invert(in Matrix value, out Matrix result) { float b0 = value.M31 * value.M42 - value.M32 * value.M41; float b1 = value.M31 * value.M43 - value.M33 * value.M41; @@ -1547,7 +1547,7 @@ namespace FlaxEngine /// input and than transpose the output. /// /// - public static void Orthogonalize(ref Matrix value, out Matrix result) + public static void Orthogonalize(in Matrix value, out Matrix result) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -1592,7 +1592,7 @@ namespace FlaxEngine /// public static Matrix Orthogonalize(Matrix value) { - Orthogonalize(ref value, out var result); + Orthogonalize(value, out var result); return result; } @@ -1620,7 +1620,7 @@ namespace FlaxEngine /// input and than transpose the output. /// /// - public static void Orthonormalize(ref Matrix value, out Matrix result) + public static void Orthonormalize(in Matrix value, out Matrix result) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthonormalization @@ -1674,7 +1674,7 @@ namespace FlaxEngine /// public static Matrix Orthonormalize(Matrix value) { - Orthonormalize(ref value, out var result); + Orthonormalize(value, out var result); return result; } @@ -1689,7 +1689,7 @@ namespace FlaxEngine /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static void UpperTriangularForm(ref Matrix value, out Matrix result) + public static void UpperTriangularForm(in Matrix value, out Matrix result) { // Adapted from the row echelon code result = value; @@ -1749,7 +1749,7 @@ namespace FlaxEngine /// public static Matrix UpperTriangularForm(Matrix value) { - UpperTriangularForm(ref value, out var result); + UpperTriangularForm(value, out var result); return result; } @@ -1764,11 +1764,11 @@ namespace FlaxEngine /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static void LowerTriangularForm(ref Matrix value, out Matrix result) + public static void LowerTriangularForm(in Matrix value, out Matrix result) { // Adapted from the row echelon code Matrix temp = value; - Transpose(ref temp, out result); + Transpose(temp, out result); var lead = 0; var rowCount = 4; @@ -1812,7 +1812,7 @@ namespace FlaxEngine lead++; } - Transpose(ref result, out result); + Transpose(result, out result); } /// @@ -1828,7 +1828,7 @@ namespace FlaxEngine /// public static Matrix LowerTriangularForm(Matrix value) { - LowerTriangularForm(ref value, out var result); + LowerTriangularForm(value, out var result); return result; } @@ -1837,7 +1837,7 @@ namespace FlaxEngine /// /// The matrix to put into row echelon form. /// When the method completes, contains the row echelon form of the matrix. - public static void RowEchelonForm(ref Matrix value, out Matrix result) + public static void RowEchelonForm(in Matrix value, out Matrix result) { // Source: Wikipedia pseudo code // Reference: http://en.wikipedia.org/wiki/Row_echelon_form#Pseudocode @@ -1897,7 +1897,7 @@ namespace FlaxEngine /// When the method completes, contains the row echelon form of the matrix. public static Matrix RowEchelonForm(Matrix value) { - RowEchelonForm(ref value, out var result); + RowEchelonForm(value, out var result); return result; } @@ -1924,7 +1924,7 @@ namespace FlaxEngine /// to analyze both the input and the result to determine if a solution really exists. /// /// - public static void ReducedRowEchelonForm(ref Matrix value, ref Float4 augment, out Matrix result, out Float4 augmentResult) + public static void ReducedRowEchelonForm(in Matrix value, in Float4 augment, out Matrix result, out Float4 augmentResult) { // Source: http://rosettacode.org // Reference: http://rosettacode.org/wiki/Reduced_row_echelon_form @@ -2037,7 +2037,7 @@ namespace FlaxEngine /// The up vector of the camera. /// The forward vector of the camera. /// When the method completes, contains the created billboard matrix. - public static void Billboard(ref Float3 objectPosition, ref Float3 cameraPosition, ref Float3 cameraUpFloat, ref Float3 cameraForwardFloat, out Matrix result) + public static void Billboard(in Float3 objectPosition, in Float3 cameraPosition, in Float3 cameraUpFloat, in Float3 cameraForwardFloat, out Matrix result) { Float3 difference = cameraPosition - objectPosition; @@ -2047,9 +2047,9 @@ namespace FlaxEngine else difference *= (float)(1.0 / Math.Sqrt(lengthSq)); - Float3.Cross(ref cameraUpFloat, ref difference, out var crossed); + Float3.Cross(cameraUpFloat, difference, out var crossed); crossed.Normalize(); - Float3.Cross(ref difference, ref crossed, out var final); + Float3.Cross(difference, crossed, out var final); result.M11 = crossed.X; result.M12 = crossed.Y; @@ -2079,7 +2079,7 @@ namespace FlaxEngine /// The created billboard matrix. public static Matrix Billboard(Float3 objectPosition, Float3 cameraPosition, Float3 cameraUpFloat, Float3 cameraForwardFloat) { - Billboard(ref objectPosition, ref cameraPosition, ref cameraUpFloat, ref cameraForwardFloat, out var result); + Billboard(objectPosition, cameraPosition, cameraUpFloat, cameraForwardFloat, out var result); return result; } @@ -2090,13 +2090,13 @@ namespace FlaxEngine /// The camera look-at target. /// The camera's up vector. /// When the method completes, contains the created look-at matrix. - public static void LookAt(ref Float3 eye, ref Float3 target, ref Float3 up, out Matrix result) + public static void LookAt(in Float3 eye, in Float3 target, in Float3 up, out Matrix result) { - Float3.Subtract(ref target, ref eye, out var zaxis); + Float3.Subtract(target, eye, out var zaxis); zaxis.Normalize(); - Float3.Cross(ref up, ref zaxis, out var xaxis); + Float3.Cross(up, zaxis, out var xaxis); xaxis.Normalize(); - Float3.Cross(ref zaxis, ref xaxis, out var yaxis); + Float3.Cross(zaxis, xaxis, out var yaxis); result = Identity; result.M11 = xaxis.X; @@ -2109,9 +2109,9 @@ namespace FlaxEngine result.M23 = zaxis.Y; result.M33 = zaxis.Z; - Float3.Dot(ref xaxis, ref eye, out result.M41); - Float3.Dot(ref yaxis, ref eye, out result.M42); - Float3.Dot(ref zaxis, ref eye, out result.M43); + Float3.Dot(xaxis, eye, out result.M41); + Float3.Dot(yaxis, eye, out result.M42); + Float3.Dot(zaxis, eye, out result.M43); result.M41 = -result.M41; result.M42 = -result.M42; @@ -2127,7 +2127,7 @@ namespace FlaxEngine /// The created look-at matrix. public static Matrix LookAt(Float3 eye, Float3 target, Float3 up) { - LookAt(ref eye, ref target, ref up, out var result); + LookAt(eye, target, up, out var result); return result; } @@ -2309,7 +2309,7 @@ namespace FlaxEngine /// /// Scaling factor for all three axes. /// When the method completes, contains the created scaling matrix. - public static void Scaling(ref Float3 scale, out Matrix result) + public static void Scaling(in Float3 scale, out Matrix result) { Scaling(scale.X, scale.Y, scale.Z, out result); } @@ -2321,7 +2321,7 @@ namespace FlaxEngine /// The created scaling matrix. public static Matrix Scaling(Float3 scale) { - Scaling(ref scale, out var result); + Scaling(scale, out var result); return result; } @@ -2480,7 +2480,7 @@ namespace FlaxEngine /// The axis around which to rotate. This parameter is assumed to be normalized. /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// When the method completes, contains the created rotation matrix. - public static void RotationAxis(ref Float3 axis, float angle, out Matrix result) + public static void RotationAxis(in Float3 axis, float angle, out Matrix result) { float x = axis.X; float y = axis.Y; @@ -2514,7 +2514,7 @@ namespace FlaxEngine /// The created rotation matrix. public static Matrix RotationAxis(Float3 axis, float angle) { - RotationAxis(ref axis, angle, out var result); + RotationAxis(axis, angle, out var result); return result; } @@ -2523,7 +2523,7 @@ namespace FlaxEngine /// /// The quaternion to use to build the matrix. /// The created rotation matrix. - public static void RotationQuaternion(ref Quaternion rotation, out Matrix result) + public static void RotationQuaternion(in Quaternion rotation, out Matrix result) { float xx = rotation.X * rotation.X; float yy = rotation.Y * rotation.Y; @@ -2554,7 +2554,7 @@ namespace FlaxEngine /// The created rotation matrix. public static Matrix RotationQuaternion(Quaternion rotation) { - RotationQuaternion(ref rotation, out var result); + RotationQuaternion(rotation, out var result); return result; } @@ -2568,7 +2568,7 @@ namespace FlaxEngine public static void RotationYawPitchRoll(float yaw, float pitch, float roll, out Matrix result) { Quaternion.RotationYawPitchRoll(yaw, pitch, roll, out var quaternion); - RotationQuaternion(ref quaternion, out result); + RotationQuaternion(quaternion, out result); } /// @@ -2589,7 +2589,7 @@ namespace FlaxEngine /// /// The offset for all three coordinate planes. /// When the method completes, contains the created translation matrix. - public static void Translation(ref Float3 value, out Matrix result) + public static void Translation(in Float3 value, out Matrix result) { Translation(value.X, value.Y, value.Z, out result); } @@ -2601,7 +2601,7 @@ namespace FlaxEngine /// The created translation matrix. public static Matrix Translation(Float3 value) { - Translation(ref value, out var result); + Translation(value, out var result); return result; } @@ -2643,15 +2643,15 @@ namespace FlaxEngine /// The rotation vector /// The translation vector /// Contains the created skew/shear matrix. - public static void Skew(float angle, ref Float3 rotationVec, ref Float3 transVec, out Matrix matrix) + public static void Skew(float angle, in Float3 rotationVec, in Float3 transVec, out Matrix matrix) { // http://elckerlyc.ewi.utwente.nl/browser/Elckerlyc/Hmi/HmiMath/src/hmi/math/Mat3f.java var MINIMAL_SKEW_ANGLE = 0.000001f; Float3 e0 = rotationVec; Float3 e1 = Float3.Normalize(transVec); - Float3.Dot(ref rotationVec, ref e1, out var rv1); + Float3.Dot(rotationVec, e1, out var rv1); e0 += rv1 * e1; - Float3.Dot(ref rotationVec, ref e0, out var rv0); + Float3.Dot(rotationVec, e0, out var rv0); var cosA = (float)Math.Cos(angle); var sinA = (float)Math.Sin(angle); float rr0 = rv0 * cosA - rv1 * sinA; @@ -2678,7 +2678,7 @@ namespace FlaxEngine /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation(float scaling, ref Quaternion rotation, ref Float3 translation, out Matrix result) + public static void AffineTransformation(float scaling, in Quaternion rotation, in Float3 translation, out Matrix result) { result = Scaling(scaling) * RotationQuaternion(rotation) * Translation(translation); } @@ -2692,7 +2692,7 @@ namespace FlaxEngine /// The created affine transformation matrix. public static Matrix AffineTransformation(float scaling, Quaternion rotation, Float3 translation) { - AffineTransformation(scaling, ref rotation, ref translation, out var result); + AffineTransformation(scaling, rotation, translation, out var result); return result; } @@ -2704,7 +2704,7 @@ namespace FlaxEngine /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation(float scaling, ref Float3 rotationCenter, ref Quaternion rotation, ref Float3 translation, out Matrix result) + public static void AffineTransformation(float scaling, in Float3 rotationCenter, in Quaternion rotation, in Float3 translation, out Matrix result) { result = Scaling(scaling) * Translation(-rotationCenter) * RotationQuaternion(rotation) * Translation(rotationCenter) * Translation(translation); @@ -2720,7 +2720,7 @@ namespace FlaxEngine /// The created affine transformation matrix. public static Matrix AffineTransformation(float scaling, Float3 rotationCenter, Quaternion rotation, Float3 translation) { - AffineTransformation(scaling, ref rotationCenter, ref rotation, ref translation, out var result); + AffineTransformation(scaling, rotationCenter, rotation, translation, out var result); return result; } @@ -2731,7 +2731,7 @@ namespace FlaxEngine /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation2D(float scaling, float rotation, ref Float2 translation, out Matrix result) + public static void AffineTransformation2D(float scaling, float rotation, in Float2 translation, out Matrix result) { result = Scaling(scaling, scaling, 1.0f) * RotationZ(rotation) * Translation((Float3)translation); } @@ -2745,7 +2745,7 @@ namespace FlaxEngine /// The created affine transformation matrix. public static Matrix AffineTransformation2D(float scaling, float rotation, Float2 translation) { - AffineTransformation2D(scaling, rotation, ref translation, out var result); + AffineTransformation2D(scaling, rotation, translation, out var result); return result; } @@ -2757,7 +2757,7 @@ namespace FlaxEngine /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation2D(float scaling, ref Float2 rotationCenter, float rotation, ref Float2 translation, out Matrix result) + public static void AffineTransformation2D(float scaling, in Float2 rotationCenter, float rotation, in Float2 translation, out Matrix result) { result = Scaling(scaling, scaling, 1.0f) * Translation((Float3)(-rotationCenter)) * RotationZ(rotation) * Translation((Float3)rotationCenter) * Translation((Float3)translation); } @@ -2772,7 +2772,7 @@ namespace FlaxEngine /// The created affine transformation matrix. public static Matrix AffineTransformation2D(float scaling, Float2 rotationCenter, float rotation, Float2 translation) { - AffineTransformation2D(scaling, ref rotationCenter, rotation, ref translation, out var result); + AffineTransformation2D(scaling, rotationCenter, rotation, translation, out var result); return result; } @@ -2785,7 +2785,7 @@ namespace FlaxEngine /// The created transformation matrix. public static Matrix Transformation(Float3 scaling, Quaternion rotation, Float3 translation) { - Transformation(ref scaling, ref rotation, ref translation, out var result); + Transformation(scaling, rotation, translation, out var result); return result; } @@ -2796,7 +2796,7 @@ namespace FlaxEngine /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// The scaling. /// When the method completes, contains the created transformation matrix. - public static void Transformation(ref Float3 scaling, ref Quaternion rotation, ref Float3 translation, out Matrix result) + public static void Transformation(in Float3 scaling, in Quaternion rotation, in Float3 translation, out Matrix result) { // Equivalent to: //result = @@ -2858,7 +2858,7 @@ namespace FlaxEngine /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created transformation matrix. - public static void Transformation(ref Float3 scalingCenter, ref Quaternion scalingRotation, ref Float3 scaling, ref Float3 rotationCenter, ref Quaternion rotation, ref Float3 translation, out Matrix result) + public static void Transformation(in Float3 scalingCenter, in Quaternion scalingRotation, in Float3 scaling, in Float3 rotationCenter, in Quaternion rotation, in Float3 translation, out Matrix result) { Matrix sr = RotationQuaternion(scalingRotation); result = Translation(-scalingCenter) * Transpose(sr) * Scaling(scaling) * sr * Translation(scalingCenter) * Translation(-rotationCenter) * RotationQuaternion(rotation) * Translation(rotationCenter) * Translation(translation); @@ -2876,7 +2876,7 @@ namespace FlaxEngine /// The created transformation matrix. public static Matrix Transformation(Float3 scalingCenter, Quaternion scalingRotation, Float3 scaling, Float3 rotationCenter, Quaternion rotation, Float3 translation) { - Transformation(ref scalingCenter, ref scalingRotation, ref scaling, ref rotationCenter, ref rotation, ref translation, out var result); + Transformation(scalingCenter, scalingRotation, scaling, rotationCenter, rotation, translation, out var result); return result; } @@ -2890,7 +2890,7 @@ namespace FlaxEngine /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created transformation matrix. - public static void Transformation2D(ref Float2 scalingCenter, float scalingRotation, ref Float2 scaling, ref Float2 rotationCenter, float rotation, ref Float2 translation, out Matrix result) + public static void Transformation2D(in Float2 scalingCenter, float scalingRotation, in Float2 scaling, in Float2 rotationCenter, float rotation, in Float2 translation, out Matrix result) { result = Translation((Float3)(-scalingCenter)) * RotationZ(-scalingRotation) * Scaling((Float3)scaling) * RotationZ(scalingRotation) * Translation((Float3)scalingCenter) * Translation((Float3)(-rotationCenter)) * RotationZ(rotation) * Translation((Float3)rotationCenter) * Translation((Float3)translation); result.M33 = 1f; @@ -2909,7 +2909,7 @@ namespace FlaxEngine /// The created transformation matrix. public static Matrix Transformation2D(Float2 scalingCenter, float scalingRotation, Float2 scaling, Float2 rotationCenter, float rotation, Float2 translation) { - Transformation2D(ref scalingCenter, scalingRotation, ref scaling, ref rotationCenter, rotation, ref translation, out var result); + Transformation2D(scalingCenter, scalingRotation, scaling, rotationCenter, rotation, translation, out var result); return result; } @@ -2922,7 +2922,7 @@ namespace FlaxEngine /// The created world matrix of given transformation world public static Matrix CreateWorld(Float3 position, Float3 forward, Float3 up) { - CreateWorld(ref position, ref forward, ref up, out var result); + CreateWorld(position, forward, up, out var result); return result; } @@ -2933,13 +2933,13 @@ namespace FlaxEngine /// The forward direction of the object. /// The upward direction of the object; usually [0, 1, 0]. /// >When the method completes, contains the created world matrix of given transformation world. - public static void CreateWorld(ref Float3 position, ref Float3 forward, ref Float3 up, out Matrix result) + public static void CreateWorld(in Float3 position, in Float3 forward, in Float3 up, out Matrix result) { - Float3.Normalize(ref forward, out var vector3); + Float3.Normalize(forward, out var vector3); vector3 = vector3.Negative; Float3 vector31 = Float3.Cross(up, vector3); vector31.Normalize(); - Float3.Cross(ref vector3, ref vector31, out var vector32); + Float3.Cross(vector3, vector31, out var vector32); result = new Matrix ( vector31.X, @@ -2969,7 +2969,7 @@ namespace FlaxEngine /// The created rotation matrix. public static Matrix CreateFromAxisAngle(Float3 axis, float angle) { - CreateFromAxisAngle(ref axis, angle, out var result); + CreateFromAxisAngle(axis, angle, out var result); return result; } @@ -2979,7 +2979,7 @@ namespace FlaxEngine /// The axis to rotate around. /// The angle to rotate around the vector. /// When the method completes, contains the created rotation matrix. - public static void CreateFromAxisAngle(ref Float3 axis, float angle, out Matrix result) + public static void CreateFromAxisAngle(in Float3 axis, float angle, out Matrix result) { float x = axis.X; float y = axis.Y; @@ -3021,7 +3021,7 @@ namespace FlaxEngine /// The sum of the two matrices. public static Matrix operator +(Matrix left, Matrix right) { - Add(ref left, ref right, out var result); + Add(left, right, out var result); return result; } @@ -3043,7 +3043,7 @@ namespace FlaxEngine /// The difference between the two matrices. public static Matrix operator -(Matrix left, Matrix right) { - Subtract(ref left, ref right, out var result); + Subtract(left, right, out var result); return result; } @@ -3054,7 +3054,7 @@ namespace FlaxEngine /// The negated matrix. public static Matrix operator -(Matrix value) { - Negate(ref value, out var result); + Negate(value, out var result); return result; } @@ -3066,7 +3066,7 @@ namespace FlaxEngine /// The scaled matrix. public static Matrix operator *(float left, Matrix right) { - Multiply(ref right, left, out var result); + Multiply(right, left, out var result); return result; } @@ -3078,7 +3078,7 @@ namespace FlaxEngine /// The scaled matrix. public static Matrix operator *(Matrix left, float right) { - Multiply(ref left, right, out var result); + Multiply(left, right, out var result); return result; } @@ -3090,7 +3090,7 @@ namespace FlaxEngine /// The product of the two matrices. public static Matrix operator *(Matrix left, Matrix right) { - Multiply(ref left, ref right, out var result); + Multiply(left, right, out var result); return result; } @@ -3102,7 +3102,7 @@ namespace FlaxEngine /// The scaled matrix. public static Matrix operator /(Matrix left, float right) { - Divide(ref left, right, out var result); + Divide(left, right, out var result); return result; } @@ -3114,7 +3114,7 @@ namespace FlaxEngine /// The quotient of the two matrices. public static Matrix operator /(Matrix left, Matrix right) { - Divide(ref left, ref right, out var result); + Divide(left, right, out var result); return result; } @@ -3127,7 +3127,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Matrix left, Matrix right) { - return left.Equals(ref right); + return left.Equals(right); } /// @@ -3139,7 +3139,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Matrix left, Matrix right) { - return !left.Equals(ref right); + return !left.Equals(right); } /// @@ -3234,7 +3234,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Matrix other) + public bool Equals(in Matrix other) { return other.M11 == M11 && other.M12 == M12 && @@ -3262,7 +3262,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Matrix other) { - return Equals(ref other); + return Equals(in other); } /// @@ -3272,7 +3272,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Matrix other && Equals(ref other); + return value is Matrix other && Equals(other); } } } diff --git a/Source/Engine/Core/Math/Matrix2x2.cs b/Source/Engine/Core/Math/Matrix2x2.cs index 7244d41bd..fd9b3d895 100644 --- a/Source/Engine/Core/Math/Matrix2x2.cs +++ b/Source/Engine/Core/Math/Matrix2x2.cs @@ -292,7 +292,7 @@ namespace FlaxEngine /// /// The scale vector. /// The result. - public static void Scale(ref Float2 scale, out Matrix2x2 result) + public static void Scale(in Float2 scale, out Matrix2x2 result) { result = new Matrix2x2(scale.X, 0, 0, scale.Y); } @@ -304,7 +304,7 @@ namespace FlaxEngine /// /// The shear angles. /// The result. - public static void Shear(ref Float2 shearAngles, out Matrix2x2 result) + public static void Shear(in Float2 shearAngles, out Matrix2x2 result) { float shearX = shearAngles.X == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(shearAngles.X, -89.0f, 89.0f)))); float shearY = shearAngles.Y == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(shearAngles.Y, -89.0f, 89.0f)))); @@ -329,7 +329,7 @@ namespace FlaxEngine /// The vector. /// The matrix. /// The result. - public static void Transform(ref Float2 vector, ref Matrix2x2 matrix, out Float2 result) + public static void Transform(in Float2 vector, in Matrix2x2 matrix, out Float2 result) { result = new Float2(vector.X * matrix.M11 + vector.Y * matrix.M21, vector.X * matrix.M12 + vector.Y * matrix.M22); } @@ -340,7 +340,7 @@ namespace FlaxEngine /// The first Matrix2x2 to multiply. /// The second Matrix2x2 to multiply. /// The product of the two matrices. - public static void Multiply(ref Matrix2x2 left, ref Matrix2x2 right, out Matrix2x2 result) + public static void Multiply(in Matrix2x2 left, in Matrix2x2 right, out Matrix2x2 result) { result = new Matrix2x2((left.M11 * right.M11) + (left.M12 * right.M21), (left.M11 * right.M12) + (left.M12 * right.M22), (left.M21 * right.M11) + (left.M22 * right.M21), (left.M21 * right.M12) + (left.M22 * right.M22)); } @@ -350,7 +350,7 @@ namespace FlaxEngine /// /// The Matrix2x2 whose inverse is to be calculated. /// When the method completes, contains the inverse of the specified Matrix2x2. - public static void Invert(ref Matrix2x2 value, out Matrix2x2 result) + public static void Invert(in Matrix2x2 value, out Matrix2x2 result) { float invDet = value.InverseDeterminant(); result = new Matrix2x2(value.M22 * invDet, -value.M12 * invDet, -value.M21 * invDet, value.M11 * invDet); @@ -365,7 +365,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Matrix2x2 left, Matrix2x2 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -377,7 +377,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Matrix2x2 left, Matrix2x2 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -481,7 +481,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Matrix2x2 other) + public bool Equals(in Matrix2x2 other) { return M11 == other.M11 && M12 == other.M12 && M21 == other.M21 && M22 == other.M22; } @@ -494,15 +494,15 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Matrix2x2 other) { - return Equals(ref other); + return Equals(in other); } /// /// Determines whether the specified are equal. /// - public static bool Equals(ref Matrix2x2 a, ref Matrix2x2 b) + public static bool Equals(in Matrix2x2 a, in Matrix2x2 b) { - return a.Equals(ref b); + return a.Equals(in b); } /// @@ -512,7 +512,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Matrix2x2 other && Equals(ref other); + return value is Matrix2x2 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Matrix3x3.cs b/Source/Engine/Core/Math/Matrix3x3.cs index 76e10ed1a..6dcb6db5a 100644 --- a/Source/Engine/Core/Math/Matrix3x3.cs +++ b/Source/Engine/Core/Math/Matrix3x3.cs @@ -411,7 +411,7 @@ namespace FlaxEngine /// public void Invert() { - Invert(ref this, out this); + Invert(this, out this); } /// @@ -419,7 +419,7 @@ namespace FlaxEngine /// public void Transpose() { - Transpose(ref this, out this); + Transpose(this, out this); } /// @@ -438,7 +438,7 @@ namespace FlaxEngine /// public void Orthogonalize() { - Orthogonalize(ref this, out this); + Orthogonalize(this, out this); } /// @@ -459,7 +459,7 @@ namespace FlaxEngine /// public void Orthonormalize() { - Orthonormalize(ref this, out this); + Orthonormalize(this, out this); } /// @@ -472,7 +472,7 @@ namespace FlaxEngine { Matrix3x3 temp = this; temp.Transpose(); - Orthonormalize(ref temp, out q); + Orthonormalize(temp, out q); q.Transpose(); r = new Matrix3x3 @@ -494,7 +494,7 @@ namespace FlaxEngine // ReSharper disable once InconsistentNaming public void DecomposeLQ(out Matrix3x3 l, out Matrix3x3 q) { - Orthonormalize(ref this, out q); + Orthonormalize(this, out q); l = new Matrix3x3 { @@ -548,7 +548,7 @@ namespace FlaxEngine M33 = M33 / scale.Z }; - Quaternion.RotationMatrix(ref rotationMatrix, out rotation); + Quaternion.RotationMatrix(rotationMatrix, out rotation); return true; } @@ -587,7 +587,7 @@ namespace FlaxEngine M32 = M32 * invScale, M33 = M33 * invScale }; - Quaternion.RotationMatrix(ref rotationMatrix, out rotation); + Quaternion.RotationMatrix(rotationMatrix, out rotation); return true; } @@ -681,7 +681,7 @@ namespace FlaxEngine /// The first Matrix3x3 to add. /// The second Matrix3x3 to add. /// When the method completes, contains the sum of the two matrices. - public static void Add(ref Matrix3x3 left, ref Matrix3x3 right, out Matrix3x3 result) + public static void Add(in Matrix3x3 left, in Matrix3x3 right, out Matrix3x3 result) { result.M11 = left.M11 + right.M11; result.M12 = left.M12 + right.M12; @@ -702,7 +702,7 @@ namespace FlaxEngine /// The sum of the two matrices. public static Matrix3x3 Add(Matrix3x3 left, Matrix3x3 right) { - Add(ref left, ref right, out Matrix3x3 result); + Add(left, right, out Matrix3x3 result); return result; } @@ -712,7 +712,7 @@ namespace FlaxEngine /// The first Matrix3x3 to subtract. /// The second Matrix3x3 to subtract. /// When the method completes, contains the difference between the two matrices. - public static void Subtract(ref Matrix3x3 left, ref Matrix3x3 right, out Matrix3x3 result) + public static void Subtract(in Matrix3x3 left, in Matrix3x3 right, out Matrix3x3 result) { result.M11 = left.M11 - right.M11; result.M12 = left.M12 - right.M12; @@ -733,7 +733,7 @@ namespace FlaxEngine /// The difference between the two matrices. public static Matrix3x3 Subtract(Matrix3x3 left, Matrix3x3 right) { - Subtract(ref left, ref right, out Matrix3x3 result); + Subtract(left, right, out Matrix3x3 result); return result; } @@ -743,7 +743,7 @@ namespace FlaxEngine /// The Matrix3x3 to scale. /// The amount by which to scale. /// When the method completes, contains the scaled Matrix3x3. - public static void Multiply(ref Matrix3x3 left, float right, out Matrix3x3 result) + public static void Multiply(in Matrix3x3 left, float right, out Matrix3x3 result) { result.M11 = left.M11 * right; result.M12 = left.M12 * right; @@ -764,7 +764,7 @@ namespace FlaxEngine /// The scaled Matrix3x3. public static Matrix3x3 Multiply(Matrix3x3 left, float right) { - Multiply(ref left, right, out Matrix3x3 result); + Multiply(left, right, out Matrix3x3 result); return result; } @@ -774,7 +774,7 @@ namespace FlaxEngine /// The first Matrix3x3 to multiply. /// The second Matrix3x3 to multiply. /// The product of the two matrices. - public static void Multiply(ref Matrix3x3 left, ref Matrix3x3 right, out Matrix3x3 result) + public static void Multiply(in Matrix3x3 left, in Matrix3x3 right, out Matrix3x3 result) { Matrix3x3 temp = new Matrix3x3 { @@ -799,7 +799,7 @@ namespace FlaxEngine /// The product of the two matrices. public static Matrix3x3 Multiply(Matrix3x3 left, Matrix3x3 right) { - Multiply(ref left, ref right, out Matrix3x3 result); + Multiply(left, right, out Matrix3x3 result); return result; } @@ -809,7 +809,7 @@ namespace FlaxEngine /// The Matrix3x3 to scale. /// The amount by which to scale. /// When the method completes, contains the scaled Matrix3x3. - public static void Divide(ref Matrix3x3 left, float right, out Matrix3x3 result) + public static void Divide(in Matrix3x3 left, float right, out Matrix3x3 result) { float inv = 1.0f / right; @@ -832,7 +832,7 @@ namespace FlaxEngine /// The scaled Matrix3x3. public static Matrix3x3 Divide(Matrix3x3 left, float right) { - Divide(ref left, right, out Matrix3x3 result); + Divide(left, right, out Matrix3x3 result); return result; } @@ -842,7 +842,7 @@ namespace FlaxEngine /// The first Matrix3x3 to divide. /// The second Matrix3x3 to divide. /// When the method completes, contains the quotient of the two matrices. - public static void Divide(ref Matrix3x3 left, ref Matrix3x3 right, out Matrix3x3 result) + public static void Divide(in Matrix3x3 left, in Matrix3x3 right, out Matrix3x3 result) { result.M11 = left.M11 / right.M11; result.M12 = left.M12 / right.M12; @@ -863,7 +863,7 @@ namespace FlaxEngine /// The quotient of the two matrices. public static Matrix3x3 Divide(Matrix3x3 left, Matrix3x3 right) { - Divide(ref left, ref right, out Matrix3x3 result); + Divide(left, right, out Matrix3x3 result); return result; } @@ -874,7 +874,7 @@ namespace FlaxEngine /// The exponent to raise the Matrix3x3 to. /// When the method completes, contains the exponential Matrix3x3. /// Thrown when the is negative. - public static void Exponent(ref Matrix3x3 value, int exponent, out Matrix3x3 result) + public static void Exponent(in Matrix3x3 value, int exponent, out Matrix3x3 result) { //Source: http://rosettacode.org //Reference: http://rosettacode.org/wiki/Matrix3x3-exponentiation_operator @@ -922,7 +922,7 @@ namespace FlaxEngine /// Thrown when the is negative. public static Matrix3x3 Exponent(Matrix3x3 value, int exponent) { - Exponent(ref value, exponent, out Matrix3x3 result); + Exponent(value, exponent, out Matrix3x3 result); return result; } @@ -931,7 +931,7 @@ namespace FlaxEngine /// /// The Matrix3x3 to be negated. /// When the method completes, contains the negated Matrix3x3. - public static void Negate(ref Matrix3x3 value, out Matrix3x3 result) + public static void Negate(in Matrix3x3 value, out Matrix3x3 result) { result.M11 = -value.M11; result.M12 = -value.M12; @@ -951,7 +951,7 @@ namespace FlaxEngine /// The negated Matrix3x3. public static Matrix3x3 Negate(Matrix3x3 value) { - Negate(ref value, out Matrix3x3 result); + Negate(value, out Matrix3x3 result); return result; } @@ -965,7 +965,7 @@ namespace FlaxEngine /// /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Matrix3x3 start, ref Matrix3x3 end, float amount, out Matrix3x3 result) + public static void Lerp(in Matrix3x3 start, in Matrix3x3 end, float amount, out Matrix3x3 result) { result.M11 = Mathf.Lerp(start.M11, end.M11, amount); result.M12 = Mathf.Lerp(start.M12, end.M12, amount); @@ -990,7 +990,7 @@ namespace FlaxEngine /// public static Matrix3x3 Lerp(Matrix3x3 start, Matrix3x3 end, float amount) { - Lerp(ref start, ref end, amount, out Matrix3x3 result); + Lerp(start, end, amount, out Matrix3x3 result); return result; } @@ -1001,10 +1001,10 @@ namespace FlaxEngine /// End Matrix3x3. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two matrices. - public static void SmoothStep(ref Matrix3x3 start, ref Matrix3x3 end, float amount, out Matrix3x3 result) + public static void SmoothStep(in Matrix3x3 start, in Matrix3x3 end, float amount, out Matrix3x3 result) { amount = Mathf.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(start, end, amount, out result); } /// @@ -1016,7 +1016,7 @@ namespace FlaxEngine /// The cubic interpolation of the two matrices. public static Matrix3x3 SmoothStep(Matrix3x3 start, Matrix3x3 end, float amount) { - SmoothStep(ref start, ref end, amount, out Matrix3x3 result); + SmoothStep(start, end, amount, out Matrix3x3 result); return result; } @@ -1025,7 +1025,7 @@ namespace FlaxEngine /// /// The Matrix3x3 whose transpose is to be calculated. /// When the method completes, contains the transpose of the specified Matrix3x3. - public static void Transpose(ref Matrix3x3 value, out Matrix3x3 result) + public static void Transpose(in Matrix3x3 value, out Matrix3x3 result) { Matrix3x3 temp = new Matrix3x3 { @@ -1048,7 +1048,7 @@ namespace FlaxEngine /// /// The Matrix3x3 whose transpose is to be calculated. /// When the method completes, contains the transpose of the specified Matrix3x3. - public static void TransposeByRef(ref Matrix3x3 value, ref Matrix3x3 result) + public static void TransposeByRef(in Matrix3x3 value, ref Matrix3x3 result) { result.M11 = value.M11; result.M12 = value.M21; @@ -1068,7 +1068,7 @@ namespace FlaxEngine /// The transpose of the specified Matrix3x3. public static Matrix3x3 Transpose(Matrix3x3 value) { - Transpose(ref value, out Matrix3x3 result); + Transpose(value, out Matrix3x3 result); return result; } @@ -1077,7 +1077,7 @@ namespace FlaxEngine /// /// The Matrix3x3 whose inverse is to be calculated. /// When the method completes, contains the inverse of the specified Matrix3x3. - public static void Invert(ref Matrix3x3 value, out Matrix3x3 result) + public static void Invert(in Matrix3x3 value, out Matrix3x3 result) { float d11 = value.M22 * value.M33 + value.M23 * -value.M32; float d12 = value.M21 * value.M33 + value.M23 * -value.M31; @@ -1138,7 +1138,7 @@ namespace FlaxEngine /// If you wish for this operation to be performed on the columns, first transpose the /// input and than transpose the output. /// - public static void Orthogonalize(ref Matrix3x3 value, out Matrix3x3 result) + public static void Orthogonalize(in Matrix3x3 value, out Matrix3x3 result) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -1172,7 +1172,7 @@ namespace FlaxEngine /// public static Matrix3x3 Orthogonalize(Matrix3x3 value) { - Orthogonalize(ref value, out Matrix3x3 result); + Orthogonalize(value, out Matrix3x3 result); return result; } @@ -1194,7 +1194,7 @@ namespace FlaxEngine /// If you wish for this operation to be performed on the columns, first transpose the /// input and than transpose the output. /// - public static void Orthonormalize(ref Matrix3x3 value, out Matrix3x3 result) + public static void Orthonormalize(in Matrix3x3 value, out Matrix3x3 result) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthonormalization @@ -1236,7 +1236,7 @@ namespace FlaxEngine /// public static Matrix3x3 Orthonormalize(Matrix3x3 value) { - Orthonormalize(ref value, out Matrix3x3 result); + Orthonormalize(value, out Matrix3x3 result); return result; } @@ -1251,7 +1251,7 @@ namespace FlaxEngine /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static void UpperTriangularForm(ref Matrix3x3 value, out Matrix3x3 result) + public static void UpperTriangularForm(in Matrix3x3 value, out Matrix3x3 result) { //Adapted from the row echelon code. result = value; @@ -1314,7 +1314,7 @@ namespace FlaxEngine /// public static Matrix3x3 UpperTriangularForm(Matrix3x3 value) { - UpperTriangularForm(ref value, out Matrix3x3 result); + UpperTriangularForm(value, out Matrix3x3 result); return result; } @@ -1329,11 +1329,11 @@ namespace FlaxEngine /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static void LowerTriangularForm(ref Matrix3x3 value, out Matrix3x3 result) + public static void LowerTriangularForm(in Matrix3x3 value, out Matrix3x3 result) { //Adapted from the row echelon code. Matrix3x3 temp = value; - Transpose(ref temp, out result); + Transpose(temp, out result); int lead = 0; int rowcount = 3; @@ -1380,7 +1380,7 @@ namespace FlaxEngine lead++; } - Transpose(ref result, out result); + Transpose(result, out result); } /// @@ -1396,7 +1396,7 @@ namespace FlaxEngine /// public static Matrix3x3 LowerTriangularForm(Matrix3x3 value) { - LowerTriangularForm(ref value, out Matrix3x3 result); + LowerTriangularForm(value, out Matrix3x3 result); return result; } @@ -1405,7 +1405,7 @@ namespace FlaxEngine /// /// The Matrix3x3 to put into row echelon form. /// When the method completes, contains the row echelon form of the Matrix3x3. - public static void RowEchelonForm(ref Matrix3x3 value, out Matrix3x3 result) + public static void RowEchelonForm(in Matrix3x3 value, out Matrix3x3 result) { //Source: Wikipedia pseudo code //Reference: http://en.wikipedia.org/wiki/Row_echelon_form#Pseudocode @@ -1467,7 +1467,7 @@ namespace FlaxEngine /// When the method completes, contains the row echelon form of the Matrix3x3. public static Matrix3x3 RowEchelonForm(Matrix3x3 value) { - RowEchelonForm(ref value, out Matrix3x3 result); + RowEchelonForm(value, out Matrix3x3 result); return result; } @@ -1479,7 +1479,7 @@ namespace FlaxEngine /// The up vector of the camera. /// The forward vector of the camera. /// When the method completes, contains the created billboard Matrix3x3. - public static void Billboard(ref Float3 objectPosition, ref Float3 cameraPosition, ref Float3 cameraUpFloat, ref Float3 cameraForwardFloat, out Matrix3x3 result) + public static void Billboard(in Float3 objectPosition, in Float3 cameraPosition, in Float3 cameraUpFloat, in Float3 cameraForwardFloat, out Matrix3x3 result) { Float3 difference = cameraPosition - objectPosition; @@ -1489,9 +1489,9 @@ namespace FlaxEngine else difference *= (float)(1.0 / Math.Sqrt(lengthSq)); - Float3.Cross(ref cameraUpFloat, ref difference, out Float3 crossed); + Float3.Cross(cameraUpFloat, difference, out Float3 crossed); crossed.Normalize(); - Float3.Cross(ref difference, ref crossed, out Float3 final); + Float3.Cross(difference, crossed, out Float3 final); result.M11 = crossed.X; result.M12 = crossed.Y; @@ -1514,7 +1514,7 @@ namespace FlaxEngine /// The created billboard Matrix3x3. public static Matrix3x3 Billboard(Float3 objectPosition, Float3 cameraPosition, Float3 cameraUpFloat, Float3 cameraForwardFloat) { - Billboard(ref objectPosition, ref cameraPosition, ref cameraUpFloat, ref cameraForwardFloat, out Matrix3x3 result); + Billboard(objectPosition, cameraPosition, cameraUpFloat, cameraForwardFloat, out Matrix3x3 result); return result; } @@ -1525,15 +1525,15 @@ namespace FlaxEngine /// The camera look-at target. /// The camera's up vector. /// When the method completes, contains the created look-at Matrix3x3. - public static void LookAt(ref Float3 eye, ref Float3 target, ref Float3 up, out Matrix3x3 result) + public static void LookAt(in Float3 eye, in Float3 target, in Float3 up, out Matrix3x3 result) { - Float3.Subtract(ref target, ref eye, out Float3 zaxis); + Float3.Subtract(target, eye, out Float3 zaxis); zaxis.Normalize(); - Float3.Cross(ref up, ref zaxis, out Float3 xaxis); + Float3.Cross(up, zaxis, out Float3 xaxis); xaxis.Normalize(); - Float3.Cross(ref zaxis, ref xaxis, out Float3 yaxis); + Float3.Cross(zaxis, xaxis, out Float3 yaxis); result = Identity; result.M11 = xaxis.X; @@ -1556,7 +1556,7 @@ namespace FlaxEngine /// The created look-at Matrix3x3. public static Matrix3x3 LookAt(Float3 eye, Float3 target, Float3 up) { - LookAt(ref eye, ref target, ref up, out Matrix3x3 result); + LookAt(eye, target, up, out Matrix3x3 result); return result; } @@ -1565,7 +1565,7 @@ namespace FlaxEngine /// /// Scaling factor for all three axes. /// When the method completes, contains the created scaling Matrix3x3. - public static void Scaling(ref Float3 scale, out Matrix3x3 result) + public static void Scaling(in Float3 scale, out Matrix3x3 result) { Scaling(scale.X, scale.Y, scale.Z, out result); } @@ -1577,7 +1577,7 @@ namespace FlaxEngine /// The created scaling Matrix3x3. public static Matrix3x3 Scaling(Float3 scale) { - Scaling(ref scale, out Matrix3x3 result); + Scaling(scale, out Matrix3x3 result); return result; } @@ -1639,7 +1639,7 @@ namespace FlaxEngine /// /// The shear angles (in degrees). /// The result. - public static void Shear(ref Float2 shearAngles, out Matrix3x3 result) + public static void Shear(in Float2 shearAngles, out Matrix3x3 result) { float shearX = shearAngles.X == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(shearAngles.X, -89.0f, 89.0f)))); float shearY = shearAngles.Y == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(shearAngles.Y, -89.0f, 89.0f)))); @@ -1739,7 +1739,7 @@ namespace FlaxEngine /// The axis around which to rotate. This parameter is assumed to be normalized. /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// When the method completes, contains the created rotation Matrix3x3. - public static void RotationAxis(ref Float3 axis, float angle, out Matrix3x3 result) + public static void RotationAxis(in Float3 axis, float angle, out Matrix3x3 result) { float x = axis.X; float y = axis.Y; @@ -1773,7 +1773,7 @@ namespace FlaxEngine /// The created rotation Matrix3x3. public static Matrix3x3 RotationAxis(Float3 axis, float angle) { - RotationAxis(ref axis, angle, out Matrix3x3 result); + RotationAxis(axis, angle, out Matrix3x3 result); return result; } @@ -1782,7 +1782,7 @@ namespace FlaxEngine /// /// The quaternion to use to build the Matrix3x3. /// The created rotation Matrix3x3. - public static void RotationQuaternion(ref Quaternion rotation, out Matrix3x3 result) + public static void RotationQuaternion(in Quaternion rotation, out Matrix3x3 result) { float xx = rotation.X * rotation.X; float yy = rotation.Y * rotation.Y; @@ -1813,7 +1813,7 @@ namespace FlaxEngine /// The created rotation Matrix3x3. public static Matrix3x3 RotationQuaternion(Quaternion rotation) { - RotationQuaternion(ref rotation, out Matrix3x3 result); + RotationQuaternion(rotation, out Matrix3x3 result); return result; } @@ -1827,7 +1827,7 @@ namespace FlaxEngine public static void RotationYawPitchRoll(float yaw, float pitch, float roll, out Matrix3x3 result) { Quaternion.RotationYawPitchRoll(yaw, pitch, roll, out Quaternion quaternion); - RotationQuaternion(ref quaternion, out result); + RotationQuaternion(quaternion, out result); } /// @@ -1848,9 +1848,9 @@ namespace FlaxEngine /// /// The translation vector. /// The result. - public static void Translation2D(ref Float2 translation, out Matrix3x3 result) + public static void Translation2D(in Float2 translation, out Matrix3x3 result) { - result = new Matrix3x3( 1, 0, 0, 0, 1, 0, translation.X, translation.Y, 1); + result = new Matrix3x3(1, 0, 0, 0, 1, 0, translation.X, translation.Y, 1); } /// @@ -1880,7 +1880,7 @@ namespace FlaxEngine /// The vector. /// The transform. /// The result. - public static void Transform2D(ref Float2 vector, ref Matrix3x3 transform, out Float2 result) + public static void Transform2D(in Float2 vector, in Matrix3x3 transform, out Float2 result) { result = new Float2((vector.X * transform.M11) + (vector.Y * transform.M21) + transform.M31, (vector.X * transform.M12) + (vector.Y * transform.M22) + transform.M32); } @@ -1893,7 +1893,7 @@ namespace FlaxEngine /// The result. public static Float2 Transform2D(Float2 vector, Matrix3x3 transform) { - Transform2D(ref vector, ref transform, out Float2 result); + Transform2D(vector, transform, out Float2 result); return result; } @@ -1905,7 +1905,7 @@ namespace FlaxEngine /// The sum of the two matrices. public static Matrix3x3 operator +(Matrix3x3 left, Matrix3x3 right) { - Add(ref left, ref right, out Matrix3x3 result); + Add(left, right, out Matrix3x3 result); return result; } @@ -1927,7 +1927,7 @@ namespace FlaxEngine /// The difference between the two matrices. public static Matrix3x3 operator -(Matrix3x3 left, Matrix3x3 right) { - Subtract(ref left, ref right, out Matrix3x3 result); + Subtract(left, right, out Matrix3x3 result); return result; } @@ -1938,7 +1938,7 @@ namespace FlaxEngine /// The negated Matrix3x3. public static Matrix3x3 operator -(Matrix3x3 value) { - Negate(ref value, out Matrix3x3 result); + Negate(value, out Matrix3x3 result); return result; } @@ -1950,7 +1950,7 @@ namespace FlaxEngine /// The scaled Matrix3x3. public static Matrix3x3 operator *(float left, Matrix3x3 right) { - Multiply(ref right, left, out Matrix3x3 result); + Multiply(right, left, out Matrix3x3 result); return result; } @@ -1962,7 +1962,7 @@ namespace FlaxEngine /// The scaled Matrix3x3. public static Matrix3x3 operator *(Matrix3x3 left, float right) { - Multiply(ref left, right, out Matrix3x3 result); + Multiply(left, right, out Matrix3x3 result); return result; } @@ -1974,7 +1974,7 @@ namespace FlaxEngine /// The product of the two matrices. public static Matrix3x3 operator *(Matrix3x3 left, Matrix3x3 right) { - Multiply(ref left, ref right, out Matrix3x3 result); + Multiply(left, right, out Matrix3x3 result); return result; } @@ -1986,7 +1986,7 @@ namespace FlaxEngine /// The scaled Matrix3x3. public static Matrix3x3 operator /(Matrix3x3 left, float right) { - Divide(ref left, right, out Matrix3x3 result); + Divide(left, right, out Matrix3x3 result); return result; } @@ -1998,7 +1998,7 @@ namespace FlaxEngine /// The quotient of the two matrices. public static Matrix3x3 operator /(Matrix3x3 left, Matrix3x3 right) { - Divide(ref left, ref right, out Matrix3x3 result); + Divide(left, right, out Matrix3x3 result); return result; } @@ -2011,7 +2011,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Matrix3x3 left, Matrix3x3 right) { - return left.Equals(ref right); + return left.Equals(right); } /// @@ -2023,7 +2023,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Matrix3x3 left, Matrix3x3 right) { - return !left.Equals(ref right); + return !left.Equals(right); } /// @@ -2123,7 +2123,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Matrix3x3 other) + public bool Equals(in Matrix3x3 other) { return M11 == other.M11 && M12 == other.M12 && @@ -2144,15 +2144,15 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Matrix3x3 other) { - return Equals(ref other); + return Equals(in other); } /// /// Determines whether the specified are equal. /// - public static bool Equals(ref Matrix3x3 a, ref Matrix3x3 b) + public static bool Equals(in Matrix3x3 a, in Matrix3x3 b) { - return a.Equals(ref b); + return a.Equals(b); } /// @@ -2162,7 +2162,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Matrix3x3 other && Equals(ref other); + return value is Matrix3x3 other && Equals(other); } } } diff --git a/Source/Engine/Core/Math/OrientedBoundingBox.cs b/Source/Engine/Core/Math/OrientedBoundingBox.cs index 59ffd0009..a29d61cab 100644 --- a/Source/Engine/Core/Math/OrientedBoundingBox.cs +++ b/Source/Engine/Core/Math/OrientedBoundingBox.cs @@ -88,8 +88,8 @@ namespace FlaxEngine var maximum = points[0]; for (var i = 1; i < points.Length; ++i) { - Vector3.Min(ref minimum, ref points[i], out minimum); - Vector3.Max(ref maximum, ref points[i], out maximum); + Vector3.Min(minimum, points[i], out minimum); + Vector3.Max(maximum, points[i], out maximum); } Vector3 center = minimum + (maximum - minimum) * 0.5f; Extents = maximum - center; @@ -156,7 +156,7 @@ namespace FlaxEngine /// /// The transformation. /// While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation for rotation only, and that preserves collision detection accuracy. - public void Transform(ref Transform transform) + public void Transform(in Transform transform) { Transformation = transform.LocalToWorld(Transformation); } @@ -166,7 +166,7 @@ namespace FlaxEngine /// /// The transformation matrix. /// While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy. - public void Transform(ref Matrix mat) + public void Transform(in Matrix mat) { mat.Decompose(out var transform); Transformation = transform.LocalToWorld(Transformation); @@ -179,14 +179,14 @@ namespace FlaxEngine /// While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy. public void Transform(Matrix mat) { - Transform(ref mat); + Transform(in mat); } /// /// Scales the by scaling its Extents without affecting the Transformation matrix, By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate. /// /// - public void Scale(ref Vector3 scaling) + public void Scale(in Vector3 scaling) { Extents *= scaling; } @@ -213,7 +213,7 @@ namespace FlaxEngine /// Translates the to a new position using a translation vector; /// /// the translation vector. - public void Translate(ref Vector3 translation) + public void Translate(in Vector3 translation) { Transformation.Translation += translation; } @@ -268,10 +268,10 @@ namespace FlaxEngine /// /// The point to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vector3 point) + public ContainmentType Contains(in Vector3 point) { // Transform the point into the obb coordinates - Transformation.WorldToLocal(ref point, out Vector3 locPoint); + Transformation.WorldToLocal(point, out Vector3 locPoint); locPoint.X = Math.Abs(locPoint.X); locPoint.Y = Math.Abs(locPoint.Y); locPoint.Z = Math.Abs(locPoint.Z); @@ -291,7 +291,7 @@ namespace FlaxEngine /// The type of containment the two objects have. public ContainmentType Contains(Vector3 point) { - return Contains(ref point); + return Contains(in point); } /// @@ -304,7 +304,7 @@ namespace FlaxEngine public ContainmentType Contains(BoundingSphere sphere, bool ignoreScale = false) { // Transform sphere center into the obb coordinates - Transformation.WorldToLocal(ref sphere.Center, out Vector3 locCenter); + Transformation.WorldToLocal(sphere.Center, out Vector3 locCenter); Real locRadius; if (ignoreScale) @@ -313,14 +313,14 @@ namespace FlaxEngine { // Transform sphere radius into the obb coordinates Vector3 vRadius = Vector3.UnitX * sphere.Radius; - Transformation.LocalToWorldVector(ref vRadius, out vRadius); + Transformation.LocalToWorldVector(vRadius, out vRadius); locRadius = vRadius.Length; } // Perform regular BoundingBox to BoundingSphere containment check Vector3 minusExtens = -Extents; - Vector3.Clamp(ref locCenter, ref minusExtens, ref Extents, out Vector3 vector); - Real distance = Vector3.DistanceSquared(ref locCenter, ref vector); + Vector3.Clamp(locCenter, minusExtens, Extents, out Vector3 vector); + Real distance = Vector3.DistanceSquared(locCenter, vector); if (distance > locRadius * locRadius) return ContainmentType.Disjoint; @@ -335,20 +335,20 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vector3 point) + public bool Intersects(in Ray ray, out Vector3 point) { // Put ray in box space Ray bRay; - Transformation.WorldToLocalVector(ref ray.Direction, out bRay.Direction); - Transformation.WorldToLocal(ref ray.Position, out bRay.Position); + Transformation.WorldToLocalVector(ray.Direction, out bRay.Direction); + Transformation.WorldToLocal(ray.Position, out bRay.Position); // Perform a regular ray to BoundingBox check var bb = new BoundingBox(-Extents, Extents); - bool intersects = CollisionsHelper.RayIntersectsBox(ref bRay, ref bb, out point); + bool intersects = CollisionsHelper.RayIntersectsBox(bRay, bb, out point); // Put the result intersection back to world if (intersects) - Transformation.LocalToWorld(ref point, out point); + Transformation.LocalToWorld(point, out point); return intersects; } @@ -359,11 +359,11 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the distance of intersection from the ray start, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Real distance) + public bool Intersects(in Ray ray, out Real distance) { - if (Intersects(ref ray, out Vector3 point)) + if (Intersects(in ray, out Vector3 point)) { - Vector3.Distance(ref ray.Position, ref point, out distance); + Vector3.Distance(ray.Position, point, out distance); return true; } distance = 0; @@ -375,9 +375,9 @@ namespace FlaxEngine /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects(in Ray ray) { - return Intersects(ref ray, out Vector3 _); + return Intersects(in ray, out Vector3 _); } /// @@ -395,7 +395,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref OrientedBoundingBox value) + public bool Equals(in OrientedBoundingBox value) { return Extents == value.Extents && Transformation == value.Transformation; } @@ -408,7 +408,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(OrientedBoundingBox value) { - return Equals(ref value); + return Equals(in value); } /// @@ -418,7 +418,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is OrientedBoundingBox other && Equals(ref other); + return value is OrientedBoundingBox other && Equals(in other); } /// @@ -431,7 +431,7 @@ namespace FlaxEngine public static OrientedBoundingBox operator *(OrientedBoundingBox box, Matrix transform) { OrientedBoundingBox result = box; - result.Transform(ref transform); + result.Transform(transform); return result; } @@ -458,7 +458,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(OrientedBoundingBox left, OrientedBoundingBox right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -470,7 +470,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(OrientedBoundingBox left, OrientedBoundingBox right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// diff --git a/Source/Engine/Core/Math/Plane.cs b/Source/Engine/Core/Math/Plane.cs index 7156f4562..a64492fc2 100644 --- a/Source/Engine/Core/Math/Plane.cs +++ b/Source/Engine/Core/Math/Plane.cs @@ -201,9 +201,9 @@ namespace FlaxEngine /// /// The point to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Vector3 point) + public PlaneIntersectionType Intersects(in Vector3 point) { - return CollisionsHelper.PlaneIntersectsPoint(ref this, ref point); + return CollisionsHelper.PlaneIntersectsPoint(this, point); } /// @@ -211,9 +211,9 @@ namespace FlaxEngine /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects(in Ray ray) { - return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out Real _); + return CollisionsHelper.RayIntersectsPlane(ray, this, out Real _); } /// @@ -222,9 +222,9 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Real distance) + public bool Intersects(in Ray ray, out Real distance) { - return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out distance); + return CollisionsHelper.RayIntersectsPlane(ray, this, out distance); } /// @@ -233,9 +233,9 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vector3 point) + public bool Intersects(in Ray ray, out Vector3 point) { - return CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out point); + return CollisionsHelper.RayIntersectsPlane(ray, this, out point); } /// @@ -243,9 +243,9 @@ namespace FlaxEngine /// /// The plane to test. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane) + public bool Intersects(in Plane plane) { - return CollisionsHelper.PlaneIntersectsPlane(ref this, ref plane); + return CollisionsHelper.PlaneIntersectsPlane(this, plane); } /// @@ -254,9 +254,9 @@ namespace FlaxEngine /// The plane to test. /// When the method completes, contains the line of intersection as a , or a zero ray if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane, out Ray line) + public bool Intersects(in Plane plane, out Ray line) { - return CollisionsHelper.PlaneIntersectsPlane(ref this, ref plane, out line); + return CollisionsHelper.PlaneIntersectsPlane(this, plane, out line); } /// @@ -266,9 +266,9 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public PlaneIntersectionType Intersects(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { - return CollisionsHelper.PlaneIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); + return CollisionsHelper.PlaneIntersectsTriangle(this, vertex1, vertex2, vertex3); } /// @@ -276,9 +276,9 @@ namespace FlaxEngine /// /// The box to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref BoundingBox box) + public PlaneIntersectionType Intersects(in BoundingBox box) { - return CollisionsHelper.PlaneIntersectsBox(ref this, ref box); + return CollisionsHelper.PlaneIntersectsBox(this, box); } /// @@ -286,9 +286,9 @@ namespace FlaxEngine /// /// The sphere to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref BoundingSphere sphere) + public PlaneIntersectionType Intersects(in BoundingSphere sphere) { - return CollisionsHelper.PlaneIntersectsSphere(ref this, ref sphere); + return CollisionsHelper.PlaneIntersectsSphere(this, sphere); } /// @@ -297,7 +297,7 @@ namespace FlaxEngine /// The plane to scale. /// The amount by which to scale the plane. /// When the method completes, contains the scaled plane. - public static void Multiply(ref Plane value, Real scale, out Plane result) + public static void Multiply(in Plane value, Real scale, out Plane result) { result.Normal.X = value.Normal.X * scale; result.Normal.Y = value.Normal.Y * scale; @@ -322,7 +322,7 @@ namespace FlaxEngine /// The source plane. /// The source vector. /// When the method completes, contains the dot product of the specified plane and vector. - public static void Dot(ref Plane left, ref Vector4 right, out Real result) + public static void Dot(in Plane left, in Vector4 right, out Real result) { result = left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z + left.D * right.W; } @@ -344,7 +344,7 @@ namespace FlaxEngine /// The source plane. /// The source vector. /// When the method completes, contains the dot product of a specified vector and the normal of the Plane plus the distance value of the plane. - public static void DotCoordinate(ref Plane left, ref Vector3 right, out Real result) + public static void DotCoordinate(in Plane left, in Vector3 right, out Real result) { result = left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z + left.D; } @@ -366,7 +366,7 @@ namespace FlaxEngine /// The source plane. /// The source vector. /// When the method completes, contains the dot product of the specified vector and the normal of the plane. - public static void DotNormal(ref Plane left, ref Vector3 right, out Real result) + public static void DotNormal(in Plane left, in Vector3 right, out Real result) { result = left.Normal.X * right.X + left.Normal.Y * right.Y + left.Normal.Z * right.Z; } @@ -387,7 +387,7 @@ namespace FlaxEngine /// /// The source plane. /// When the method completes, contains the normalized plane. - public static void Normalize(ref Plane plane, out Plane result) + public static void Normalize(in Plane plane, out Plane result) { Real magnitude = 1.0f / (Real)Math.Sqrt(plane.Normal.X * plane.Normal.X + plane.Normal.Y * plane.Normal.Y + plane.Normal.Z * plane.Normal.Z); result.Normal.X = plane.Normal.X * magnitude; @@ -413,7 +413,7 @@ namespace FlaxEngine /// The normalized source plane. /// The quaternion rotation. /// When the method completes, contains the transformed plane. - public static void Transform(ref Plane plane, ref Quaternion rotation, out Plane result) + public static void Transform(in Plane plane, in Quaternion rotation, out Plane result) { Real x2 = rotation.X + rotation.X; Real y2 = rotation.Y + rotation.Y; @@ -446,7 +446,7 @@ namespace FlaxEngine /// The transformed plane. public static Plane Transform(Plane plane, Quaternion rotation) { - Transform(ref plane, ref rotation, out var result); + Transform(in plane, in rotation, out var result); return result; } @@ -456,13 +456,13 @@ namespace FlaxEngine /// The normalized source plane. /// The transformation matrix. /// When the method completes, contains the transformed plane. - public static void Transform(ref Plane plane, ref Matrix transformation, out Plane result) + public static void Transform(in Plane plane, in Matrix transformation, out Plane result) { Real x = plane.Normal.X; Real y = plane.Normal.Y; Real z = plane.Normal.Z; Real d = plane.D; - Matrix.Invert(ref transformation, out Matrix inverse); + Matrix.Invert(transformation, out Matrix inverse); result.Normal.X = x * inverse.M11 + y * inverse.M12 + z * inverse.M13 + d * inverse.M14; result.Normal.Y = x * inverse.M21 + y * inverse.M22 + z * inverse.M23 + d * inverse.M24; result.Normal.Z = x * inverse.M31 + y * inverse.M32 + z * inverse.M33 + d * inverse.M34; @@ -477,7 +477,7 @@ namespace FlaxEngine /// When the method completes, contains the transformed plane. public static Plane Transform(Plane plane, Matrix transformation) { - Transform(ref plane, ref transformation, out var result); + Transform(in plane, in transformation, out var result); return result; } @@ -512,7 +512,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Plane left, Plane right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -524,7 +524,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Plane left, Plane right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -585,7 +585,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Plane other) + public bool Equals(in Plane other) { return Normal == other.Normal && D == other.D; } @@ -598,7 +598,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Plane other) { - return Equals(ref other); + return Equals(in other); } /// @@ -608,7 +608,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Plane other && Equals(ref other); + return value is Plane other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index d89b71488..1592f220e 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -368,7 +368,7 @@ namespace FlaxEngine /// The first quaternion to add. /// The second quaternion to add. /// When the method completes, contains the sum of the two quaternions. - public static void Add(ref Quaternion left, ref Quaternion right, out Quaternion result) + public static void Add(in Quaternion left, in Quaternion right, out Quaternion result) { result.X = left.X + right.X; result.Y = left.Y + right.Y; @@ -384,7 +384,7 @@ namespace FlaxEngine /// The sum of the two quaternions. public static Quaternion Add(Quaternion left, Quaternion right) { - Add(ref left, ref right, out var result); + Add(in left, in right, out var result); return result; } @@ -394,7 +394,7 @@ namespace FlaxEngine /// The first quaternion to subtract. /// The second quaternion to subtract. /// When the method completes, contains the difference of the two quaternions. - public static void Subtract(ref Quaternion left, ref Quaternion right, out Quaternion result) + public static void Subtract(in Quaternion left, in Quaternion right, out Quaternion result) { result.X = left.X - right.X; result.Y = left.Y - right.Y; @@ -410,7 +410,7 @@ namespace FlaxEngine /// The difference of the two quaternions. public static Quaternion Subtract(Quaternion left, Quaternion right) { - Subtract(ref left, ref right, out var result); + Subtract(in left, in right, out var result); return result; } @@ -420,7 +420,7 @@ namespace FlaxEngine /// The quaternion to scale. /// The amount by which to scale the quaternion. /// When the method completes, contains the scaled quaternion. - public static void Multiply(ref Quaternion value, float scale, out Quaternion result) + public static void Multiply(in Quaternion value, float scale, out Quaternion result) { result.X = value.X * scale; result.Y = value.Y * scale; @@ -436,7 +436,7 @@ namespace FlaxEngine /// The scaled quaternion. public static Quaternion Multiply(Quaternion value, float scale) { - Multiply(ref value, scale, out var result); + Multiply(in value, scale, out var result); return result; } @@ -446,7 +446,7 @@ namespace FlaxEngine /// The first quaternion to multiply. /// The second quaternion to multiply. /// When the method completes, contains the multiplied quaternion. - public static void Multiply(ref Quaternion left, ref Quaternion right, out Quaternion result) + public static void Multiply(in Quaternion left, in Quaternion right, out Quaternion result) { float a = left.Y * right.Z - left.Z * right.Y; float b = left.Z * right.X - left.X * right.Z; @@ -466,7 +466,7 @@ namespace FlaxEngine /// The multiplied quaternion. public static Quaternion Multiply(Quaternion left, Quaternion right) { - Multiply(ref left, ref right, out var result); + Multiply(in left, in right, out var result); return result; } @@ -475,7 +475,7 @@ namespace FlaxEngine /// /// The quaternion to negate. /// When the method completes, contains a quaternion facing in the opposite direction. - public static void Negate(ref Quaternion value, out Quaternion result) + public static void Negate(in Quaternion value, out Quaternion result) { result.X = -value.X; result.Y = -value.Y; @@ -490,7 +490,7 @@ namespace FlaxEngine /// A quaternion facing in the opposite direction. public static Quaternion Negate(Quaternion value) { - Negate(ref value, out var result); + Negate(in value, out var result); return result; } @@ -503,11 +503,11 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains a new containing the 4D Cartesian coordinates of the specified point. - public static void Barycentric(ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, float amount1, float amount2, out Quaternion result) + public static void Barycentric(in Quaternion value1, in Quaternion value2, in Quaternion value3, float amount1, float amount2, out Quaternion result) { - Slerp(ref value1, ref value2, amount1 + amount2, out var start); - Slerp(ref value1, ref value3, amount1 + amount2, out var end); - Slerp(ref start, ref end, amount2 / (amount1 + amount2), out result); + Slerp(in value1, in value2, amount1 + amount2, out var start); + Slerp(in value1, in value3, amount1 + amount2, out var end); + Slerp(in start, in end, amount2 / (amount1 + amount2), out result); } /// @@ -521,7 +521,7 @@ namespace FlaxEngine /// A new containing the 4D Cartesian coordinates of the specified point. public static Quaternion Barycentric(Quaternion value1, Quaternion value2, Quaternion value3, float amount1, float amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out var result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out var result); return result; } @@ -530,7 +530,7 @@ namespace FlaxEngine /// /// The quaternion to conjugate. /// When the method completes, contains the conjugated quaternion. - public static void Conjugate(ref Quaternion value, out Quaternion result) + public static void Conjugate(in Quaternion value, out Quaternion result) { result.X = -value.X; result.Y = -value.Y; @@ -545,7 +545,7 @@ namespace FlaxEngine /// The conjugated quaternion. public static Quaternion Conjugate(Quaternion value) { - Conjugate(ref value, out var result); + Conjugate(in value, out var result); return result; } @@ -555,7 +555,7 @@ namespace FlaxEngine /// First source quaternion. /// Second source quaternion. /// The dot product of the two quaternions. - public static float Dot(ref Quaternion left, ref Quaternion right) + public static float Dot(in Quaternion left, in Quaternion right) { return left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } @@ -588,7 +588,7 @@ namespace FlaxEngine /// /// The quaternion to exponentiate. /// When the method completes, contains the exponentiated quaternion. - public static void Exponential(ref Quaternion value, out Quaternion result) + public static void Exponential(in Quaternion value, out Quaternion result) { var angle = (float)Math.Sqrt(value.X * value.X + value.Y * value.Y + value.Z * value.Z); var sin = (float)Math.Sin(angle); @@ -615,7 +615,7 @@ namespace FlaxEngine /// The exponentiated quaternion. public static Quaternion Exponential(Quaternion value) { - Exponential(ref value, out var result); + Exponential(in value, out var result); return result; } @@ -624,7 +624,7 @@ namespace FlaxEngine /// /// The quaternion to conjugate and renormalize. /// When the method completes, contains the conjugated and renormalized quaternion. - public static void Invert(ref Quaternion value, out Quaternion result) + public static void Invert(in Quaternion value, out Quaternion result) { result = value; result.Invert(); @@ -680,7 +680,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 /// will cause to be returned. /// - public static void Lerp(ref Quaternion start, ref Quaternion end, float amount, out Quaternion result) + public static void Lerp(in Quaternion start, in Quaternion end, float amount, out Quaternion result) { float inverse = 1.0f - amount; @@ -717,7 +717,7 @@ namespace FlaxEngine /// public static Quaternion Lerp(Quaternion start, Quaternion end, float amount) { - Lerp(ref start, ref end, amount, out var result); + Lerp(in start, in end, amount, out var result); return result; } @@ -726,7 +726,7 @@ namespace FlaxEngine /// /// The quaternion whose logarithm will be calculated. /// When the method completes, contains the natural logarithm of the quaternion. - public static void Logarithm(ref Quaternion value, out Quaternion result) + public static void Logarithm(in Quaternion value, out Quaternion result) { if (Math.Abs(value.W) < 1.0) { @@ -760,7 +760,7 @@ namespace FlaxEngine /// The natural logarithm of the quaternion. public static Quaternion Logarithm(Quaternion value) { - Logarithm(ref value, out var result); + Logarithm(in value, out var result); return result; } @@ -769,7 +769,7 @@ namespace FlaxEngine /// /// The quaternion to normalize. /// When the method completes, contains the normalized quaternion. - public static void Normalize(ref Quaternion value, out Quaternion result) + public static void Normalize(in Quaternion value, out Quaternion result) { Quaternion temp = value; result = temp; @@ -793,9 +793,9 @@ namespace FlaxEngine /// The axis of rotation. /// The angle of rotation (in radians). /// When the method completes, contains the newly created quaternion. - public static void RotationAxis(ref Float3 axis, float angle, out Quaternion result) + public static void RotationAxis(in Float3 axis, float angle, out Quaternion result) { - Float3.Normalize(ref axis, out var normalized); + Float3.Normalize(axis, out var normalized); float half = angle * 0.5f; var sin = (float)Math.Sin(half); @@ -815,7 +815,7 @@ namespace FlaxEngine /// The newly created quaternion. public static Quaternion RotationAxis(Float3 axis, float angle) { - RotationAxis(ref axis, angle, out var result); + RotationAxis(in axis, angle, out var result); return result; } @@ -824,7 +824,7 @@ namespace FlaxEngine /// /// The rotation matrix. /// When the method completes, contains the newly created quaternion. - public static void RotationMatrix(ref Matrix matrix, out Quaternion result) + public static void RotationMatrix(in Matrix matrix, out Quaternion result) { float sqrt; float half; @@ -877,7 +877,7 @@ namespace FlaxEngine /// /// The rotation matrix. /// When the method completes, contains the newly created quaternion. - public static void RotationMatrix(ref Matrix3x3 matrix, out Quaternion result) + public static void RotationMatrix(in Matrix3x3 matrix, out Quaternion result) { float sqrt; float half; @@ -932,10 +932,10 @@ namespace FlaxEngine /// The camera look-at target. /// The camera's up vector. /// When the method completes, contains the created look-at quaternion. - public static void LookAt(ref Float3 eye, ref Float3 target, ref Float3 up, out Quaternion result) + public static void LookAt(in Float3 eye, in Float3 target, in Float3 up, out Quaternion result) { - Matrix3x3.LookAt(ref eye, ref target, ref up, out var matrix); - RotationMatrix(ref matrix, out result); + Matrix3x3.LookAt(eye, target, up, out var matrix); + RotationMatrix(in matrix, out result); } /// @@ -958,7 +958,7 @@ namespace FlaxEngine /// The created look-at quaternion. public static Quaternion LookAt(Float3 eye, Float3 target, Float3 up) { - LookAt(ref eye, ref target, ref up, out var result); + LookAt(in eye, in target, in up, out var result); return result; } @@ -968,10 +968,10 @@ namespace FlaxEngine /// The camera's forward direction. /// The camera's up vector. /// When the method completes, contains the created look-at quaternion. - public static void RotationLookAt(ref Float3 forward, ref Float3 up, out Quaternion result) + public static void RotationLookAt(in Float3 forward, in Float3 up, out Quaternion result) { var eye = Float3.Zero; - LookAt(ref eye, ref forward, ref up, out result); + LookAt(in eye, in forward, in up, out result); } /// @@ -992,7 +992,7 @@ namespace FlaxEngine /// The created look-at quaternion. public static Quaternion RotationLookAt(Float3 forward, Float3 up) { - RotationLookAt(ref forward, ref up, out var result); + RotationLookAt(in forward, in up, out var result); return result; } @@ -1014,7 +1014,7 @@ namespace FlaxEngine /// The calculated quaternion. public static Quaternion LookRotation(Float3 forward, Float3 up) { - LookRotation(ref forward, ref up, out var result); + LookRotation(in forward, in up, out var result); return result; } @@ -1024,13 +1024,13 @@ namespace FlaxEngine /// The forward direction. Direction to orient towards. /// The up direction. Constrains y axis orientation to a plane this vector lies on. This rule might be broken if forward and up direction are nearly parallel. /// The calculated quaternion. - public static void LookRotation(ref Float3 forward, ref Float3 up, out Quaternion result) + public static void LookRotation(in Float3 forward, in Float3 up, out Quaternion result) { Float3 forwardNorm = forward; forwardNorm.Normalize(); - Float3.Cross(ref up, ref forwardNorm, out var rightNorm); + Float3.Cross(up, forwardNorm, out var rightNorm); rightNorm.Normalize(); - Float3.Cross(ref forwardNorm, ref rightNorm, out var upNorm); + Float3.Cross(forwardNorm, rightNorm, out var upNorm); float m00 = rightNorm.X; float m01 = rightNorm.Y; @@ -1088,7 +1088,7 @@ namespace FlaxEngine /// The destination vector. /// The result. /// The fallback axis. - public static void GetRotationFromTo(ref Float3 from, ref Float3 to, out Quaternion result, ref Float3 fallbackAxis) + public static void GetRotationFromTo(in Float3 from, in Float3 to, out Quaternion result, in Float3 fallbackAxis) { // Based on Stan Melax's article in Game Programming Gems @@ -1098,7 +1098,7 @@ namespace FlaxEngine v1.Normalize(); // If dot == 1, vectors are the same - float d = Float3.Dot(ref v0, ref v1); + float d = Float3.Dot(v0, v1); if (d >= 1.0f) { result = Identity; @@ -1110,7 +1110,7 @@ namespace FlaxEngine if (fallbackAxis != Float3.Zero) { // Rotate 180 degrees about the fallback axis - RotationAxis(ref fallbackAxis, Mathf.Pi, out result); + RotationAxis(in fallbackAxis, Mathf.Pi, out result); } else { @@ -1119,14 +1119,14 @@ namespace FlaxEngine if (axis.LengthSquared < Mathf.Epsilon) // Pick another if colinear axis = Float3.Cross(Float3.UnitY, from); axis.Normalize(); - RotationAxis(ref axis, Mathf.Pi, out result); + RotationAxis(in axis, Mathf.Pi, out result); } } else { float s = Mathf.Sqrt((1 + d) * 2); float invS = 1 / s; - Float3.Cross(ref v0, ref v1, out var c); + Float3.Cross(v0, v1, out var c); result.X = c.X * invS; result.Y = c.Y * invS; result.Z = c.Z * invS; @@ -1144,7 +1144,7 @@ namespace FlaxEngine /// The rotation. public static Quaternion GetRotationFromTo(Float3 from, Float3 to, Float3 fallbackAxis) { - GetRotationFromTo(ref from, ref to, out var result, ref fallbackAxis); + GetRotationFromTo(in from, in to, out var result, in fallbackAxis); return result; } @@ -1154,7 +1154,7 @@ namespace FlaxEngine /// The source vector. /// The destination vector. /// The result. - public static void FindBetween(ref Float3 from, ref Float3 to, out Quaternion result) + public static void FindBetween(in Float3 from, in Float3 to, out Quaternion result) { // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final float normFromNormTo = Mathf.Sqrt(from.LengthSquared * to.LengthSquared); @@ -1186,7 +1186,7 @@ namespace FlaxEngine /// The rotation. public static Quaternion FindBetween(Float3 from, Float3 to) { - FindBetween(ref from, ref to, out var result); + FindBetween(in from, in to, out var result); return result; } @@ -1198,10 +1198,10 @@ namespace FlaxEngine /// The up vector of the camera. /// The forward vector of the camera. /// When the method completes, contains the created billboard quaternion. - public static void Billboard(ref Float3 objectPosition, ref Float3 cameraPosition, ref Float3 cameraUpVector, ref Float3 cameraForwardVector, out Quaternion result) + public static void Billboard(in Float3 objectPosition, in Float3 cameraPosition, in Float3 cameraUpVector, in Float3 cameraForwardVector, out Quaternion result) { - Matrix3x3.Billboard(ref objectPosition, ref cameraPosition, ref cameraUpVector, ref cameraForwardVector, out var matrix); - RotationMatrix(ref matrix, out result); + Matrix3x3.Billboard(objectPosition, cameraPosition, cameraUpVector, cameraForwardVector, out var matrix); + RotationMatrix(in matrix, out result); } /// @@ -1214,7 +1214,7 @@ namespace FlaxEngine /// The created billboard quaternion. public static Quaternion Billboard(Float3 objectPosition, Float3 cameraPosition, Float3 cameraUpVector, Float3 cameraForwardVector) { - Billboard(ref objectPosition, ref cameraPosition, ref cameraUpVector, ref cameraForwardVector, out var result); + Billboard(in objectPosition, in cameraPosition, in cameraUpVector, in cameraForwardVector, out var result); return result; } @@ -1225,7 +1225,7 @@ namespace FlaxEngine /// The newly created quaternion. public static Quaternion RotationMatrix(Matrix matrix) { - RotationMatrix(ref matrix, out var result); + RotationMatrix(in matrix, out var result); return result; } @@ -1311,7 +1311,7 @@ namespace FlaxEngine /// /// The pitch, yaw and roll angles of rotation. /// When the method completes, contains the newly created quaternion. - public static void Euler(ref Float3 eulerAngles, out Quaternion result) + public static void Euler(in Float3 eulerAngles, out Quaternion result) { RotationYawPitchRoll(eulerAngles.Y * Mathf.DegreesToRadians, eulerAngles.X * Mathf.DegreesToRadians, eulerAngles.Z * Mathf.DegreesToRadians, out result); } @@ -1387,7 +1387,7 @@ namespace FlaxEngine /// End quaternion. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the spherical linear interpolation of the two quaternions. - public static void Slerp(ref Quaternion start, ref Quaternion end, float amount, out Quaternion result) + public static void Slerp(in Quaternion start, in Quaternion end, float amount, out Quaternion result) { float opposite; float inverse; @@ -1422,7 +1422,7 @@ namespace FlaxEngine /// The spherical linear interpolation of the two quaternions. public static Quaternion Slerp(Quaternion start, Quaternion end, float amount) { - Slerp(ref start, ref end, amount, out var result); + Slerp(in start, in end, amount, out var result); return result; } @@ -1435,11 +1435,11 @@ namespace FlaxEngine /// Fourth source quaternion. /// Value between 0 and 1 indicating the weight of interpolation. /// When the method completes, contains the spherical quadrangle interpolation of the quaternions. - public static void Squad(ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, ref Quaternion value4, float amount, out Quaternion result) + public static void Squad(in Quaternion value1, in Quaternion value2, in Quaternion value3, in Quaternion value4, float amount, out Quaternion result) { - Slerp(ref value1, ref value4, amount, out var start); - Slerp(ref value2, ref value3, amount, out var end); - Slerp(ref start, ref end, 2.0f * amount * (1.0f - amount), out result); + Slerp(in value1, in value4, amount, out var start); + Slerp(in value2, in value3, amount, out var end); + Slerp(in start, in end, 2.0f * amount * (1.0f - amount), out result); } /// @@ -1453,7 +1453,7 @@ namespace FlaxEngine /// The spherical quadrangle interpolation of the quaternions. public static Quaternion Squad(Quaternion value1, Quaternion value2, Quaternion value3, Quaternion value4, float amount) { - Squad(ref value1, ref value2, ref value3, ref value4, amount, out var result); + Squad(in value1, in value2, in value3, in value4, amount, out var result); return result; } @@ -1472,8 +1472,8 @@ namespace FlaxEngine Quaternion q3 = (value3 + value4).LengthSquared < (value3 - value4).LengthSquared ? -value4 : value4; Quaternion q1 = value2; - Exponential(ref q1, out var q1Exp); - Exponential(ref q2, out var q2Exp); + Exponential(in q1, out var q1Exp); + Exponential(in q2, out var q2Exp); var results = new Quaternion[3]; results[0] = q1 * Exponential(-0.25f * (Logarithm(q1Exp * q2) + Logarithm(q1Exp * q0))); @@ -1530,7 +1530,7 @@ namespace FlaxEngine /// The sum of the two quaternions. public static Quaternion operator +(Quaternion left, Quaternion right) { - Add(ref left, ref right, out var result); + Add(in left, in right, out var result); return result; } @@ -1542,7 +1542,7 @@ namespace FlaxEngine /// The difference of the two quaternions. public static Quaternion operator -(Quaternion left, Quaternion right) { - Subtract(ref left, ref right, out var result); + Subtract(in left, in right, out var result); return result; } @@ -1553,7 +1553,7 @@ namespace FlaxEngine /// A quaternion facing in the opposite direction. public static Quaternion operator -(Quaternion value) { - Negate(ref value, out var result); + Negate(in value, out var result); return result; } @@ -1565,7 +1565,7 @@ namespace FlaxEngine /// The scaled quaternion. public static Quaternion operator *(float scale, Quaternion value) { - Multiply(ref value, scale, out var result); + Multiply(in value, scale, out var result); return result; } @@ -1577,7 +1577,7 @@ namespace FlaxEngine /// The scaled quaternion. public static Quaternion operator *(Quaternion value, float scale) { - Multiply(ref value, scale, out var result); + Multiply(in value, scale, out var result); return result; } @@ -1589,7 +1589,7 @@ namespace FlaxEngine /// The multiplied quaternion. public static Quaternion operator *(Quaternion left, Quaternion right) { - Multiply(ref left, ref right, out var result); + Multiply(in left, in right, out var result); return result; } @@ -1602,7 +1602,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Quaternion left, Quaternion right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1614,7 +1614,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Quaternion left, Quaternion right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1690,7 +1690,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Quaternion left, Quaternion right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -1700,7 +1700,7 @@ namespace FlaxEngine /// The right quaternion. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Quaternion left, ref Quaternion right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Quaternion left, in Quaternion right, float epsilon = Mathf.Epsilon) { //return Dot(ref left, ref right) > 1.0f - epsilon; return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon) && Mathf.WithinEpsilon(left.Z, right.Z, epsilon) && Mathf.WithinEpsilon(left.W, right.W, epsilon); @@ -1712,7 +1712,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Quaternion other) + public bool Equals(in Quaternion other) { return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } @@ -1725,7 +1725,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Quaternion other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1735,7 +1735,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Quaternion other && Equals(ref other); + return value is Quaternion other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Ray.cs b/Source/Engine/Core/Math/Ray.cs index 36203cbf7..7d7bde180 100644 --- a/Source/Engine/Core/Math/Ray.cs +++ b/Source/Engine/Core/Math/Ray.cs @@ -96,9 +96,9 @@ namespace FlaxEngine /// /// The point to test. /// Whether the two objects intersected. - public bool Intersects(ref Vector3 point) + public bool Intersects(in Vector3 point) { - return CollisionsHelper.RayIntersectsPoint(ref this, ref point); + return CollisionsHelper.RayIntersectsPoint(this, point); } /// @@ -106,9 +106,9 @@ namespace FlaxEngine /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects(in Ray ray) { - return CollisionsHelper.RayIntersectsRay(ref this, ref ray, out _); + return CollisionsHelper.RayIntersectsRay(this, ray, out _); } /// @@ -117,9 +117,9 @@ namespace FlaxEngine /// The ray to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vector3 point) + public bool Intersects(in Ray ray, out Vector3 point) { - return CollisionsHelper.RayIntersectsRay(ref this, ref ray, out point); + return CollisionsHelper.RayIntersectsRay(this, ray, out point); } /// @@ -127,9 +127,9 @@ namespace FlaxEngine /// /// The plane to test /// Whether the two objects intersected. - public bool Intersects(ref Plane plane) + public bool Intersects(in Plane plane) { - return CollisionsHelper.RayIntersectsPlane(ref this, ref plane, out Real _); + return CollisionsHelper.RayIntersectsPlane(this, plane, out Real _); } /// @@ -138,9 +138,9 @@ namespace FlaxEngine /// The plane to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane, out Real distance) + public bool Intersects(in Plane plane, out Real distance) { - return CollisionsHelper.RayIntersectsPlane(ref this, ref plane, out distance); + return CollisionsHelper.RayIntersectsPlane(this, plane, out distance); } #if USE_LARGE_WORLDS @@ -152,9 +152,9 @@ namespace FlaxEngine /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. [Obsolete("Use Intersects with 'out Real distance' parameter instead")] - public bool Intersects(ref Plane plane, out float distance) + public bool Intersects(in Plane plane, out float distance) { - return CollisionsHelper.RayIntersectsPlane(ref this, ref plane, out distance); + return CollisionsHelper.RayIntersectsPlane(this, plane, out distance); } #endif @@ -164,9 +164,9 @@ namespace FlaxEngine /// The plane to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane, out Vector3 point) + public bool Intersects(in Plane plane, out Vector3 point) { - return CollisionsHelper.RayIntersectsPlane(ref this, ref plane, out point); + return CollisionsHelper.RayIntersectsPlane(this, plane, out point); } /// @@ -176,9 +176,9 @@ namespace FlaxEngine /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3) + public bool Intersects(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3) { - return CollisionsHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out Real _); + return CollisionsHelper.RayIntersectsTriangle(this, vertex1, vertex2, vertex3, out Real _); } /// @@ -189,9 +189,9 @@ namespace FlaxEngine /// The third vertex of the triangle to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Real distance) + public bool Intersects(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3, out Real distance) { - return CollisionsHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out distance); + return CollisionsHelper.RayIntersectsTriangle(this, vertex1, vertex2, vertex3, out distance); } #if USE_LARGE_WORLDS @@ -205,9 +205,9 @@ namespace FlaxEngine /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. [Obsolete("Use Intersects with 'out Real distance' parameter instead")] - public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out float distance) + public bool Intersects(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3, out float distance) { - var result = CollisionsHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out Real dst); + var result = CollisionsHelper.RayIntersectsTriangle(this, vertex1, vertex2, vertex3, out Real dst); distance = (float)dst; return result; } @@ -221,9 +221,9 @@ namespace FlaxEngine /// The third vertex of the triangle to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 point) + public bool Intersects(in Vector3 vertex1, in Vector3 vertex2, in Vector3 vertex3, out Vector3 point) { - return CollisionsHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out point); + return CollisionsHelper.RayIntersectsTriangle(this, vertex1, vertex2, vertex3, out point); } /// @@ -231,9 +231,9 @@ namespace FlaxEngine /// /// The box to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box) + public bool Intersects(in BoundingBox box) { - return CollisionsHelper.RayIntersectsBox(ref this, ref box, out Real _); + return CollisionsHelper.RayIntersectsBox(this, box, out Real _); } /// @@ -243,7 +243,7 @@ namespace FlaxEngine /// Whether the two objects intersected. public bool Intersects(BoundingBox box) { - return Intersects(ref box); + return Intersects(in box); } /// @@ -252,9 +252,9 @@ namespace FlaxEngine /// The box to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box, out Real distance) + public bool Intersects(in BoundingBox box, out Real distance) { - return CollisionsHelper.RayIntersectsBox(ref this, ref box, out distance); + return CollisionsHelper.RayIntersectsBox(this, box, out distance); } /// @@ -263,9 +263,9 @@ namespace FlaxEngine /// The box to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box, out Vector3 point) + public bool Intersects(in BoundingBox box, out Vector3 point) { - return CollisionsHelper.RayIntersectsBox(ref this, ref box, out point); + return CollisionsHelper.RayIntersectsBox(this, box, out point); } /// @@ -273,9 +273,9 @@ namespace FlaxEngine /// /// The sphere to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere) + public bool Intersects(in BoundingSphere sphere) { - return CollisionsHelper.RayIntersectsSphere(ref this, ref sphere, out Real _); + return CollisionsHelper.RayIntersectsSphere(this, sphere, out Real _); } /// @@ -285,7 +285,7 @@ namespace FlaxEngine /// Whether the two objects intersected. public bool Intersects(BoundingSphere sphere) { - return Intersects(ref sphere); + return Intersects(in sphere); } /// @@ -294,9 +294,9 @@ namespace FlaxEngine /// The sphere to test. /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere, out Real distance) + public bool Intersects(in BoundingSphere sphere, out Real distance) { - return CollisionsHelper.RayIntersectsSphere(ref this, ref sphere, out distance); + return CollisionsHelper.RayIntersectsSphere(this, sphere, out distance); } #if USE_LARGE_WORLDS @@ -308,9 +308,9 @@ namespace FlaxEngine /// When the method completes, contains the distance of the intersection, or 0 if there was no intersection. /// Whether the two objects intersected. [Obsolete("Use Intersects with 'out Real distance' parameter instead")] - public bool Intersects(ref BoundingSphere sphere, out float distance) + public bool Intersects(in BoundingSphere sphere, out float distance) { - var result = CollisionsHelper.RayIntersectsSphere(ref this, ref sphere, out Real dst); + var result = CollisionsHelper.RayIntersectsSphere(this, sphere, out Real dst); distance = (float)dst; return result; } @@ -322,9 +322,9 @@ namespace FlaxEngine /// The sphere to test. /// When the method completes, contains the point of intersection, or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere, out Vector3 point) + public bool Intersects(in BoundingSphere sphere, out Vector3 point) { - return CollisionsHelper.RayIntersectsSphere(ref this, ref sphere, out point); + return CollisionsHelper.RayIntersectsSphere(this, sphere, out point); } /// @@ -335,7 +335,7 @@ namespace FlaxEngine /// The screen viewport. /// The View*Projection matrix. /// The resulting ray. - public static Ray GetPickRay(float x, float y, ref Viewport viewport, ref Matrix vp) + public static Ray GetPickRay(float x, float y, in Viewport viewport, in Matrix vp) { Vector3 nearPoint = new Vector3(x, y, 0.0f); Vector3 farPoint = new Vector3(x, y, 1.0f); @@ -358,7 +358,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Ray left, Ray right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -370,7 +370,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Ray left, Ray right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -431,7 +431,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Ray other) + public bool Equals(in Ray other) { return Position == other.Position && Direction == other.Direction; } @@ -444,7 +444,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Ray other) { - return Equals(ref other); + return Equals(in other); } /// @@ -454,7 +454,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Ray other && Equals(ref other); + return value is Ray other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Rectangle.cs b/Source/Engine/Core/Math/Rectangle.cs index 81c689d48..377239c21 100644 --- a/Source/Engine/Core/Math/Rectangle.cs +++ b/Source/Engine/Core/Math/Rectangle.cs @@ -177,7 +177,7 @@ namespace FlaxEngine /// /// Point location to check /// True if point is inside rectangle's area - public bool Contains(ref Float2 location) + public bool Contains(in Float2 location) { return (location.X >= Location.X && location.Y >= Location.Y) && (location.X <= Location.X + Size.X && location.Y <= Location.Y + Size.Y); } @@ -197,7 +197,7 @@ namespace FlaxEngine /// /// The rectangle to evaluate /// True if this rectangle entirely contains the specified rectangle, or false if not - public bool Contains(ref Rectangle value) + public bool Contains(in Rectangle value) { return (Location.X <= value.Location.X) && (value.Right <= Right) && (Location.Y <= value.Location.Y) && (value.Bottom <= Bottom); } @@ -217,7 +217,7 @@ namespace FlaxEngine /// /// The rectangle to evaluate /// True if the specified rectangle intersects with this one, otherwise false - public bool Intersects(ref Rectangle value) + public bool Intersects(in Rectangle value) { return (value.Location.X <= Right) && (Location.X <= value.Right) && (value.Location.Y <= Bottom) && (Location.Y <= value.Bottom); } @@ -364,7 +364,7 @@ namespace FlaxEngine /// First rectangle /// Second rectangle /// When the method completes, contains the rectangle that both a and b rectangles. - public static void Union(ref Rectangle a, ref Rectangle b, out Rectangle result) + public static void Union(in Rectangle a, in Rectangle b, out Rectangle result) { float left = Mathf.Min(a.Left, b.Left); float right = Mathf.Max(a.Right, b.Right); @@ -394,7 +394,7 @@ namespace FlaxEngine /// The first rectangle. /// The second rectangle. /// When the method completes, contains the rectangle that shared part of a and b rectangles. - public static void Shared(ref Rectangle a, ref Rectangle b, out Rectangle result) + public static void Shared(in Rectangle a, in Rectangle b, out Rectangle result) { float left = Mathf.Max(a.Left, b.Left); float right = Mathf.Min(a.Right, b.Right); @@ -411,8 +411,8 @@ namespace FlaxEngine /// Rectangle that contains both p1 and p2 public static Rectangle FromPoints(Float2 p1, Float2 p2) { - Float2.Min(ref p1, ref p2, out var upperLeft); - Float2.Max(ref p1, ref p2, out var rightBottom); + Float2.Min(p1, p2, out var upperLeft); + Float2.Max(p1, p2, out var rightBottom); return new Rectangle(upperLeft, Float2.Max(rightBottom - upperLeft, Float2.Zero)); } @@ -421,12 +421,12 @@ namespace FlaxEngine /// /// First point /// Second point - /// Rectangle that contains both p1 and p2 /// When the method completes, contains the rectangle that contains both p1 and p2 points. - public static void FromPoints(ref Float2 p1, ref Float2 p2, out Rectangle result) + /// Rectangle that contains both p1 and p2 + public static void FromPoints(in Float2 p1, in Float2 p2, out Rectangle result) { - Float2.Min(ref p1, ref p2, out var upperLeft); - Float2.Max(ref p1, ref p2, out var rightBottom); + Float2.Min(p1, p2, out var upperLeft); + Float2.Max(p1, p2, out var rightBottom); result = new Rectangle(upperLeft, Float2.Max(rightBottom - upperLeft, Float2.Zero)); } @@ -474,7 +474,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Rectangle left, Rectangle right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -486,7 +486,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rectangle left, Rectangle right) { - return !left.Equals(ref right); + return !left.Equals(in right); } #endregion @@ -497,7 +497,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Rectangle other) + public bool Equals(in Rectangle other) { return Location == other.Location && Size == other.Size; } @@ -505,13 +505,13 @@ namespace FlaxEngine /// public bool Equals(Rectangle other) { - return Equals(ref other); + return Equals(in other); } /// public override bool Equals(object obj) { - return obj is Rectangle other && Equals(ref other); + return obj is Rectangle other && Equals(in other); } /// diff --git a/Source/Engine/Core/Math/Transform.cs b/Source/Engine/Core/Math/Transform.cs index fc16a501b..c789dae2e 100644 --- a/Source/Engine/Core/Math/Transform.cs +++ b/Source/Engine/Core/Math/Transform.cs @@ -127,7 +127,7 @@ namespace FlaxEngine /// Rotation matrix public Matrix GetRotation() { - Matrix.RotationQuaternion(ref Orientation, out var result); + Matrix.RotationQuaternion(Orientation, out var result); return result; } @@ -137,7 +137,7 @@ namespace FlaxEngine /// Matrix to set public void GetRotation(out Matrix result) { - Matrix.RotationQuaternion(ref Orientation, out result); + Matrix.RotationQuaternion(Orientation, out result); } /// @@ -146,7 +146,7 @@ namespace FlaxEngine /// Rotation matrix public void SetRotation(Matrix value) { - Quaternion.RotationMatrix(ref value, out Orientation); + Quaternion.RotationMatrix(value, out Orientation); } /// @@ -155,7 +155,7 @@ namespace FlaxEngine /// Rotation matrix public void SetRotation(ref Matrix value) { - Quaternion.RotationMatrix(ref value, out Orientation); + Quaternion.RotationMatrix(value, out Orientation); } /// @@ -166,7 +166,7 @@ namespace FlaxEngine public Matrix GetWorld() { Float3 translation = Translation; - Matrix.Transformation(ref Scale, ref Orientation, ref translation, out var result); + Matrix.Transformation(Scale, Orientation, translation, out var result); return result; } @@ -178,7 +178,7 @@ namespace FlaxEngine public void GetWorld(out Matrix result) { Float3 translation = Translation; - Matrix.Transformation(ref Scale, ref Orientation, ref translation, out result); + Matrix.Transformation(Scale, Orientation, translation, out result); } /// @@ -190,9 +190,9 @@ namespace FlaxEngine public static Transform Add(Transform left, Transform right) { Transform result; - Quaternion.Multiply(ref left.Orientation, ref right.Orientation, out result.Orientation); - Float3.Multiply(ref left.Scale, ref right.Scale, out result.Scale); - Vector3.Add(ref left.Translation, ref right.Translation, out result.Translation); + Quaternion.Multiply(left.Orientation, right.Orientation, out result.Orientation); + Float3.Multiply(left.Scale, right.Scale, out result.Scale); + Vector3.Add(left.Translation, right.Translation, out result.Translation); return result; } @@ -205,10 +205,10 @@ namespace FlaxEngine public static Transform Subtract(Transform left, Transform right) { Transform result; - Vector3.Subtract(ref left.Translation, ref right.Translation, out result.Translation); + Vector3.Subtract(left.Translation, right.Translation, out result.Translation); Quaternion invRotation = right.Orientation.Conjugated(); - Quaternion.Multiply(ref left.Orientation, ref invRotation, out result.Orientation); - Float3.Divide(ref left.Scale, ref right.Scale, out result.Scale); + Quaternion.Multiply(left.Orientation, invRotation, out result.Orientation); + Float3.Divide(left.Scale, right.Scale, out result.Scale); return result; } @@ -220,8 +220,8 @@ namespace FlaxEngine public Transform LocalToWorld(Transform other) { Transform result; - Quaternion.Multiply(ref Orientation, ref other.Orientation, out result.Orientation); - Float3.Multiply(ref Scale, ref other.Scale, out result.Scale); + Quaternion.Multiply(Orientation, other.Orientation, out result.Orientation); + Float3.Multiply(Scale, other.Scale, out result.Scale); result.Translation = LocalToWorld(other.Translation); return result; } @@ -234,7 +234,7 @@ namespace FlaxEngine public Vector3 LocalToWorld(Vector3 point) { point *= Scale; - Vector3.Transform(ref point, ref Orientation, out point); + Vector3.Transform(point, Orientation, out point); return point + Translation; } @@ -246,7 +246,7 @@ namespace FlaxEngine public Vector3 LocalToWorldVector(Vector3 vector) { vector *= Scale; - Vector3.Transform(ref vector, ref Orientation, out vector); + Vector3.Transform(vector, Orientation, out vector); return vector; } @@ -257,8 +257,8 @@ namespace FlaxEngine /// World space transform public void LocalToWorld(ref Transform other, out Transform result) { - Quaternion.Multiply(ref Orientation, ref other.Orientation, out result.Orientation); - Float3.Multiply(ref Scale, ref other.Scale, out result.Scale); + Quaternion.Multiply(Orientation, other.Orientation, out result.Orientation); + Float3.Multiply(Scale, other.Scale, out result.Scale); result.Translation = LocalToWorld(other.Translation); } @@ -267,10 +267,10 @@ namespace FlaxEngine /// /// Local space point /// World space point - public void LocalToWorld(ref Vector3 point, out Vector3 result) + public void LocalToWorld(in Vector3 point, out Vector3 result) { Vector3 tmp = point * Scale; - Vector3.Transform(ref tmp, ref Orientation, out result); + Vector3.Transform(tmp, Orientation, out result); result += Translation; } @@ -279,10 +279,10 @@ namespace FlaxEngine /// /// The local space vector. /// World space vector - public void LocalToWorldVector(ref Vector3 vector, out Vector3 result) + public void LocalToWorldVector(in Vector3 vector, out Vector3 result) { Vector3 tmp = vector * Scale; - Vector3.Transform(ref tmp, ref Orientation, out result); + Vector3.Transform(tmp, Orientation, out result); } /// @@ -315,8 +315,8 @@ namespace FlaxEngine Transform result; result.Orientation = Orientation; result.Orientation.Invert(); - Quaternion.Multiply(ref result.Orientation, ref other.Orientation, out result.Orientation); - Float3.Multiply(ref other.Scale, ref invScale, out result.Scale); + Quaternion.Multiply(result.Orientation, other.Orientation, out result.Orientation); + Float3.Multiply(other.Scale, invScale, out result.Scale); result.Translation = WorldToLocal(other.Translation); return result; } @@ -337,7 +337,7 @@ namespace FlaxEngine invScale.Z = 1.0f / invScale.Z; Quaternion invRotation = Orientation.Conjugated(); Vector3 result = point - Translation; - Vector3.Transform(ref result, ref invRotation, out result); + Vector3.Transform(result, invRotation, out result); return result * invScale; } @@ -356,7 +356,7 @@ namespace FlaxEngine if (invScale.Z != 0.0f) invScale.Z = 1.0f / invScale.Z; Quaternion invRotation = Orientation.Conjugated(); - Vector3.Transform(ref vector, ref invRotation, out var result); + Vector3.Transform(vector, invRotation, out var result); return result * invScale; } @@ -366,7 +366,7 @@ namespace FlaxEngine /// World space point /// When the method completes, contains the local space point. /// Local space point - public void WorldToLocal(ref Vector3 point, out Vector3 result) + public void WorldToLocal(in Vector3 point, out Vector3 result) { var invScale = Scale; if (invScale.X != 0.0f) @@ -377,7 +377,7 @@ namespace FlaxEngine invScale.Z = 1.0f / invScale.Z; Quaternion invRotation = Orientation.Conjugated(); Vector3 tmp = point - Translation; - Vector3.Transform(ref tmp, ref invRotation, out result); + Vector3.Transform(tmp, invRotation, out result); result *= invScale; } @@ -386,7 +386,7 @@ namespace FlaxEngine /// /// World space vector /// Local space vector - public void WorldToLocalVector(ref Vector3 vector, out Vector3 result) + public void WorldToLocalVector(in Vector3 vector, out Vector3 result) { var invScale = Scale; if (invScale.X != 0.0f) @@ -396,7 +396,7 @@ namespace FlaxEngine if (invScale.Z != 0.0f) invScale.Z = 1.0f / invScale.Z; Quaternion invRotation = Orientation.Conjugated(); - Vector3.Transform(ref vector, ref invRotation, out result); + Vector3.Transform(vector, invRotation, out result); result *= invScale; } @@ -418,7 +418,7 @@ namespace FlaxEngine for (int i = 0; i < points.Length; i++) { result[i] = points[i] - Translation; - Vector3.Transform(ref result[i], ref invRotation, out result[i]); + Vector3.Transform(result[i], invRotation, out result[i]); result[i] *= invScale; } } @@ -431,7 +431,7 @@ namespace FlaxEngine /// The transformed direction vector. public Vector3 TransformDirection(Vector3 direction) { - Vector3.Transform(ref direction, ref Orientation, out var result); + Vector3.Transform(direction, Orientation, out var result); return result; } @@ -457,9 +457,9 @@ namespace FlaxEngine public static Transform Lerp(Transform start, Transform end, float amount) { Transform result; - Vector3.Lerp(ref start.Translation, ref end.Translation, amount, out result.Translation); - Quaternion.Slerp(ref start.Orientation, ref end.Orientation, amount, out result.Orientation); - Float3.Lerp(ref start.Scale, ref end.Scale, amount, out result.Scale); + Vector3.Lerp(start.Translation, end.Translation, amount, out result.Translation); + Quaternion.Slerp(start.Orientation, end.Orientation, amount, out result.Orientation); + Float3.Lerp(start.Scale, end.Scale, amount, out result.Scale); return result; } @@ -471,11 +471,11 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two transformations. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Transform start, ref Transform end, float amount, out Transform result) + public static void Lerp(in Transform start, in Transform end, float amount, out Transform result) { - Vector3.Lerp(ref start.Translation, ref end.Translation, amount, out result.Translation); - Quaternion.Slerp(ref start.Orientation, ref end.Orientation, amount, out result.Orientation); - Float3.Lerp(ref start.Scale, ref end.Scale, amount, out result.Scale); + Vector3.Lerp(start.Translation, end.Translation, amount, out result.Translation); + Quaternion.Slerp(start.Orientation, end.Orientation, amount, out result.Orientation); + Float3.Lerp(start.Scale, end.Scale, amount, out result.Scale); } /// @@ -577,7 +577,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Transform left, Transform right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -589,7 +589,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Transform left, Transform right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -682,7 +682,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Transform left, Transform right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -692,9 +692,9 @@ namespace FlaxEngine /// The right transform. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Transform left, ref Transform right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Transform left, in Transform right, float epsilon = Mathf.Epsilon) { - return Vector3.NearEqual(ref left.Translation, ref right.Translation, epsilon) && Quaternion.NearEqual(ref left.Orientation, ref right.Orientation, epsilon) && Float3.NearEqual(ref left.Scale, ref right.Scale, epsilon); + return Vector3.NearEqual(left.Translation, right.Translation, epsilon) && Quaternion.NearEqual(left.Orientation, right.Orientation, epsilon) && Float3.NearEqual(left.Scale, right.Scale, epsilon); } /// @@ -703,7 +703,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Transform other) + public bool Equals(in Transform other) { return Translation == other.Translation && Orientation == other.Orientation && Scale == other.Scale; } @@ -716,7 +716,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Transform other) { - return Equals(ref other); + return Equals(in other); } /// @@ -726,7 +726,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Transform other && Equals(ref other); + return value is Transform other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 8e1599513..2013e9a05 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -332,7 +332,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Vector2 left, ref Vector2 right, out Vector2 result) + public static void Add(in Vector2 left, in Vector2 right, out Vector2 result) { result = new Vector2(left.X + right.X, left.Y + right.Y); } @@ -354,7 +354,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Vector2 left, ref float right, out Vector2 result) + public static void Add(in Vector2 left, float right, out Vector2 result) { result = new Vector2(left.X + right, left.Y + right); } @@ -376,7 +376,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Vector2 left, ref Vector2 right, out Vector2 result) + public static void Subtract(in Vector2 left, in Vector2 right, out Vector2 result) { result = new Vector2(left.X - right.X, left.Y - right.Y); } @@ -398,7 +398,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Vector2 left, ref float right, out Vector2 result) + public static void Subtract(in Vector2 left, float right, out Vector2 result) { result = new Vector2(left.X - right, left.Y - right); } @@ -420,7 +420,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector /// The vector with subtracted scalar for each element. - public static void Subtract(ref float left, ref Vector2 right, out Vector2 result) + public static void Subtract(float left, in Vector2 right, out Vector2 result) { result = new Vector2(left - right.X, left - right.Y); } @@ -442,7 +442,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Vector2 value, float scale, out Vector2 result) + public static void Multiply(in Vector2 value, float scale, out Vector2 result) { result = new Vector2(value.X * scale, value.Y * scale); } @@ -464,7 +464,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Vector2 left, ref Vector2 right, out Vector2 result) + public static void Multiply(in Vector2 left, in Vector2 right, out Vector2 result) { result = new Vector2(left.X * right.X, left.Y * right.Y); } @@ -486,7 +486,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Vector2 value, float scale, out Vector2 result) + public static void Divide(in Vector2 value, float scale, out Vector2 result) { result = new Vector2(value.X / scale, value.Y / scale); } @@ -508,7 +508,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(float scale, ref Vector2 value, out Vector2 result) + public static void Divide(float scale, in Vector2 value, out Vector2 result) { result = new Vector2(scale / value.X, scale / value.Y); } @@ -529,7 +529,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Vector2 value, out Vector2 result) + public static void Negate(in Vector2 value, out Vector2 result) { result = new Vector2(-value.X, -value.Y); } @@ -554,7 +554,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 2D Cartesian coordinates of the specified point. - public static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result) + public static void Barycentric(in Vector2 value1, in Vector2 value2, in Vector2 value3, float amount1, float amount2, out Vector2 result) { result = new Vector2(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y)); @@ -572,7 +572,7 @@ namespace FlaxEngine /// A new containing the 2D Cartesian coordinates of the specified point. public static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out Vector2 result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out Vector2 result); return result; } @@ -583,7 +583,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Vector2 value, ref Vector2 min, ref Vector2 max, out Vector2 result) + public static void Clamp(in Vector2 value, in Vector2 min, in Vector2 max, out Vector2 result) { Real x = value.X; x = x > max.X ? max.X : x; @@ -603,7 +603,7 @@ namespace FlaxEngine /// The clamped value. public static Vector2 Clamp(Vector2 value, Vector2 min, Vector2 max) { - Clamp(ref value, ref min, ref max, out Vector2 result); + Clamp(in value, in min, in max, out Vector2 result); return result; } @@ -623,7 +623,7 @@ namespace FlaxEngine /// The second triangle vertex. /// The third triangle vertex. /// The triangle area. - public static Real TriangleArea(ref Vector2 v0, ref Vector2 v1, ref Vector2 v2) + public static Real TriangleArea(in Vector2 v0, in Vector2 v1, in Vector2 v2) { return Math.Abs((v0.X * (v1.Y - v2.Y) + v1.X * (v2.Y - v0.Y) + v2.X * (v0.Y - v1.Y)) / 2); } @@ -634,8 +634,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Vector2 value1, ref Vector2 value2, out Real result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Vector2 value1, in Vector2 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -662,8 +662,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static Real Distance(ref Vector2 value1, ref Vector2 value2) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static Real Distance(in Vector2 value1, in Vector2 value2) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -676,7 +676,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out Real result) + public static void DistanceSquared(in Vector2 value1, in Vector2 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -689,7 +689,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// The squared distance between the two vectors. - public static Real DistanceSquared(ref Vector2 value1, ref Vector2 value2) + public static Real DistanceSquared(in Vector2 value1, in Vector2 value2) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -718,7 +718,7 @@ namespace FlaxEngine /// true if left and right are near, false otherwise public static bool NearEqual(Vector2 left, Vector2 right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -728,7 +728,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Vector2 left, ref Vector2 right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Vector2 left, in Vector2 right, float epsilon = Mathf.Epsilon) { return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon); } @@ -739,7 +739,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Vector2 left, ref Vector2 right, out Real result) + public static void Dot(in Vector2 left, in Vector2 right, out Real result) { result = left.X * right.X + left.Y * right.Y; } @@ -750,7 +750,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The dot product of the two vectors. - public static Real Dot(ref Vector2 left, ref Vector2 right) + public static Real Dot(in Vector2 left, in Vector2 right) { return left.X * right.X + left.Y * right.Y; } @@ -772,7 +772,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains the cross product of the two vectors. - public static void Cross(ref Vector2 left, ref Vector2 right, out Real result) + public static void Cross(in Vector2 left, in Vector2 right, out Real result) { result = left.X * right.Y - left.Y * right.X; } @@ -783,7 +783,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// The cross product of the two vectors. - public static Real Cross(ref Vector2 left, ref Vector2 right) + public static Real Cross(in Vector2 left, in Vector2 right) { return left.X * right.Y - left.Y * right.X; } @@ -804,7 +804,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Vector2 value, out Vector2 result) + public static void Normalize(in Vector2 value, out Vector2 result) { result = value; result.Normalize(); @@ -906,7 +906,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result) + public static void Lerp(in Vector2 start, in Vector2 end, float amount, out Vector2 result) { result.X = Mathr.Lerp(start.X, end.X, amount); result.Y = Mathr.Lerp(start.Y, end.Y, amount); @@ -922,7 +922,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Vector2 Lerp(Vector2 start, Vector2 end, float amount) { - Lerp(ref start, ref end, amount, out Vector2 result); + Lerp(in start, in end, amount, out Vector2 result); return result; } @@ -934,7 +934,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Vector2 start, ref Vector2 end, ref Vector2 amount, out Vector2 result) + public static void Lerp(in Vector2 start, in Vector2 end, in Vector2 amount, out Vector2 result) { result.X = Mathr.Lerp(start.X, end.X, amount.X); result.Y = Mathr.Lerp(start.Y, end.Y, amount.Y); @@ -950,7 +950,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Vector2 Lerp(Vector2 start, Vector2 end, Vector2 amount) { - Lerp(ref start, ref end, ref amount, out Vector2 result); + Lerp(in start, in end, in amount, out Vector2 result); return result; } @@ -1046,10 +1046,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result) + public static void SmoothStep(in Vector2 start, in Vector2 end, float amount, out Vector2 result) { amount = Mathf.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -1061,7 +1061,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Vector2 SmoothStep(Vector2 start, Vector2 end, float amount) { - SmoothStep(ref start, ref end, amount, out Vector2 result); + SmoothStep(in start, in end, amount, out Vector2 result); return result; } @@ -1074,7 +1074,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 result) + public static void Hermite(in Vector2 value1, in Vector2 tangent1, in Vector2 value2, in Vector2 tangent2, float amount, out Vector2 result) { float squared = amount * amount; float cubed = amount * squared; @@ -1097,7 +1097,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out Vector2 result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out Vector2 result); return result; } @@ -1116,7 +1116,7 @@ namespace FlaxEngine /// /// The in direction. /// When the method completes, contains the result of the calculation. - public static void Perpendicular(ref Vector2 inDirection, out Vector2 result) + public static void Perpendicular(in Vector2 inDirection, out Vector2 result) { result = new Vector2(-inDirection.Y, inDirection.X); } @@ -1130,7 +1130,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result) + public static void CatmullRom(in Vector2 value1, in Vector2 value2, in Vector2 value3, in Vector2 value4, float amount, out Vector2 result) { float squared = amount * amount; float cubed = amount * squared; @@ -1153,7 +1153,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out Vector2 result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out Vector2 result); return result; } @@ -1163,7 +1163,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Vector2 left, ref Vector2 right, out Vector2 result) + public static void Max(in Vector2 left, in Vector2 right, out Vector2 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -1177,7 +1177,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Vector2 Max(Vector2 left, Vector2 right) { - Max(ref left, ref right, out Vector2 result); + Max(in left, in right, out Vector2 result); return result; } @@ -1187,7 +1187,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Vector2 left, ref Vector2 right, out Vector2 result) + public static void Min(in Vector2 left, in Vector2 right, out Vector2 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -1201,7 +1201,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Vector2 Min(Vector2 left, Vector2 right) { - Min(ref left, ref right, out Vector2 result); + Min(in left, in right, out Vector2 result); return result; } @@ -1222,7 +1222,7 @@ namespace FlaxEngine /// Normal of the surface. /// When the method completes, contains the reflected vector. /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result) + public static void Reflect(in Vector2 vector, in Vector2 normal, out Vector2 result) { var dot = vector.X * normal.X + vector.Y * normal.Y; result.X = vector.X - 2.0f * dot * normal.X; @@ -1238,7 +1238,7 @@ namespace FlaxEngine /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. public static Vector2 Reflect(Vector2 vector, Vector2 normal) { - Reflect(ref vector, ref normal, out Vector2 result); + Reflect(in vector, in normal, out Vector2 result); return result; } @@ -1248,7 +1248,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Vector2 vector, ref Quaternion rotation, out Vector2 result) + public static void Transform(in Vector2 vector, in Quaternion rotation, out Vector2 result) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1269,7 +1269,7 @@ namespace FlaxEngine /// The transformed . public static Vector2 Transform(Vector2 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out Vector2 result); + Transform(in vector, in rotation, out Vector2 result); return result; } @@ -1279,7 +1279,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vector2 vector, ref Matrix transform, out Vector4 result) + public static void Transform(in Vector2 vector, in Matrix transform, out Vector4 result) { result = new Vector4(vector.X * transform.M11 + vector.Y * transform.M21 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + transform.M42, @@ -1295,7 +1295,7 @@ namespace FlaxEngine /// The transformed . public static Vector4 Transform(Vector2 vector, Matrix transform) { - Transform(ref vector, ref transform, out Vector4 result); + Transform(in vector, in transform, out Vector4 result); return result; } @@ -1312,7 +1312,7 @@ namespace FlaxEngine /// therefore makes the vector homogeneous. The homogeneous vector is often preferred when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Vector2 coordinate, ref Matrix transform, out Vector2 result) + public static void TransformCoordinate(in Vector2 coordinate, in Matrix transform, out Vector2 result) { var vector = new Vector4 { @@ -1339,7 +1339,7 @@ namespace FlaxEngine /// public static Vector2 TransformCoordinate(Vector2 coordinate, Matrix transform) { - TransformCoordinate(ref coordinate, ref transform, out Vector2 result); + TransformCoordinate(in coordinate, in transform, out Vector2 result); return result; } @@ -1356,7 +1356,7 @@ namespace FlaxEngine /// apply. This is often preferred for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Vector2 normal, ref Matrix transform, out Vector2 result) + public static void TransformNormal(in Vector2 normal, in Matrix transform, out Vector2 result) { result = new Vector2(normal.X * transform.M11 + normal.Y * transform.M21, normal.X * transform.M12 + normal.Y * transform.M22); @@ -1377,7 +1377,7 @@ namespace FlaxEngine /// public static Vector2 TransformNormal(Vector2 normal, Matrix transform) { - TransformNormal(ref normal, ref transform, out Vector2 result); + TransformNormal(in normal, in transform, out Vector2 result); return result; } @@ -1406,7 +1406,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1654,7 +1654,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Vector2 left, Vector2 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1666,7 +1666,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Vector2 left, Vector2 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1780,7 +1780,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Vector2 other) + public bool Equals(in Vector2 other) { return X == other.X && Y == other.Y; } @@ -1788,9 +1788,9 @@ namespace FlaxEngine /// /// Determines whether the specified are equal. /// - public static bool Equals(ref Vector2 a, ref Vector2 b) + public static bool Equals(in Vector2 a, in Vector2 b) { - return a.Equals(ref b); + return a.Equals(in b); } /// @@ -1801,7 +1801,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Vector2 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1811,7 +1811,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Vector2 other && Equals(ref other); + return value is Vector2 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 5e01a7a6c..38fb2b7b9 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -392,7 +392,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Vector3 left, ref Vector3 right, out Vector3 result) + public static void Add(in Vector3 left, in Vector3 right, out Vector3 result) { result = new Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); } @@ -414,7 +414,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Vector3 left, ref float right, out Vector3 result) + public static void Add(in Vector3 left, float right, out Vector3 result) { result = new Vector3(left.X + right, left.Y + right, left.Z + right); } @@ -436,7 +436,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Vector3 left, ref Vector3 right, out Vector3 result) + public static void Subtract(in Vector3 left, in Vector3 right, out Vector3 result) { result = new Vector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); } @@ -458,7 +458,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Vector3 left, ref float right, out Vector3 result) + public static void Subtract(in Vector3 left, float right, out Vector3 result) { result = new Vector3(left.X - right, left.Y - right, left.Z - right); } @@ -480,7 +480,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref float left, ref Vector3 right, out Vector3 result) + public static void Subtract(float left, in Vector3 right, out Vector3 result) { result = new Vector3(left - right.X, left - right.Y, left - right.Z); } @@ -502,7 +502,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Vector3 value, float scale, out Vector3 result) + public static void Multiply(in Vector3 value, float scale, out Vector3 result) { result = new Vector3(value.X * scale, value.Y * scale, value.Z * scale); } @@ -524,7 +524,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Vector3 left, ref Vector3 right, out Vector3 result) + public static void Multiply(in Vector3 left, in Vector3 right, out Vector3 result) { result = new Vector3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); } @@ -546,7 +546,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector (per component). /// When the method completes, contains the divided vector. - public static void Divide(ref Vector3 value, ref Vector3 scale, out Vector3 result) + public static void Divide(in Vector3 value, in Vector3 scale, out Vector3 result) { result = new Vector3(value.X / scale.X, value.Y / scale.Y, value.Z / scale.Z); } @@ -568,7 +568,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Vector3 value, float scale, out Vector3 result) + public static void Divide(in Vector3 value, float scale, out Vector3 result) { result = new Vector3(value.X / scale, value.Y / scale, value.Z / scale); } @@ -590,7 +590,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(float scale, ref Vector3 value, out Vector3 result) + public static void Divide(float scale, in Vector3 value, out Vector3 result) { result = new Vector3(scale / value.X, scale / value.Y, scale / value.Z); } @@ -611,7 +611,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Vector3 value, out Vector3 result) + public static void Negate(in Vector3 value, out Vector3 result) { result = new Vector3(-value.X, -value.Y, -value.Z); } @@ -635,7 +635,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 3D Cartesian coordinates of the specified point. - public static void Barycentric(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, float amount1, float amount2, out Vector3 result) + public static void Barycentric(in Vector3 value1, in Vector3 value2, in Vector3 value3, float amount1, float amount2, out Vector3 result) { result = new Vector3(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y), @@ -653,7 +653,7 @@ namespace FlaxEngine /// A new containing the 3D Cartesian coordinates of the specified point. public static Vector3 Barycentric(Vector3 value1, Vector3 value2, Vector3 value3, float amount1, float amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out var result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out var result); return result; } @@ -664,7 +664,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Vector3 value, ref Vector3 min, ref Vector3 max, out Vector3 result) + public static void Clamp(in Vector3 value, in Vector3 min, in Vector3 max, out Vector3 result) { Real x = value.X; x = x > max.X ? max.X : x; @@ -687,7 +687,7 @@ namespace FlaxEngine /// The clamped value. public static Vector3 Clamp(Vector3 value, Vector3 min, Vector3 max) { - Clamp(ref value, ref min, ref max, out var result); + Clamp(in value, in min, in max, out var result); return result; } @@ -697,7 +697,7 @@ namespace FlaxEngine /// First source vector. /// Second source vector. /// When the method completes, contains he cross product of the two vectors. - public static void Cross(ref Vector3 left, ref Vector3 right, out Vector3 result) + public static void Cross(in Vector3 left, in Vector3 right, out Vector3 result) { result = new Vector3(left.Y * right.Z - left.Z * right.Y, left.Z * right.X - left.X * right.Z, @@ -712,7 +712,7 @@ namespace FlaxEngine /// The cross product of the two vectors. public static Vector3 Cross(Vector3 left, Vector3 right) { - Cross(ref left, ref right, out var result); + Cross(in left, in right, out var result); return result; } @@ -722,8 +722,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Vector3 value1, ref Vector3 value2, out Real result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Vector3 value1, in Vector3 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -737,8 +737,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static Real Distance(ref Vector3 value1, ref Vector3 value2) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static Real Distance(in Vector3 value1, in Vector3 value2) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -767,7 +767,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Vector3 value1, ref Vector3 value2, out Real result) + public static void DistanceSquared(in Vector3 value1, in Vector3 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -781,7 +781,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// The squared distance between the two vectors. - public static Real DistanceSquared(ref Vector3 value1, ref Vector3 value2) + public static Real DistanceSquared(in Vector3 value1, in Vector3 value2) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -809,7 +809,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the XY plane. - public static void DistanceXY(ref Vector3 value1, ref Vector3 value2, out Real result) + public static void DistanceXY(in Vector3 value1, in Vector3 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -822,7 +822,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the XY plane. - public static void DistanceXYSquared(ref Vector3 value1, ref Vector3 value2, out Real result) + public static void DistanceXYSquared(in Vector3 value1, in Vector3 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -835,7 +835,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the XY plane. - public static void DistanceXZ(ref Vector3 value1, ref Vector3 value2, out Real result) + public static void DistanceXZ(in Vector3 value1, in Vector3 value2, out Real result) { Real x = value1.X - value2.X; Real z = value1.Z - value2.Z; @@ -848,7 +848,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the XY plane. - public static void DistanceXZSquared(ref Vector3 value1, ref Vector3 value2, out Real result) + public static void DistanceXZSquared(in Vector3 value1, in Vector3 value2, out Real result) { Real x = value1.X - value2.X; Real z = value1.Z - value2.Z; @@ -861,7 +861,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors in the YZ plane. - public static void DistanceYZ(ref Vector3 value1, ref Vector3 value2, out Real result) + public static void DistanceYZ(in Vector3 value1, in Vector3 value2, out Real result) { Real y = value1.Y - value2.Y; Real z = value1.Z - value2.Z; @@ -874,7 +874,7 @@ namespace FlaxEngine /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors in the YZ plane. - public static void DistanceYZSquared(ref Vector3 value1, ref Vector3 value2, out Real result) + public static void DistanceYZSquared(in Vector3 value1, in Vector3 value2, out Real result) { Real y = value1.Y - value2.Y; Real z = value1.Z - value2.Z; @@ -890,7 +890,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Vector3 left, Vector3 right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -900,7 +900,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Vector3 left, ref Vector3 right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Vector3 left, in Vector3 right, float epsilon = Mathf.Epsilon) { return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon) && Mathf.WithinEpsilon(left.Z, right.Z, epsilon); } @@ -912,7 +912,7 @@ namespace FlaxEngine /// Second source vector. /// When the method completes, contains the dot product of the two vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dot(ref Vector3 left, ref Vector3 right, out Real result) + public static void Dot(in Vector3 left, in Vector3 right, out Real result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z; } @@ -924,7 +924,7 @@ namespace FlaxEngine /// Second source vector. /// The dot product of the two vectors. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Real Dot(ref Vector3 left, ref Vector3 right) + public static Real Dot(in Vector3 left, in Vector3 right) { return left.X * right.X + left.Y * right.Y + left.Z * right.Z; } @@ -946,7 +946,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Vector3 value, out Vector3 result) + public static void Normalize(in Vector3 value, out Vector3 result) { result = value; result.Normalize(); @@ -1022,7 +1022,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Vector3 start, ref Vector3 end, float amount, out Vector3 result) + public static void Lerp(in Vector3 start, in Vector3 end, float amount, out Vector3 result) { result.X = Mathr.Lerp(start.X, end.X, amount); result.Y = Mathr.Lerp(start.Y, end.Y, amount); @@ -1039,7 +1039,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Vector3 Lerp(Vector3 start, Vector3 end, float amount) { - Lerp(ref start, ref end, amount, out var result); + Lerp(in start, in end, amount, out var result); return result; } @@ -1147,10 +1147,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Vector3 start, ref Vector3 end, float amount, out Vector3 result) + public static void SmoothStep(in Vector3 start, in Vector3 end, float amount, out Vector3 result) { amount = Mathf.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -1162,7 +1162,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Vector3 SmoothStep(Vector3 start, Vector3 end, float amount) { - SmoothStep(ref start, ref end, amount, out var result); + SmoothStep(in start, in end, amount, out var result); return result; } @@ -1192,7 +1192,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Vector3 value1, ref Vector3 tangent1, ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result) + public static void Hermite(in Vector3 value1, in Vector3 tangent1, in Vector3 value2, in Vector3 tangent2, float amount, out Vector3 result) { float squared = amount * amount; float cubed = amount * squared; @@ -1216,7 +1216,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Vector3 Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, Vector3 tangent2, float amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out var result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out var result); return result; } @@ -1229,7 +1229,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, ref Vector3 value4, float amount, out Vector3 result) + public static void CatmullRom(in Vector3 value1, in Vector3 value2, in Vector3 value3, in Vector3 value4, float amount, out Vector3 result) { float squared = amount * amount; float cubed = amount * squared; @@ -1255,7 +1255,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Vector3 CatmullRom(Vector3 value1, Vector3 value2, Vector3 value3, Vector3 value4, float amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out var result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out var result); return result; } @@ -1265,7 +1265,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Vector3 left, ref Vector3 right, out Vector3 result) + public static void Max(in Vector3 left, in Vector3 right, out Vector3 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -1280,7 +1280,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Vector3 Max(Vector3 left, Vector3 right) { - Max(ref left, ref right, out var result); + Max(in left, in right, out var result); return result; } @@ -1290,7 +1290,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Vector3 left, ref Vector3 right, out Vector3 result) + public static void Min(in Vector3 left, in Vector3 right, out Vector3 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -1305,7 +1305,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Vector3 Min(Vector3 left, Vector3 right) { - Min(ref left, ref right, out var result); + Min(in left, in right, out var result); return result; } @@ -1385,9 +1385,9 @@ namespace FlaxEngine /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in screen space. - public static void Project(ref Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vector3 result) + public static void Project(in Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, in Matrix worldViewProjection, out Vector3 result) { - TransformCoordinate(ref vector, ref worldViewProjection, out var v); + TransformCoordinate(in vector, in worldViewProjection, out var v); result = new Vector3((1.0f + v.X) * 0.5f * width + x, (1.0f - v.Y) * 0.5f * height + y, v.Z * (maxZ - minZ) + minZ); } @@ -1405,7 +1405,7 @@ namespace FlaxEngine /// The vector in screen space. public static Vector3 Project(Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection) { - Project(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); + Project(in vector, x, y, width, height, minZ, maxZ, in worldViewProjection, out var result); return result; } @@ -1421,16 +1421,16 @@ namespace FlaxEngine /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in object space. - public static void Unproject(ref Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vector3 result) + public static void Unproject(in Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, in Matrix worldViewProjection, out Vector3 result) { - Matrix.Invert(ref worldViewProjection, out var matrix); + Matrix.Invert(worldViewProjection, out var matrix); var v = new Vector3 { X = (vector.X - x) / width * 2.0f - 1.0f, Y = -((vector.Y - y) / height * 2.0f - 1.0f), Z = (vector.Z - minZ) / (maxZ - minZ) }; - TransformCoordinate(ref v, ref matrix, out result); + TransformCoordinate(in v, in matrix, out result); } /// @@ -1447,7 +1447,7 @@ namespace FlaxEngine /// The vector in object space. public static Vector3 Unproject(Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection) { - Unproject(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out var result); + Unproject(in vector, x, y, width, height, minZ, maxZ, in worldViewProjection, out var result); return result; } @@ -1458,7 +1458,7 @@ namespace FlaxEngine /// Normal of the surface. /// When the method completes, contains the reflected vector. /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Vector3 vector, ref Vector3 normal, out Vector3 result) + public static void Reflect(in Vector3 vector, in Vector3 normal, out Vector3 result) { Real dot = vector.X * normal.X + vector.Y * normal.Y + vector.Z * normal.Z; result.X = vector.X - 2.0f * dot * normal.X; @@ -1475,7 +1475,7 @@ namespace FlaxEngine /// Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it. public static Vector3 Reflect(Vector3 vector, Vector3 normal) { - Reflect(ref vector, ref normal, out var result); + Reflect(in vector, in normal, out var result); return result; } @@ -1485,7 +1485,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Vector3 vector, ref Quaternion rotation, out Vector3 result) + public static void Transform(in Vector3 vector, in Quaternion rotation, out Vector3 result) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1512,7 +1512,7 @@ namespace FlaxEngine /// The transformed . public static Vector3 Transform(Vector3 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out var result); + Transform(in vector, in rotation, out var result); return result; } @@ -1522,7 +1522,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vector3 vector, ref Matrix3x3 transform, out Vector3 result) + public static void Transform(in Vector3 vector, in Matrix3x3 transform, out Vector3 result) { result = new Vector3((vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31), (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32), @@ -1537,7 +1537,7 @@ namespace FlaxEngine /// The transformed . public static Vector3 Transform(Vector3 vector, Matrix3x3 transform) { - Transform(ref vector, ref transform, out var result); + Transform(in vector, in transform, out var result); return result; } @@ -1547,7 +1547,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vector3 vector, ref Matrix transform, out Vector3 result) + public static void Transform(in Vector3 vector, in Matrix transform, out Vector3 result) { result = new Vector3(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + transform.M42, @@ -1560,7 +1560,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vector3 vector, ref Matrix transform, out Vector4 result) + public static void Transform(in Vector3 vector, in Matrix transform, out Vector4 result) { result = new Vector4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + transform.M42, @@ -1574,9 +1574,9 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vector3 vector, ref Transform transform, out Vector3 result) + public static void Transform(in Vector3 vector, in Transform transform, out Vector3 result) { - transform.LocalToWorld(ref vector, out result); + transform.LocalToWorld(vector, out result); } /// @@ -1587,7 +1587,7 @@ namespace FlaxEngine /// The transformed . public static Vector3 Transform(Vector3 vector, Matrix transform) { - Transform(ref vector, ref transform, out Vector3 result); + Transform(in vector, in transform, out Vector3 result); return result; } @@ -1599,7 +1599,7 @@ namespace FlaxEngine /// The transformed . public static Vector3 Transform(Vector3 vector, Transform transform) { - Transform(ref vector, ref transform, out Vector3 result); + Transform(in vector, in transform, out Vector3 result); return result; } @@ -1616,7 +1616,7 @@ namespace FlaxEngine /// therefore makes the vector homogeneous. The homogeneous vector is often preferred when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Vector3 coordinate, ref Matrix transform, out Vector3 result) + public static void TransformCoordinate(in Vector3 coordinate, in Matrix transform, out Vector3 result) { var vector = new Vector4 { @@ -1643,7 +1643,7 @@ namespace FlaxEngine /// public static Vector3 TransformCoordinate(Vector3 coordinate, Matrix transform) { - TransformCoordinate(ref coordinate, ref transform, out var result); + TransformCoordinate(in coordinate, in transform, out var result); return result; } @@ -1660,7 +1660,7 @@ namespace FlaxEngine /// apply. This is often preferred for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Vector3 normal, ref Matrix transform, out Vector3 result) + public static void TransformNormal(in Vector3 normal, in Matrix transform, out Vector3 result) { result = new Vector3(normal.X * transform.M11 + normal.Y * transform.M21 + normal.Z * transform.M31, normal.X * transform.M12 + normal.Y * transform.M22 + normal.Z * transform.M32, @@ -1682,7 +1682,7 @@ namespace FlaxEngine /// public static Vector3 TransformNormal(Vector3 normal, Matrix transform) { - TransformNormal(ref normal, ref transform, out var result); + TransformNormal(in normal, in transform, out var result); return result; } @@ -1750,7 +1750,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1799,7 +1799,7 @@ namespace FlaxEngine /// The scaled vector. public static Vector3 operator *(Vector3 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out var result); + Transform(in vector, in rotation, out var result); return result; } @@ -2010,7 +2010,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Vector3 left, Vector3 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -2022,7 +2022,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Vector3 left, Vector3 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -2139,7 +2139,7 @@ namespace FlaxEngine /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Vector3 other) + public bool Equals(in Vector3 other) { return X == other.X && Y == other.Y && Z == other.Z; } @@ -2152,7 +2152,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Vector3 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -2162,7 +2162,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Vector3 other && Equals(ref other); + return value is Vector3 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Vector4.cs b/Source/Engine/Core/Math/Vector4.cs index e50d03ca0..5f14539fc 100644 --- a/Source/Engine/Core/Math/Vector4.cs +++ b/Source/Engine/Core/Math/Vector4.cs @@ -386,7 +386,7 @@ namespace FlaxEngine /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Vector4 left, ref Vector4 right, out Vector4 result) + public static void Add(in Vector4 left, in Vector4 right, out Vector4 result) { result = new Vector4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); } @@ -408,7 +408,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be added to elements /// The vector with added scalar for each element. - public static void Add(ref Vector4 left, ref Real right, out Vector4 result) + public static void Add(in Vector4 left, in Real right, out Vector4 result) { result = new Vector4(left.X + right, left.Y + right, left.Z + right, left.W + right); } @@ -430,7 +430,7 @@ namespace FlaxEngine /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Vector4 left, ref Vector4 right, out Vector4 result) + public static void Subtract(in Vector4 left, in Vector4 right, out Vector4 result) { result = new Vector4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); } @@ -452,7 +452,7 @@ namespace FlaxEngine /// The input vector /// The scalar value to be subtracted from elements /// The vector with subtracted scalar for each element. - public static void Subtract(ref Vector4 left, ref Real right, out Vector4 result) + public static void Subtract(in Vector4 left, in Real right, out Vector4 result) { result = new Vector4(left.X - right, left.Y - right, left.Z - right, left.W - right); } @@ -474,7 +474,7 @@ namespace FlaxEngine /// The scalar value to be subtracted from elements /// The input vector. /// The vector with subtracted scalar for each element. - public static void Subtract(ref Real left, ref Vector4 right, out Vector4 result) + public static void Subtract(in Real left, in Vector4 right, out Vector4 result) { result = new Vector4(left - right.X, left - right.Y, left - right.Z, left - right.W); } @@ -496,7 +496,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Vector4 value, Real scale, out Vector4 result) + public static void Multiply(in Vector4 value, Real scale, out Vector4 result) { result = new Vector4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); } @@ -518,7 +518,7 @@ namespace FlaxEngine /// The first vector to multiply. /// The second vector to multiply. /// When the method completes, contains the multiplied vector. - public static void Multiply(ref Vector4 left, ref Vector4 right, out Vector4 result) + public static void Multiply(in Vector4 left, in Vector4 right, out Vector4 result) { result = new Vector4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); } @@ -540,7 +540,7 @@ namespace FlaxEngine /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Vector4 value, Real scale, out Vector4 result) + public static void Divide(in Vector4 value, Real scale, out Vector4 result) { result = new Vector4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); } @@ -562,7 +562,7 @@ namespace FlaxEngine /// The amount by which to scale the vector. /// The vector to scale. /// When the method completes, contains the scaled vector. - public static void Divide(Real scale, ref Vector4 value, out Vector4 result) + public static void Divide(Real scale, in Vector4 value, out Vector4 result) { result = new Vector4(scale / value.X, scale / value.Y, scale / value.Z, scale / value.W); } @@ -583,7 +583,7 @@ namespace FlaxEngine /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Vector4 value, out Vector4 result) + public static void Negate(in Vector4 value, out Vector4 result) { result = new Vector4(-value.X, -value.Y, -value.Z, -value.W); } @@ -607,7 +607,7 @@ namespace FlaxEngine /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 4D Cartesian coordinates of the specified point. - public static void Barycentric(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, float amount1, float amount2, out Vector4 result) + public static void Barycentric(in Vector4 value1, in Vector4 value2, in Vector4 value3, float amount1, float amount2, out Vector4 result) { result = new Vector4(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X), value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y), @@ -626,7 +626,7 @@ namespace FlaxEngine /// A new containing the 4D Cartesian coordinates of the specified point. public static Vector4 Barycentric(Vector4 value1, Vector4 value2, Vector4 value3, float amount1, float amount2) { - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out Vector4 result); + Barycentric(in value1, in value2, in value3, amount1, amount2, out Vector4 result); return result; } @@ -637,7 +637,7 @@ namespace FlaxEngine /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Vector4 value, ref Vector4 min, ref Vector4 max, out Vector4 result) + public static void Clamp(in Vector4 value, in Vector4 min, in Vector4 max, out Vector4 result) { Real x = value.X; x = x > max.X ? max.X : x; @@ -663,7 +663,7 @@ namespace FlaxEngine /// The clamped value. public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max) { - Clamp(ref value, ref min, ref max, out Vector4 result); + Clamp(in value, in min, in max, out Vector4 result); return result; } @@ -673,8 +673,8 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the distance between the two vectors. - /// may be preferred when only the relative distance is needed and speed is of the essence. - public static void Distance(ref Vector4 value1, ref Vector4 value2, out Real result) + /// may be preferred when only the relative distance is needed and speed is of the essence. + public static void Distance(in Vector4 value1, in Vector4 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -705,7 +705,7 @@ namespace FlaxEngine /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - public static void DistanceSquared(ref Vector4 value1, ref Vector4 value2, out Real result) + public static void DistanceSquared(in Vector4 value1, in Vector4 value2, out Real result) { Real x = value1.X - value2.X; Real y = value1.Y - value2.Y; @@ -738,7 +738,7 @@ namespace FlaxEngine /// true if left and right are near another, false otherwise public static bool NearEqual(Vector4 left, Vector4 right, float epsilon = Mathf.Epsilon) { - return NearEqual(ref left, ref right, epsilon); + return NearEqual(in left, in right, epsilon); } /// @@ -748,7 +748,7 @@ namespace FlaxEngine /// The right vector. /// The epsilon. /// true if left and right are near another, false otherwise - public static bool NearEqual(ref Vector4 left, ref Vector4 right, float epsilon = Mathf.Epsilon) + public static bool NearEqual(in Vector4 left, in Vector4 right, float epsilon = Mathf.Epsilon) { return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon) && Mathf.WithinEpsilon(left.Z, right.Z, epsilon) && Mathf.WithinEpsilon(left.W, right.W, epsilon); } @@ -759,7 +759,7 @@ namespace FlaxEngine /// First source vector /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Vector4 left, ref Vector4 right, out Real result) + public static void Dot(in Vector4 left, in Vector4 right, out Real result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } @@ -780,7 +780,7 @@ namespace FlaxEngine /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - public static void Normalize(ref Vector4 value, out Vector4 result) + public static void Normalize(in Vector4 value, out Vector4 result) { result = value; result.Normalize(); @@ -856,7 +856,7 @@ namespace FlaxEngine /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two vectors. /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. - public static void Lerp(ref Vector4 start, ref Vector4 end, Real amount, out Vector4 result) + public static void Lerp(in Vector4 start, in Vector4 end, Real amount, out Vector4 result) { result.X = Mathr.Lerp(start.X, end.X, amount); result.Y = Mathr.Lerp(start.Y, end.Y, amount); @@ -874,7 +874,7 @@ namespace FlaxEngine /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. public static Vector4 Lerp(Vector4 start, Vector4 end, Real amount) { - Lerp(ref start, ref end, amount, out Vector4 result); + Lerp(in start, in end, amount, out Vector4 result); return result; } @@ -885,10 +885,10 @@ namespace FlaxEngine /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Vector4 start, ref Vector4 end, Real amount, out Vector4 result) + public static void SmoothStep(in Vector4 start, in Vector4 end, Real amount, out Vector4 result) { amount = Mathr.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + Lerp(in start, in end, amount, out result); } /// @@ -900,7 +900,7 @@ namespace FlaxEngine /// The cubic interpolation of the two vectors. public static Vector4 SmoothStep(Vector4 start, Vector4 end, Real amount) { - SmoothStep(ref start, ref end, amount, out Vector4 result); + SmoothStep(in start, in end, amount, out Vector4 result); return result; } @@ -913,7 +913,7 @@ namespace FlaxEngine /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Vector4 value1, ref Vector4 tangent1, ref Vector4 value2, ref Vector4 tangent2, float amount, out Vector4 result) + public static void Hermite(in Vector4 value1, in Vector4 tangent1, in Vector4 value2, in Vector4 tangent2, float amount, out Vector4 result) { float squared = amount * amount; float cubed = amount * squared; @@ -938,7 +938,7 @@ namespace FlaxEngine /// The result of the Hermite spline interpolation. public static Vector4 Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount) { - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out Vector4 result); + Hermite(in value1, in tangent1, in value2, in tangent2, amount, out Vector4 result); return result; } @@ -951,7 +951,7 @@ namespace FlaxEngine /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, ref Vector4 value4, float amount, out Vector4 result) + public static void CatmullRom(in Vector4 value1, in Vector4 value2, in Vector4 value3, in Vector4 value4, float amount, out Vector4 result) { float squared = amount * amount; float cubed = amount * squared; @@ -972,7 +972,7 @@ namespace FlaxEngine /// A vector that is the result of the Catmull-Rom interpolation. public static Vector4 CatmullRom(Vector4 value1, Vector4 value2, Vector4 value3, Vector4 value4, float amount) { - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out Vector4 result); + CatmullRom(in value1, in value2, in value3, in value4, amount, out Vector4 result); return result; } @@ -982,7 +982,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Vector4 left, ref Vector4 right, out Vector4 result) + public static void Max(in Vector4 left, in Vector4 right, out Vector4 result) { result.X = left.X > right.X ? left.X : right.X; result.Y = left.Y > right.Y ? left.Y : right.Y; @@ -998,7 +998,7 @@ namespace FlaxEngine /// A vector containing the largest components of the source vectors. public static Vector4 Max(Vector4 left, Vector4 right) { - Max(ref left, ref right, out Vector4 result); + Max(in left, in right, out Vector4 result); return result; } @@ -1008,7 +1008,7 @@ namespace FlaxEngine /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Vector4 left, ref Vector4 right, out Vector4 result) + public static void Min(in Vector4 left, in Vector4 right, out Vector4 result) { result.X = left.X < right.X ? left.X : right.X; result.Y = left.Y < right.Y ? left.Y : right.Y; @@ -1024,7 +1024,7 @@ namespace FlaxEngine /// A vector containing the smallest components of the source vectors. public static Vector4 Min(Vector4 left, Vector4 right) { - Min(ref left, ref right, out Vector4 result); + Min(in left, in right, out Vector4 result); return result; } @@ -1044,7 +1044,7 @@ namespace FlaxEngine /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Vector4 vector, ref Quaternion rotation, out Vector4 result) + public static void Transform(in Vector4 vector, in Quaternion rotation, out Vector4 result) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1072,7 +1072,7 @@ namespace FlaxEngine /// The transformed . public static Vector4 Transform(Vector4 vector, Quaternion rotation) { - Transform(ref vector, ref rotation, out Vector4 result); + Transform(in vector, in rotation, out Vector4 result); return result; } @@ -1082,7 +1082,7 @@ namespace FlaxEngine /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vector4 vector, ref Matrix transform, out Vector4 result) + public static void Transform(in Vector4 vector, in Matrix transform, out Vector4 result) { result = new Vector4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + vector.W * transform.M41, vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + vector.W * transform.M42, @@ -1098,7 +1098,7 @@ namespace FlaxEngine /// The transformed . public static Vector4 Transform(Vector4 vector, Matrix transform) { - Transform(ref vector, ref transform, out Vector4 result); + Transform(in vector, in transform, out Vector4 result); return result; } @@ -1114,7 +1114,7 @@ namespace FlaxEngine } /// - /// Multiplies a vector with another by performing component-wise multiplication equivalent to . + /// Multiplies a vector with another by performing component-wise multiplication equivalent to . /// /// The first vector to multiply. /// The second vector to multiply. @@ -1362,7 +1362,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Vector4 left, Vector4 right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -1374,7 +1374,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Vector4 left, Vector4 right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -1491,7 +1491,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Vector4 other) + public bool Equals(in Vector4 other) { return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } @@ -1504,7 +1504,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Vector4 other) { - return Equals(ref other); + return Equals(in other); } /// @@ -1514,7 +1514,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Vector4 other && Equals(ref other); + return value is Vector4 other && Equals(in other); } } } diff --git a/Source/Engine/Core/Math/Viewport.cs b/Source/Engine/Core/Math/Viewport.cs index f2be10457..2d6b350b2 100644 --- a/Source/Engine/Core/Math/Viewport.cs +++ b/Source/Engine/Core/Math/Viewport.cs @@ -171,7 +171,7 @@ namespace FlaxEngine /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - public bool Equals(ref Viewport other) + public bool Equals(in Viewport other) { return Mathf.NearEqual(X, other.X) && Mathf.NearEqual(Y, other.Y) && @@ -189,7 +189,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Viewport other) { - return Equals(ref other); + return Equals(in other); } /// @@ -199,7 +199,7 @@ namespace FlaxEngine /// true if the specified object is equal to this instance; otherwise, false. public override bool Equals(object obj) { - return obj is Viewport other && Equals(ref other); + return obj is Viewport other && Equals(in other); } /// @@ -231,7 +231,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Viewport left, Viewport right) { - return left.Equals(ref right); + return left.Equals(in right); } /// @@ -243,7 +243,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Viewport left, Viewport right) { - return !left.Equals(ref right); + return !left.Equals(in right); } /// @@ -265,10 +265,10 @@ namespace FlaxEngine /// The projected vector. public Vector3 Project(Vector3 source, Matrix projection, Matrix view, Matrix world) { - Matrix.Multiply(ref world, ref view, out Matrix matrix); - Matrix.Multiply(ref matrix, ref projection, out matrix); + Matrix.Multiply(world, view, out Matrix matrix); + Matrix.Multiply(matrix, projection, out matrix); - Project(ref source, ref matrix, out Vector3 vector); + Project(in source, in matrix, out Vector3 vector); return vector; } @@ -278,9 +278,9 @@ namespace FlaxEngine /// The vector to project. /// A combined WorldViewProjection matrix. /// The projected vector. - public void Project(ref Vector3 source, ref Matrix matrix, out Vector3 vector) + public void Project(in Vector3 source, in Matrix matrix, out Vector3 vector) { - Vector3.Transform(ref source, ref matrix, out vector); + Vector3.Transform(source, matrix, out vector); var w = source.X * matrix.M14 + source.Y * matrix.M24 + source.Z * matrix.M34 + matrix.M44; if (!Mathf.IsZero(w)) @@ -303,11 +303,11 @@ namespace FlaxEngine /// The unprojected Vector. public Vector3 Unproject(Vector3 source, Matrix projection, Matrix view, Matrix world) { - Matrix.Multiply(ref world, ref view, out Matrix matrix); - Matrix.Multiply(ref matrix, ref projection, out matrix); - Matrix.Invert(ref matrix, out matrix); + Matrix.Multiply(world, view, out Matrix matrix); + Matrix.Multiply(matrix, projection, out matrix); + Matrix.Invert(matrix, out matrix); - Unproject(ref source, ref matrix, out Vector3 vector); + Unproject(in source, in matrix, out Vector3 vector); return vector; } @@ -317,14 +317,14 @@ namespace FlaxEngine /// The vector to project. /// An inverted combined WorldViewProjection matrix. /// The unprojected vector. - public void Unproject(ref Vector3 source, ref Matrix matrix, out Vector3 vector) + public void Unproject(in Vector3 source, in Matrix matrix, out Vector3 vector) { vector.X = (source.X - X) / Width * 2f - 1f; vector.Y = -((source.Y - Y) / Height * 2f - 1f); vector.Z = (source.Z - MinDepth) / (MaxDepth - MinDepth); var w = vector.X * matrix.M14 + vector.Y * matrix.M24 + vector.Z * matrix.M34 + matrix.M44; - Vector3.Transform(ref vector, ref matrix, out vector); + Vector3.Transform(vector, matrix, out vector); if (!Mathf.IsZero(w)) { diff --git a/Source/Engine/Graphics/Models/MeshAccessor.cs b/Source/Engine/Graphics/Models/MeshAccessor.cs index 29ff54cf1..e7d551843 100644 --- a/Source/Engine/Graphics/Models/MeshAccessor.cs +++ b/Source/Engine/Graphics/Models/MeshAccessor.cs @@ -494,8 +494,8 @@ namespace FlaxEngine for (int i = 0; i < vertices; i++) { Float3 pos = positionStream.GetFloat3(i); - Float3.Min(ref min, ref pos, out min); - Float3.Max(ref max, ref pos, out max); + Float3.Min(min, pos, out min); + Float3.Max(max, pos, out max); } bounds = new BoundingBox(min, max); } diff --git a/Source/Engine/Graphics/RenderView.cs b/Source/Engine/Graphics/RenderView.cs index ffd131e7a..b865ff218 100644 --- a/Source/Engine/Graphics/RenderView.cs +++ b/Source/Engine/Graphics/RenderView.cs @@ -24,11 +24,11 @@ namespace FlaxEngine /// public void UpdateCachedData() { - Matrix.Invert(ref View, out IV); - Matrix.Invert(ref Projection, out IP); - Matrix.Multiply(ref View, ref Projection, out var viewProjection); - Frustum = new BoundingFrustum(ref viewProjection); - Matrix.Invert(ref viewProjection, out IVP); + Matrix.Invert(View, out IV); + Matrix.Invert(Projection, out IP); + Matrix.Multiply(View, Projection, out var viewProjection); + Frustum = new BoundingFrustum(viewProjection); + Matrix.Invert(viewProjection, out IVP); CullingFrustum = Frustum; NonJitteredProjection = Projection; } @@ -71,7 +71,7 @@ namespace FlaxEngine // Create view matrix Direction = direction; var target = Position + Direction; - Matrix.LookAt(ref Position, ref target, ref up, out View); + Matrix.LookAt(Position, target, up, out View); UpdateCachedData(); } @@ -117,7 +117,7 @@ namespace FlaxEngine public void GetWorldMatrix(ref Transform transform, out Matrix world) { Float3 translation = transform.Translation - Origin; - Matrix.Transformation(ref transform.Scale, ref transform.Orientation, ref translation, out world); + Matrix.Transformation(transform.Scale, transform.Orientation, translation, out world); } } } diff --git a/Source/Engine/Graphics/Textures/GPUTextureDescription.cs b/Source/Engine/Graphics/Textures/GPUTextureDescription.cs index 00aa17141..29639b6cd 100644 --- a/Source/Engine/Graphics/Textures/GPUTextureDescription.cs +++ b/Source/Engine/Graphics/Textures/GPUTextureDescription.cs @@ -390,7 +390,7 @@ namespace FlaxEngine MultiSampleLevel == other.MultiSampleLevel && Flags == other.Flags && Usage == other.Usage && - DefaultClearColor.Equals(ref other.DefaultClearColor); + DefaultClearColor.Equals(other.DefaultClearColor); } }; } diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 51b24e25f..f6ba6b04c 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -79,7 +79,7 @@ namespace FlaxEngine get => Orientation.EulerAngles; set { - Quaternion.Euler(ref value, out var orientation); + Quaternion.Euler(value, out var orientation); Internal_SetOrientation(__unmanagedPtr, orientation); } } @@ -97,7 +97,7 @@ namespace FlaxEngine get => LocalOrientation.EulerAngles; set { - Quaternion.Euler(ref value, out var orientation); + Quaternion.Euler(value, out var orientation); Internal_SetLocalOrientation(__unmanagedPtr, orientation); } } diff --git a/Source/Engine/Physics/Collisions.cs b/Source/Engine/Physics/Collisions.cs index 9285781e2..55524348b 100644 --- a/Source/Engine/Physics/Collisions.cs +++ b/Source/Engine/Physics/Collisions.cs @@ -93,7 +93,7 @@ namespace FlaxEngine { get { - Vector3.Subtract(ref ThisVelocity, ref OtherVelocity, out var result); + Vector3.Subtract(ThisVelocity, OtherVelocity, out var result); return result; } } diff --git a/Source/Engine/Tests/TestTransform.cs b/Source/Engine/Tests/TestTransform.cs index a3f3b2f03..f639500c7 100644 --- a/Source/Engine/Tests/TestTransform.cs +++ b/Source/Engine/Tests/TestTransform.cs @@ -26,12 +26,12 @@ namespace FlaxEngine.Tests Matrix a2; { Matrix m1, m2; - Matrix.Scaling(ref t1.Scale, out a2); - Matrix.RotationQuaternion(ref t1.Orientation, out m2); - Matrix.Multiply(ref a2, ref m2, out m1); + Matrix.Scaling(t1.Scale, out a2); + Matrix.RotationQuaternion(t1.Orientation, out m2); + Matrix.Multiply(a2, m2, out m1); Float3 translation = t1.Translation; - Matrix.Translation(ref translation, out m2); - Matrix.Multiply(ref m1, ref m2, out a2); + Matrix.Translation(translation, out m2); + Matrix.Multiply(m1, m2, out a2); } Matrix a3; @@ -57,10 +57,10 @@ namespace FlaxEngine.Tests { Vector3 result; Matrix scale, rotation, scaleRotation; - Matrix.Scaling(ref t1.Scale, out scale); - Matrix.RotationQuaternion(ref t1.Orientation, out rotation); - Matrix.Multiply(ref scale, ref rotation, out scaleRotation); - Vector3.Transform(ref t2.Translation, ref scaleRotation, out result); + Matrix.Scaling(t1.Scale, out scale); + Matrix.RotationQuaternion(t1.Orientation, out rotation); + Matrix.Multiply(scale, rotation, out scaleRotation); + Vector3.Transform(t2.Translation, scaleRotation, out result); a3 = result + t1.Translation; } @@ -88,12 +88,12 @@ namespace FlaxEngine.Tests Float3 a3; { Matrix scale, rotation, scaleRotation; - Matrix.Scaling(ref t1.Scale, out scale); - Matrix.RotationQuaternion(ref t1.Orientation, out rotation); - Matrix.Multiply(ref scale, ref rotation, out scaleRotation); - Matrix.Invert(ref scaleRotation, out scale); + Matrix.Scaling(t1.Scale, out scale); + Matrix.RotationQuaternion(t1.Orientation, out rotation); + Matrix.Multiply(scale, rotation, out scaleRotation); + Matrix.Invert(scaleRotation, out scale); a3 = t2.Translation - t1.Translation; - Float3.Transform(ref a3, ref scale, out a3); + Float3.Transform(a3, scale, out a3); } var a4T = new Vector3[1]; @@ -145,7 +145,7 @@ namespace FlaxEngine.Tests Transform ab = a.LocalToWorld(b); Transform ba = a.WorldToLocal(ab); - Assert.IsTrue(Transform.NearEqual(ref b, ref ba, 0.00001f), $"Got: {b} but expected {ba}"); + Assert.IsTrue(Transform.NearEqual(b, ba, 0.00001f), $"Got: {b} but expected {ba}"); } } @@ -163,11 +163,11 @@ namespace FlaxEngine.Tests Transform ab = a + b; Transform newA = ab - b; - Assert.IsTrue(Transform.NearEqual(ref a, ref newA, 0.00001f), $"Got: {newA} but expected {a}"); + Assert.IsTrue(Transform.NearEqual(a, newA, 0.00001f), $"Got: {newA} but expected {a}"); Transform ba = b + a; Transform newB = ba - a; - Assert.IsTrue(Transform.NearEqual(ref b, ref newB, 0.00001f), $"Got: {newB} but expected {b}"); + Assert.IsTrue(Transform.NearEqual(b, newB, 0.00001f), $"Got: {newB} but expected {b}"); } } } diff --git a/Source/Engine/UI/GUI/CanvasRootControl.cs b/Source/Engine/UI/GUI/CanvasRootControl.cs index 4697c5051..d3b69ac9c 100644 --- a/Source/Engine/UI/GUI/CanvasRootControl.cs +++ b/Source/Engine/UI/GUI/CanvasRootControl.cs @@ -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; } diff --git a/Source/Engine/UI/GUI/CanvasScaler.cs b/Source/Engine/UI/GUI/CanvasScaler.cs index b7f2495c4..bc9251eef 100644 --- a/Source/Engine/UI/GUI/CanvasScaler.cs +++ b/Source/Engine/UI/GUI/CanvasScaler.cs @@ -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) { diff --git a/Source/Engine/UI/GUI/Common/CheckBox.cs b/Source/Engine/UI/GUI/Common/CheckBox.cs index 47073cb27..92066e9fe 100644 --- a/Source/Engine/UI/GUI/Common/CheckBox.cs +++ b/Source/Engine/UI/GUI/Common/CheckBox.cs @@ -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); } /// @@ -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; diff --git a/Source/Engine/UI/GUI/Common/Dropdown.cs b/Source/Engine/UI/GUI/Common/Dropdown.cs index a227e5acd..8928241ca 100644 --- a/Source/Engine/UI/GUI/Common/Dropdown.cs +++ b/Source/Engine/UI/GUI/Common/Dropdown.cs @@ -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; diff --git a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs index 133279812..d153fc5e1 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs @@ -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; diff --git a/Source/Engine/UI/GUI/Common/Slider.cs b/Source/Engine/UI/GUI/Common/Slider.cs index fb40af296..cb44a44de 100644 --- a/Source/Engine/UI/GUI/Common/Slider.cs +++ b/Source/Engine/UI/GUI/Common/Slider.cs @@ -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; diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 243e4786e..293ffb940 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -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(); diff --git a/Source/Engine/UI/GUI/ContainerControl.cs b/Source/Engine/UI/GUI/ContainerControl.cs index 32ddb8641..8831933b3 100644 --- a/Source/Engine/UI/GUI/ContainerControl.cs +++ b/Source/Engine/UI/GUI/ContainerControl.cs @@ -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(); diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs index 62bffd6f7..3c5156661 100644 --- a/Source/Engine/UI/GUI/Control.Bounds.cs +++ b/Source/Engine/UI/GUI/Control.Bounds.cs @@ -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); } /// @@ -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) diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs index ef3ee5f91..9a0c7b435 100644 --- a/Source/Engine/UI/GUI/Control.cs +++ b/Source/Engine/UI/GUI/Control.cs @@ -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 /// The converted point location in parent control coordinates. 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 /// The converted point location in control's space. 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; } diff --git a/Source/Engine/UI/GUI/Margin.cs b/Source/Engine/UI/GUI/Margin.cs index c19d06f09..ba30526fc 100644 --- a/Source/Engine/UI/GUI/Margin.cs +++ b/Source/Engine/UI/GUI/Margin.cs @@ -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); } /// @@ -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); } /// @@ -249,7 +249,7 @@ namespace FlaxEngine.GUI /// /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. - 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 are equal. /// [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); } /// @@ -274,7 +274,7 @@ namespace FlaxEngine.GUI [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Margin other) { - return Equals(ref other); + return Equals(in other); } /// @@ -284,7 +284,7 @@ namespace FlaxEngine.GUI /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Margin margin && Equals(ref margin); + return value is Margin margin && Equals(in margin); } } } diff --git a/Source/Engine/UI/GUI/Panels/DropPanel.cs b/Source/Engine/UI/GUI/Panels/DropPanel.cs index cb142f197..3fe17f42b 100644 --- a/Source/Engine/UI/GUI/Panels/DropPanel.cs +++ b/Source/Engine/UI/GUI/Panels/DropPanel.cs @@ -253,7 +253,7 @@ namespace FlaxEngine.GUI /// public override bool OnTestTooltipOverControl(ref Float2 location) { - return HeaderRectangle.Contains(ref location); + return HeaderRectangle.Contains(location); } /// @@ -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(); diff --git a/Source/Engine/UI/GUI/Panels/Panel.cs b/Source/Engine/UI/GUI/Panels/Panel.cs index 354613cdf..149dd8fd4 100644 --- a/Source/Engine/UI/GUI/Panels/Panel.cs +++ b/Source/Engine/UI/GUI/Panels/Panel.cs @@ -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; } diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 52222946e..dfe8ee05f 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -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(); diff --git a/Source/Engine/UI/GUI/Panels/ScrollBar.cs b/Source/Engine/UI/GUI/Panels/ScrollBar.cs index 756c698c5..5ca3982f4 100644 --- a/Source/Engine/UI/GUI/Panels/ScrollBar.cs +++ b/Source/Engine/UI/GUI/Panels/ScrollBar.cs @@ -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; diff --git a/Source/Engine/UI/GUI/Panels/TilesPanel.cs b/Source/Engine/UI/GUI/Panels/TilesPanel.cs index b295ca441..71ebca9fb 100644 --- a/Source/Engine/UI/GUI/Panels/TilesPanel.cs +++ b/Source/Engine/UI/GUI/Panels/TilesPanel.cs @@ -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(); diff --git a/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs b/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs index b8d59c4d7..9b4ca21b1 100644 --- a/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs +++ b/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs @@ -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(); diff --git a/Source/Engine/UI/UICanvas.cs b/Source/Engine/UI/UICanvas.cs index f385864f5..3a4c1aa14 100644 --- a/Source/Engine/UI/UICanvas.cs +++ b/Source/Engine/UI/UICanvas.cs @@ -79,11 +79,11 @@ namespace FlaxEngine // Calculate rendering matrix (world*view*projection) Canvas.GetWorldMatrix(renderContext.View.Origin, out Matrix worldMatrix); - Matrix.Multiply(ref worldMatrix, ref renderContext.View.View, out Matrix viewMatrix); + Matrix.Multiply(worldMatrix, renderContext.View.View, out Matrix viewMatrix); Matrix projectionMatrix = renderContext.View.Projection; if (worldSpace && (Canvas.RenderLocation == PostProcessEffectLocation.Default || Canvas.RenderLocation == PostProcessEffectLocation.AfterAntiAliasingPass)) projectionMatrix = renderContext.View.NonJitteredProjection; // Fix TAA jittering when rendering UI in world after TAA resolve - Matrix.Multiply(ref viewMatrix, ref projectionMatrix, out Matrix viewProjectionMatrix); + Matrix.Multiply(viewMatrix, projectionMatrix, out Matrix viewProjectionMatrix); // Pick a depth buffer GPUTexture depthBuffer = Canvas.IgnoreDepth ? null : renderContext.Buffers.DepthBuffer; @@ -344,7 +344,7 @@ namespace FlaxEngine }; GetWorldMatrix(out Matrix world); Matrix.Translation((float)bounds.Extents.X, (float)bounds.Extents.Y, 0, out Matrix offset); - Matrix.Multiply(ref offset, ref world, out var boxWorld); + Matrix.Multiply(offset, world, out var boxWorld); boxWorld.Decompose(out bounds.Transformation); return bounds; } @@ -385,19 +385,19 @@ namespace FlaxEngine { if (_renderMode == CanvasRenderMode.WorldSpace) { - Matrix.Transformation(ref transform.Scale, ref transform.Orientation, ref translation, out world); + Matrix.Transformation(transform.Scale, transform.Orientation, translation, out world); } else if (_renderMode == CanvasRenderMode.WorldSpaceFaceCamera) { var view = _editorTask.View; Matrix.Translation(_guiRoot.Width * -0.5f, _guiRoot.Height * -0.5f, 0, out var m1); - Matrix.Scaling(ref transform.Scale, out var m2); - Matrix.Multiply(ref m1, ref m2, out var m3); + Matrix.Scaling(transform.Scale, out var m2); + Matrix.Multiply(m1, m2, out var m3); Quaternion.Euler(180, 180, 0, out var quat); - Matrix.RotationQuaternion(ref quat, out m2); - Matrix.Multiply(ref m3, ref m2, out m1); + Matrix.RotationQuaternion(quat, out m2); + Matrix.Multiply(m3, m2, out m1); m2 = Matrix.Transformation(Float3.One, Quaternion.FromDirection(-view.Direction), translation); - Matrix.Multiply(ref m1, ref m2, out world); + Matrix.Multiply(m1, m2, out world); } else if (_renderMode == CanvasRenderMode.CameraSpace) { @@ -409,14 +409,14 @@ namespace FlaxEngine _guiRoot.Size = _editorTask.Viewport.Size; Matrix.Translation(_guiRoot.Width / -2.0f, _guiRoot.Height / -2.0f, 0, out world); Matrix.RotationYawPitchRoll(Mathf.Pi, Mathf.Pi, 0, out var tmp2); - Matrix.Multiply(ref world, ref tmp2, out var tmp1); + Matrix.Multiply(world, tmp2, out var tmp1); Float3 viewPos = view.Position - viewOrigin; var viewRot = view.Direction != Float3.Up ? Quaternion.LookRotation(view.Direction, Float3.Up) : Quaternion.LookRotation(view.Direction, Float3.Right); var viewUp = Float3.Up * viewRot; var viewForward = view.Direction; var pos = view.Position + view.Direction * Distance; - Matrix.Billboard(ref pos, ref viewPos, ref viewUp, ref viewForward, out tmp2); - Matrix.Multiply(ref tmp1, ref tmp2, out world); + Matrix.Billboard(pos, viewPos, viewUp, viewForward, out tmp2); + Matrix.Multiply(tmp1, tmp2, out world); return; } else @@ -433,19 +433,19 @@ namespace FlaxEngine if (_renderMode == CanvasRenderMode.WorldSpace || (_renderMode == CanvasRenderMode.WorldSpaceFaceCamera && !camera)) { // In 3D world - Matrix.Transformation(ref transform.Scale, ref transform.Orientation, ref translation, out world); + Matrix.Transformation(transform.Scale, transform.Orientation, translation, out world); } else if (_renderMode == CanvasRenderMode.WorldSpaceFaceCamera) { // In 3D world face camera Matrix.Translation(_guiRoot.Width * -0.5f, _guiRoot.Height * -0.5f, 0, out var m1); - Matrix.Scaling(ref transform.Scale, out var m2); - Matrix.Multiply(ref m1, ref m2, out var m3); + Matrix.Scaling(transform.Scale, out var m2); + Matrix.Multiply(m1, m2, out var m3); Quaternion.Euler(180, 180, 0, out var quat); - Matrix.RotationQuaternion(ref quat, out m2); - Matrix.Multiply(ref m3, ref m2, out m1); + Matrix.RotationQuaternion(quat, out m2); + Matrix.Multiply(m3, m2, out m1); m2 = Matrix.Transformation(Vector3.One, Quaternion.FromDirection(-camera.Direction), translation); - Matrix.Multiply(ref m1, ref m2, out world); + Matrix.Multiply(m1, m2, out world); } else if (_renderMode == CanvasRenderMode.CameraSpace && camera) { @@ -456,8 +456,8 @@ namespace FlaxEngine if (camera.UsePerspective) { camera.GetMatrices(out tmp1, out var tmp3, viewport); - Matrix.Multiply(ref tmp1, ref tmp3, out tmp2); - var frustum = new BoundingFrustum(ref tmp2); + Matrix.Multiply(tmp1, tmp3, out tmp2); + var frustum = new BoundingFrustum(tmp2); _guiRoot.Size = new Float2(frustum.GetWidthAtDepth(Distance), frustum.GetHeightAtDepth(Distance)); } else @@ -468,7 +468,7 @@ namespace FlaxEngine // Center viewport (and flip) Matrix.Translation(_guiRoot.Width / -2.0f, _guiRoot.Height / -2.0f, 0, out world); Matrix.RotationYawPitchRoll(Mathf.Pi, Mathf.Pi, 0, out tmp2); - Matrix.Multiply(ref world, ref tmp2, out tmp1); + Matrix.Multiply(world, tmp2, out tmp1); // In front of the camera Float3 viewPos = camera.Position - viewOrigin; @@ -476,9 +476,9 @@ namespace FlaxEngine var viewUp = Float3.Up * viewRot; var viewForward = Float3.Forward * viewRot; var pos = viewPos + viewForward * Distance; - Matrix.Billboard(ref pos, ref viewPos, ref viewUp, ref viewForward, out tmp2); + Matrix.Billboard(pos, viewPos, viewUp, viewForward, out tmp2); - Matrix.Multiply(ref tmp1, ref tmp2, out world); + Matrix.Multiply(tmp1, tmp2, out world); } else { diff --git a/Source/Engine/UI/UIControl.cs b/Source/Engine/UI/UIControl.cs index 89563a21a..ba2f38a47 100644 --- a/Source/Engine/UI/UIControl.cs +++ b/Source/Engine/UI/UIControl.cs @@ -137,7 +137,7 @@ namespace FlaxEngine }; canvasRoot.Canvas.GetWorldMatrix(out Matrix world); Matrix.Translation(min.X + size.X * 0.5f, min.Y + size.Y * 0.5f, 0, out Matrix offset); - Matrix.Multiply(ref offset, ref world, out var boxWorld); + Matrix.Multiply(offset, world, out var boxWorld); boxWorld.Decompose(out bounds.Transformation); return bounds; }