-
Notifications
You must be signed in to change notification settings - Fork 0
/
NLocateSet.cs
59 lines (54 loc) · 1.45 KB
/
NLocateSet.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Nixlib.Dungeon {
public class NLocateSet
{
public List<NLocate> Set = new List<NLocate>();
public double DistanceTo(NLocateSet set, out NLocate srcLoc, out NLocate dstLoc)
{
double min = double.MaxValue;
srcLoc = new NLocate(0, 0);
dstLoc = new NLocate(0, 0);
foreach(var l in set.Set)
{
NLocate nearestLoc;
var dis = DistanceTo(l,out nearestLoc);
if (dis < min)
{
min = dis;
srcLoc = nearestLoc;
dstLoc = l;
}
}
return min;
}
public double DistanceTo(NLocate loc, out NLocate nearestLoc)
{
double min = double.MaxValue;
nearestLoc = loc;
foreach (var l in Set)
{
var dis = l.DistanceTo(loc);
if (dis < min)
{
min = dis;
nearestLoc = l;
}
}
return min;
}
public void Fill(NMap map, byte val)
{
foreach( var l in Set)
{
map.SetBlock(l.X, l.Y, val);
}
}
public int AreaSize()
{
return Set.Count;
}
}
}