回答編集履歴
3
記述微修正
answer
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
int distance = Math.Abs( target.Location.x - datas[i].Location.x ) + Math.Abs( target.Location.z - datas[i].Location.z );
|
43
43
|
```
|
44
44
|
|
45
|
-
こんな感じ
|
45
|
+
こんな感じ↓のを対象の型に合わせて毎度書けば一番近いやつを得られるようにも思いますが…
|
46
46
|
|
47
47
|
```CSharp
|
48
48
|
//targetからの距離でソートして先頭に来たやつを得る
|
2
タプルな形を追記
answer
CHANGED
@@ -21,4 +21,32 @@
|
|
21
21
|
}
|
22
22
|
```
|
23
23
|
|
24
|
-
みたいな感じでどうでしょうか.
|
24
|
+
みたいな感じでどうでしょうか.
|
25
|
+
|
26
|
+
---
|
27
|
+
|
28
|
+
> タプル
|
29
|
+
|
30
|
+
という話をちゃんと読めていなかった……
|
31
|
+
↓
|
32
|
+
素人たる私にはそのタプルを特定の名称で得るための interface を用意するくらいしか方法がわかりませぬ.
|
33
|
+
|
34
|
+
```CSharp
|
35
|
+
//タプルを Location なる名称で得るためのinterface
|
36
|
+
interface IVertex
|
37
|
+
{
|
38
|
+
(int x, int y, int z ) Location { get; }
|
39
|
+
}
|
40
|
+
|
41
|
+
//※NearestDataの実装において,Locationという名前を使う
|
42
|
+
int distance = Math.Abs( target.Location.x - datas[i].Location.x ) + Math.Abs( target.Location.z - datas[i].Location.z );
|
43
|
+
```
|
44
|
+
|
45
|
+
こんな感じで対象の型に合わせて毎度書けば一番近いやつを得られるようにも思いますが…
|
46
|
+
|
47
|
+
```CSharp
|
48
|
+
//targetからの距離でソートして先頭に来たやつを得る
|
49
|
+
var Nearest =
|
50
|
+
routeDatas.Select( rv => { return ( rv, Math.Abs(rv.Vertex.x - target.Position.x) + Math.Abs(rv.Vertex.z - target.Position.z) ); } )
|
51
|
+
.OrderBy( data=>data.Item2 ).First().Item1;
|
52
|
+
```
|
1
何か static って書いてたのを削除
answer
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
double z{ get; }
|
14
14
|
}
|
15
15
|
|
16
|
-
|
16
|
+
private T NearestData<T, T2>(T[] datas, T2 target)
|
17
17
|
where T : class,IVector //nullについてはclassで?
|
18
18
|
where T2 : IVector
|
19
19
|
{
|