forked from gradientspace/geometry3Sharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFalloffFunctions.cs
81 lines (63 loc) · 2.01 KB
/
FalloffFunctions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Ryan Schmidt (rms@gradientspace.com) - All Rights Reserved
// Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using g3;
namespace gs
{
public interface IFalloffFunction
{
/// <summary>
/// t is value in range [0,1], returns value in range [0,1]
/// </summary>
double FalloffT(double t);
/// <summary>
/// In most cases, users of IFalloffFunction will make a local copy
/// </summary>
IFalloffFunction Duplicate();
}
/// <summary>
/// returns 1 in range [0,ConstantRange], and then falls off to 0 in range [ConstantRange,1]
/// </summary>
public class LinearFalloff : IFalloffFunction
{
public double ConstantRange = 0;
public double FalloffT(double t)
{
t = MathUtil.Clamp(t, 0.0, 1.0);
if (ConstantRange <= 0)
return 1.0 - t;
else
return (t < ConstantRange) ? 1.0 : 1.0 - ((t - ConstantRange) / (1 - ConstantRange));
}
public IFalloffFunction Duplicate()
{
return new WyvillFalloff() {
ConstantRange = this.ConstantRange
};
}
}
/// <summary>
/// returns 1 in range [0,ConstantRange], and then falls off to 0 in range [ConstantRange,1]
/// </summary>
public class WyvillFalloff : IFalloffFunction
{
public double ConstantRange = 0;
public double FalloffT(double t)
{
t = MathUtil.Clamp(t, 0.0, 1.0);
if (ConstantRange <= 0)
return MathUtil.WyvillFalloff01(t);
else
return MathUtil.WyvillFalloff(t, ConstantRange, 1.0);
}
public IFalloffFunction Duplicate()
{
return new WyvillFalloff() {
ConstantRange = this.ConstantRange
};
}
}
}