-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] add replacements for System.Numerics Vector3 / Quaternion #1638
Open
0x53A
wants to merge
25
commits into
fable-compiler:nagareyama
Choose a base branch
from
0x53A:replacement-system-numerics
base: nagareyama
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e1a48c6
add replacements for System.Numerics Vector3 / Quaternion
0x53A e074968
Merge branch 'master' into replacement-system-numerics
0x53A 33979c4
v3 / q use public fields, not properties
0x53A 04f4fc6
add transforms for ILFieldGet / ILFieldSet
0x53A 38fc343
ILFieldGet / Set
0x53A e5cf894
ILFieldGet
0x53A 64b2b57
add (hopefully) correct transforms for ILFieldGet / ILFieldSet
0x53A 7b472ed
oops
0x53A d402839
add tests for field read / write
0x53A d8387b8
merge from master
0x53A 6b0db68
minor comment
0x53A 31fbbbc
adapt to rename fable-core => fable-library
0x53A 8271537
implement some more members of Vector3
0x53A 7dc6c31
wip comments
0x53A c3733e5
merge from upstream/master
0x53A c6a5b3a
fable-library was moved
0x53A 1e3a33d
Vector3.ToString
0x53A ee4e1d2
Merge remote-tracking branch 'upstream/master' into replacement-syste…
0x53A 2cef223
Fable.Tests: add PackageReference to System.Numerics.Vectors
0x53A 444a9c6
add support for nested "testList", fixes https://github.com/fable-com…
0x53A 250c63e
add equality tests
0x53A 0d4cfc1
override equality and comparison for Vector3
0x53A 1b928ca
split file into Vector3.fs and Quaternion.fs
0x53A 5c27ea2
add missing cases to transformTypeInfo
0x53A 50aa0a9
Revert "split file into Vector3.fs and Quaternion.fs"
0x53A File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
namespace System.Numerics | ||
|
||
// contains the types Vector3 and Quaternion. | ||
// feel free to add the rest as required | ||
|
||
|
||
|
||
type Vector3 = | ||
struct | ||
|
||
val mutable public X : single | ||
val mutable public Y : single | ||
val mutable public Z : single | ||
|
||
new (value : single) = { X = value; Y = value; Z = value } | ||
new (x : single, y : single, z : single) = { X = x; Y = y; Z = z } | ||
|
||
member this.Abs() = Vector3(System.Math.Abs(this.X), System.Math.Abs(this.Y), System.Math.Abs(this.Z)) | ||
|
||
member this.CopyTo(arr : single array, index : int) = | ||
arr.[index + 0] <- this.X | ||
arr.[index + 1] <- this.Y | ||
arr.[index + 2] <- this.Z | ||
|
||
member this.CopyTo(arr : single array) = this.CopyTo(arr, 0) | ||
|
||
//member __.Equals(other : Vector3) = | ||
// x = other.X && | ||
// y = other.Y && | ||
// z = other.Z | ||
|
||
//override this.Equals(other : obj) = | ||
// match other with | ||
// | :? Vector3 as vother -> | ||
// this.Equals(vother) | ||
// | _ -> false | ||
|
||
//override __.GetHashCode() = | ||
// hash(x, y, z) | ||
|
||
|
||
// -------------------------------- | ||
// Static members of Vector3 | ||
|
||
static member One = Vector3(1.f, 1.f, 1.f) | ||
|
||
static member UnitX = Vector3(1.f, 0.f, 0.f) | ||
static member UnitY = Vector3(0.f, 1.f, 0.f) | ||
static member UnitZ = Vector3(0.f, 0.f, 1.f) | ||
|
||
static member Zero = Vector3(0.f, 0.f, 0.f) | ||
|
||
static member Add(left : Vector3, right : Vector3) = | ||
Vector3(left.X + right.X, left.Y + right.Y, left.Z + right.Z) | ||
|
||
static member Divide(left : Vector3, right : Vector3) = | ||
Vector3(left.X / right.X, left.Y / right.Y, left.Z / right.Z) | ||
|
||
static member Divide(left : Vector3, right : single) = | ||
Vector3(left.X / right, left.Y / right, left.Z / right) | ||
|
||
static member Clamp(value : Vector3, min : Vector3, max : Vector3) = | ||
let inline clamp v min max = | ||
if v < min then min | ||
else if v > max then max | ||
else v | ||
Vector3(clamp value.X min.X max.X, | ||
clamp value.Y min.Y max.Y, | ||
clamp value.Z min.Z max.Z) | ||
|
||
static member Cross(vector1 : Vector3, vector2 : Vector3) = | ||
Vector3(vector1.Y * vector2.Z - vector1.Z * vector2.Y, | ||
vector1.Z * vector2.X - vector1.X * vector2.Z, | ||
vector1.X * vector2.Y - vector1.Y * vector2.X) | ||
|
||
static member Distance(value1 : Vector3, value2 : Vector3) : single = | ||
let num2 = value1.X - value2.X | ||
let num3 = value1.Y - value2.Y | ||
let num4 = value1.Z - value2.Z | ||
let num5 = num2 * num2 + num3 * num3 + num4 * num4; | ||
single ( System.Math.Sqrt(float num5) ) | ||
|
||
static member DistanceSquared(value1 : Vector3, value2 : Vector3) : single = | ||
let num2 = value1.X - value2.X | ||
let num3 = value1.Y - value2.Y | ||
let num4 = value1.Z - value2.Z | ||
let num5 = num2 * num2 + num3 * num3 + num4 * num4; | ||
num5 | ||
|
||
|
||
// -------------------------------- | ||
// Operators of Vector3 | ||
|
||
static member (+) (left:Vector3, right:Vector3) : Vector3 = | ||
Vector3.Add(left, right) | ||
|
||
static member (/) (left:Vector3, right:Vector3) : Vector3 = | ||
Vector3.Divide(left, right) | ||
|
||
static member (/) (left:Vector3, right:single) : Vector3 = | ||
Vector3.Divide(left, right) | ||
end | ||
|
||
type Quaternion = | ||
struct | ||
|
||
val mutable public X : single | ||
val mutable public Y : single | ||
val mutable public Z : single | ||
val mutable public W : single | ||
|
||
new (x : single, y : single, z : single, w : single) = { X = x; Y = y; Z = z; W = w } | ||
new(vectorPart : Vector3, scalarPart : single) = | ||
Quaternion(vectorPart.X, vectorPart.Y, vectorPart.Z, scalarPart) | ||
|
||
member this.IsIdentity = | ||
this.X = 0.f && | ||
this.Y = 0.f && | ||
this.Z = 0.f && | ||
this.W = 1.f | ||
|
||
member this.Length() : single = | ||
let ls = this.LengthSquared() | ||
single ( System.Math.Sqrt(float ls) ) | ||
|
||
member this.LengthSquared() : single = | ||
this.X * this.X + this.Y * this.Y + this.Z * this.Z + this.W * this.W | ||
|
||
|
||
// -------------------------------- | ||
// static members of Quaternion | ||
|
||
static member Identity = Quaternion(0.f, 0.f, 0.f, 1.f) | ||
|
||
static member Add(value1 : Quaternion, value2 : Quaternion) = | ||
Quaternion( | ||
value1.X + value2.X, | ||
value1.Y + value2.Y, | ||
value1.Z + value2.Z, | ||
value1.W + value2.W | ||
) | ||
|
||
static member Concatenate(value1 : Quaternion, value2 : Quaternion) = | ||
let x = value2.X; | ||
let y = value2.Y; | ||
let z = value2.Z; | ||
let w = value2.W; | ||
let x2 = value1.X; | ||
let y2 = value1.Y; | ||
let z2 = value1.Z; | ||
let w2 = value1.W; | ||
let num = y * z2 - z * y2; | ||
let num2 = z * x2 - x * z2; | ||
let num3 = x * y2 - y * x2; | ||
let num4 = x * x2 + y * y2 + z * z2; | ||
Quaternion( | ||
x * w2 + x2 * w + num, | ||
y * w2 + y2 * w + num2, | ||
z * w2 + z2 * w + num3, | ||
w * w2 - num4 | ||
) | ||
|
||
static member Conjugate(value : Quaternion) = | ||
Quaternion( | ||
0.f - value.X, | ||
0.f - value.Y, | ||
0.f - value.Z, | ||
value.W | ||
) | ||
|
||
static member Divide(value1 : Quaternion, value2 : Quaternion) = | ||
let x = value1.X; | ||
let y = value1.Y; | ||
let z = value1.Z; | ||
let w = value1.W; | ||
let num = value2.X * value2.X + value2.Y * value2.Y + value2.Z * value2.Z + value2.W * value2.W; | ||
let num2 = 1.f / num; | ||
let num3 = (0.f - value2.X) * num2; | ||
let num4 = (0.f - value2.Y) * num2; | ||
let num5 = (0.f - value2.Z) * num2; | ||
let num6 = value2.W * num2; | ||
let num7 = y * num5 - z * num4; | ||
let num8 = z * num3 - x * num5; | ||
let num9 = x * num4 - y * num3; | ||
let num10 = x * num3 + y * num4 + z * num5; | ||
Quaternion( | ||
x * num6 + num3 * w + num7, | ||
y * num6 + num4 * w + num8, | ||
z * num6 + num5 * w + num9, | ||
w * num6 - num10 | ||
) | ||
|
||
static member Dot(quaternion1 : Quaternion, quaternion2 : Quaternion) : single = | ||
quaternion1.X * quaternion2.X + quaternion1.Y * quaternion2.Y + quaternion1.Z * quaternion2.Z + quaternion1.W * quaternion2.W | ||
|
||
static member Inverse(value : Quaternion) : Quaternion = | ||
let num = value.X * value.X + value.Y * value.Y + value.Z * value.Z + value.W * value.W; | ||
let num2 = 1.f / num; | ||
Quaternion( | ||
(0.f - value.X) * num2, | ||
(0.f - value.Y) * num2, | ||
(0.f - value.Z) * num2, | ||
value.W * num2 | ||
) | ||
|
||
static member Multiply(value1 : Quaternion, value2 : Quaternion) : Quaternion = | ||
let x = value1.X; | ||
let y = value1.Y; | ||
let z = value1.Z; | ||
let w = value1.W; | ||
let x2 = value2.X; | ||
let y2 = value2.Y; | ||
let z2 = value2.Z; | ||
let w2 = value2.W; | ||
let num = y * z2 - z * y2; | ||
let num2 = z * x2 - x * z2; | ||
let num3 = x * y2 - y * x2; | ||
let num4 = x * x2 + y * y2 + z * z2; | ||
Quaternion( | ||
x * w2 + x2 * w + num, | ||
y * w2 + y2 * w + num2, | ||
z * w2 + z2 * w + num3, | ||
w * w2 - num4 | ||
) | ||
|
||
static member Multiply(value1 : Quaternion, value2 : single) : Quaternion = | ||
Quaternion( | ||
value1.X * value2, | ||
value1.Y * value2, | ||
value1.Z * value2, | ||
value1.W * value2 | ||
) | ||
|
||
|
||
// -------------------------------- | ||
// Operators of Quaternion | ||
|
||
static member (+) (left:Quaternion, right:Quaternion) : Quaternion = | ||
Quaternion.Add(left, right) | ||
|
||
static member (/) (left:Quaternion, right:Quaternion) : Quaternion = | ||
Quaternion.Divide(left, right) | ||
|
||
static member (*) (left:Quaternion, right:Quaternion) : Quaternion = | ||
Quaternion.Multiply(left, right) | ||
|
||
static member (*) (left:Quaternion, right:single) : Quaternion = | ||
Quaternion.Multiply(left, right) | ||
|
||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just use
let! callee = transformExpr com ctx callee
(same below for ILFieldSet).