Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Operand ambiguity occurs when referencing built-in Vector types via arithmetic and comparison operators

オープン
#177 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp, unity

調査の方向性

まず、VectorX と floatX の型定義、および既存の変換と演算子の実装を見つけます。Input.mousePosition と float3 の例を再現し、関連する算術式と比較式が曖昧さなく解決され、意図した Unity.Mathematics の結果型を生成することを確認します。

索引モデルが issue の本文から書いたものです。

説明

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.mousePosition is a unity built-in property or field, so its type is Vector3
  • There are no explicit arithmetic operator implementations for VectorX types and floatX types.

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;
主要言語
C#
スター
1.4k
フォーク
159
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Unity-Technologies/Unity.Mathematics のほかの issue

Unity-Technologies/Unity.Mathematics の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。