File tree Expand file tree Collapse file tree 5 files changed +74
-11
lines changed Expand file tree Collapse file tree 5 files changed +74
-11
lines changed Original file line number Diff line number Diff line change @@ -98,11 +98,24 @@ public Box2D<T> GetTranslated(Vector2D<T> distance)
98
98
/// <returns>The calculated box.</returns>
99
99
public Box2D < T > GetScaled ( Vector2D < T > scale , Vector2D < T > anchor )
100
100
{
101
- var min = ( scale * ( Min - anchor ) ) + Min ;
102
- var max = ( scale * ( Max - anchor ) ) + Max ;
101
+ var min = ( scale * ( Min - anchor ) ) + anchor ;
102
+ var max = ( scale * ( Max - anchor ) ) + anchor ;
103
103
return new ( min , max ) ;
104
104
}
105
105
106
+ /// <summary>
107
+ /// Calculates a new box scaled by the given scale around the given anchor.
108
+ /// </summary>
109
+ /// <param name="scale">The scale.</param>
110
+ /// <param name="anchor">The anchor.</param>
111
+ /// <typeparam name="TScale">The type of the scale.</typeparam>
112
+ /// <returns>The calculated box.</returns>
113
+ public Box2D < T > GetScaled < TScale > ( Vector2D < TScale > scale , Vector2D < T > anchor )
114
+ where TScale : unmanaged, IFormattable , IEquatable < TScale > , IComparable < TScale >
115
+ {
116
+ return this . As < TScale > ( ) . GetScaled ( scale , anchor . As < TScale > ( ) ) . As < T > ( ) ;
117
+ }
118
+
106
119
/// <summary>
107
120
/// Calculates a box inflated to contain the given point.
108
121
/// </summary>
Original file line number Diff line number Diff line change @@ -103,10 +103,26 @@ public Box3D<T> GetTranslated(Vector3D<T> distance)
103
103
/// <returns>The calculated box.</returns>
104
104
public Box3D < T > GetScaled ( Vector3D < T > scale , Vector3D < T > anchor )
105
105
{
106
- var min = ( scale * ( Min - anchor ) ) + Min ;
107
- var max = ( scale * ( Max - anchor ) ) + Max ;
106
+ var min = ( scale * ( Min - anchor ) ) + anchor ;
107
+ var max = ( scale * ( Max - anchor ) ) + anchor ;
108
108
return new ( min , max ) ;
109
109
}
110
+
111
+ /// <summary>
112
+ /// Calculates a new box scaled by the given scale around the given anchor.
113
+ /// </summary>
114
+ /// <typeparam name="TScale">The type of the scale.</typeparam>
115
+ /// <param name="scale">The scale.</param>
116
+ /// <param name="anchor">The anchor.</param>
117
+ /// <returns>The calculated box.</returns>
118
+ public Box3D < T > GetScaled < TScale > ( Vector3D < TScale > scale , Vector3D < T > anchor )
119
+ where TScale : unmanaged, IFormattable , IEquatable < TScale > , IComparable < TScale >
120
+ {
121
+ var convertedAnchor = anchor . As < TScale > ( ) ;
122
+ var min = ( scale * ( Min . As < TScale > ( ) - convertedAnchor ) ) + convertedAnchor ;
123
+ var max = ( scale * ( Max . As < TScale > ( ) - convertedAnchor ) ) + convertedAnchor ;
124
+ return new Box3D < T > ( min . As < T > ( ) , max . As < T > ( ) ) ;
125
+ }
110
126
111
127
/// <summary>
112
128
/// Calculates a box inflated to contain the given point.
Original file line number Diff line number Diff line change @@ -115,11 +115,26 @@ public Cube<T> GetTranslated(Vector3D<T> distance)
115
115
/// <returns>The calculated cube.</returns>
116
116
public Cube < T > GetScaled ( Vector3D < T > scale , Vector3D < T > anchor )
117
117
{
118
- var origMax = Max ;
119
- var min = ( scale * ( Origin - anchor ) ) + Origin ;
120
- var max = ( scale * ( origMax - anchor ) ) + origMax ;
118
+ var min = ( scale * ( Origin - anchor ) ) + anchor ;
119
+ var max = ( scale * ( Max - anchor ) ) + anchor ;
121
120
return new ( min , max - min ) ;
122
121
}
122
+
123
+ /// <summary>
124
+ /// Calculates a new cube scaled by the given scale around the given anchor.
125
+ /// </summary>
126
+ /// <typeparam name="TScale">The type of the scale.</typeparam>
127
+ /// <param name="scale">The scale.</param>
128
+ /// <param name="anchor">The anchor.</param>
129
+ /// <returns>The calculated cube.</returns>
130
+ public Cube < T > GetScaled < TScale > ( Vector3D < TScale > scale , Vector3D < T > anchor )
131
+ where TScale : unmanaged, IFormattable , IEquatable < TScale > , IComparable < TScale >
132
+ {
133
+ var convertedAnchor = anchor . As < TScale > ( ) ;
134
+ var min = ( scale * ( Origin . As < TScale > ( ) - convertedAnchor ) ) + convertedAnchor ;
135
+ var max = ( scale * ( Max . As < TScale > ( ) - convertedAnchor ) ) + convertedAnchor ;
136
+ return new ( min . As < T > ( ) , ( max - min ) . As < T > ( ) ) ;
137
+ }
123
138
124
139
/// <summary>
125
140
/// Calculates a cube inflated to contain the given point.
Original file line number Diff line number Diff line change @@ -20,4 +20,8 @@ Silk.NET.Maths.Rectangle<T>.As<TOther>() -> Silk.NET.Maths.Rectangle<TOther>
20
20
Silk.NET.Maths.Sphere<T>.As<TOther>() -> Silk.NET.Maths.Sphere<TOther>
21
21
Silk.NET.Maths.Vector2D<T>.As<TOther>() -> Silk.NET.Maths.Vector2D<TOther>
22
22
Silk.NET.Maths.Vector3D<T>.As<TOther>() -> Silk.NET.Maths.Vector3D<TOther>
23
- Silk.NET.Maths.Vector4D<T>.As<TOther>() -> Silk.NET.Maths.Vector4D<TOther>
23
+ Silk.NET.Maths.Vector4D<T>.As<TOther>() -> Silk.NET.Maths.Vector4D<TOther>
24
+ Silk.NET.Maths.Box2D<T>.GetScaled<TScale>(Silk.NET.Maths.Vector2D<TScale> scale, Silk.NET.Maths.Vector2D<T> anchor) -> Silk.NET.Maths.Box2D<T>
25
+ Silk.NET.Maths.Box3D<T>.GetScaled<TScale>(Silk.NET.Maths.Vector3D<TScale> scale, Silk.NET.Maths.Vector3D<T> anchor) -> Silk.NET.Maths.Box3D<T>
26
+ Silk.NET.Maths.Rectangle<T>.GetScaled<TScale>(Silk.NET.Maths.Vector2D<TScale> scale, Silk.NET.Maths.Vector2D<T> anchor) -> Silk.NET.Maths.Rectangle<T>
27
+ Silk.NET.Maths.Cube<T>.GetScaled<TScale>(Silk.NET.Maths.Vector3D<TScale> scale, Silk.NET.Maths.Vector3D<T> anchor) -> Silk.NET.Maths.Cube<T>
Original file line number Diff line number Diff line change @@ -111,11 +111,26 @@ public Rectangle<T> GetTranslated(Vector2D<T> distance)
111
111
/// <returns>The calculated rectangle.</returns>
112
112
public Rectangle < T > GetScaled ( Vector2D < T > scale , Vector2D < T > anchor )
113
113
{
114
- var origMax = Max ;
115
- var min = ( scale * ( Origin - anchor ) ) + Origin ;
116
- var max = ( scale * ( origMax - anchor ) ) + origMax ;
114
+ var min = ( scale * ( Origin - anchor ) ) + anchor ;
115
+ var max = ( scale * ( Max - anchor ) ) + anchor ;
117
116
return new ( min , max - min ) ;
118
117
}
118
+
119
+ /// <summary>
120
+ /// Calculates a new rectangle scaled by the given scale around the given anchor.
121
+ /// </summary>
122
+ /// <typeparam name="TScale">The type of the scale.</typeparam>
123
+ /// <param name="scale">The scale.</param>
124
+ /// <param name="anchor">The anchor.</param>
125
+ /// <returns>The calculated rectangle.</returns>
126
+ public Rectangle < T > GetScaled < TScale > ( Vector2D < TScale > scale , Vector2D < T > anchor )
127
+ where TScale : unmanaged, IFormattable , IEquatable < TScale > , IComparable < TScale >
128
+ {
129
+ var convertedAnchor = anchor . As < TScale > ( ) ;
130
+ var min = ( scale * ( Origin . As < TScale > ( ) - convertedAnchor ) ) + convertedAnchor ;
131
+ var max = ( scale * ( Max . As < TScale > ( ) - convertedAnchor ) ) + convertedAnchor ;
132
+ return new ( min . As < T > ( ) , ( max - min ) . As < T > ( ) ) ;
133
+ }
119
134
120
135
/// <summary>
121
136
/// Calculates a rectangle inflated to contain the given point.
You can’t perform that action at this time.
0 commit comments