-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmoothCircleEq.cs
49 lines (38 loc) · 1.24 KB
/
SmoothCircleEq.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChromAber {
class SmoothCircleEq {
static readonly double[,] FILTER = new[,] {
{ 1.0/16, 2.0/16, 1.0/16 },
{ 2.0/16, 4.0/16, 2.0/16 },
{ 1.0/16, 2.0/16, 1.0/16 }
};
double
_centerX,
_centerY,
_radius;
public SmoothCircleEq(double centerX, double centerY, double radius) {
_centerX = centerX;
_centerY = centerY;
_radius = radius;
}
public double CalcBelongingScore(double x, double y) {
var result = 0.0;
for(var dx = -1; dx <= 1; dx++) {
for(var dy = -1; dy <= 1; dy++) {
var diffX = x + dx - _centerX;
var diffY = y + dy - _centerY;
var dist = Math.Sqrt(diffX * diffX + diffY * diffY);
if(dist <= _radius)
result += Math.Min(_radius - dist, 1) * FILTER[1 + dx, 1 + dy];
}
}
if(result < 0)
result = 0;
return result;
}
}
}