Operand ambiguity occurs when referencing built-in Vector types via arithmetic and comparison operators
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- csharp, unity
- Lĩnh vực
- computer-graphics
Hướng nghiên cứu
Bắt đầu bằng cách xác định các định nghĩa kiểu VectorX và floatX cùng các triển khai chuyển đổi và toán tử hiện có của chúng. Tái hiện ví dụ về Input.mousePosition và float3, sau đó xác minh rằng các biểu thức số học và so sánh liên quan được phân giải không mơ hồ và tạo ra kiểu kết quả Unity.Mathematics mong muốn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Given the following code snip:
static float3 lastMouseSpinViewPos;
var delta = Input.mousePosition - lastMouseSpinViewPos;
The following compiler error occurs:
Operator '-' is ambiguous on operands of type 'Vector3' and 'float3'
The reason is that the compiler doesn't know if it should implicitly convert the first operand to float3, or implicitly convert the second operand to Vector3.
Expected Behavior
My expectation is that Unity.Mathematics types should assume priority in this case: the first operand is converted to float3 and the result type is a float3. I'm not sure if there's a valid case for expecting behavior favoring Vector3, and if there were, it could be achieved by using explicit (Vector3) cast or type definition. Seeking a legacy Vector3 result is an edge case and is well-suited to be delegated to an explicit cast condition.
Cause of Problem
Input.mousePositionis a unity built-in property or field, so its type isVector3- There are no explicit arithmetic operator implementations for
VectorXtypes andfloatXtypes.
Proposed solution
For the sake of streamlining interoperability with Unity built-in class Vector types, I think it makes sense to provide explicit implementations of arithmetic and comparison operators, like so:
public static float3 operator +(Vector3 l, float3 r) { return (float3)l + r; }
public static float3 operator -(Vector3 l, float3 r) { return (float3)l - r; }
public static float3 operator +(float3 l, Vector3 r) { return l + (float3)r; }
public static float3 operator -(float3 l, Vector3 r) { return l - (float3)r; }
Workaround
Add explicit typecast in all situations, like so:
static float3 lastMouseSpinViewPos;
var delta = (float3)Input.mousePosition - lastMouseSpinViewPos;
- Ngôn ngữ chính
- C#
- Star
- 1.4k
- Fork
- 159
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Unity-Technologies/Unity.Mathematics
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
-
64 Bit Quaternion Request Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Unity-Technologies/Unity.Mathematics#245 · 3 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
Unity-Technologies/Unity.Mathematics#243 · 6 reaction ·
Tất cả issue của Unity-Technologies/Unity.Mathematics
Issue tương tự
-
effort:S P3 refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
nightscout/nocturne#1532 ·
-
core dependencies
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
C#/.NET Roslyn LSP Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Suspicious code fragments Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
DotNetNext/SqlSugar#1458 ·