-
Notifications
You must be signed in to change notification settings - Fork 53
/
Utilities.cs
827 lines (712 loc) · 28.3 KB
/
Utilities.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
// Copyright (c) 2016 Framefield. All rights reserved.
// Released under the MIT license. (see LICENSE.txt)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics;
using SharpDX;
namespace Framefield.Core
{
public static class Utilities
{
public class ValueFunction : OperatorPart.Function
{
public event EventHandler<EventArgs> EvaluatedEvent;
// a value function has no parent because multiple operatorparts can share one instance
public override OperatorPart OperatorPart { get { return null; } set { } }
public IValue Value
{
get { return _value; }
set {
_value = value;
TriggerChangedEvent(EventArgs.Empty);
}
}
public override OperatorPart.Function Clone()
{
var newFunc = CreateValueFunction(Value);
newFunc.OperatorPart = OperatorPart;
return newFunc;
}
public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)
{
if (!Value.Cacheable || Changed)
{
if (inputs.Count > 0)
{
//regardless what we get as outputidx, we need to pass our evaluationidx for evaluating our input
inputs[0].Eval(context, EvaluationIndex);
Value.SetValueFromContext(context);
}
else
Value.SetValueInContext(context);
Changed = false;
}
else
{
Value.SetValueInContext(context);
}
if (EvaluatedEvent != null)
EvaluatedEvent(this, EventArgs.Empty);
return context;
}
private IValue _value;
}
public class DefaultValueFunction : ValueFunction
{
public override OperatorPart.Function Clone()
{
//only one instance exists of a default value function
return this;
}
public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)
{
Value.SetValueInContext(context);
Changed = false;
return context;
}
}
public static OperatorPart.Function CreateValueFunction(IValue value)
{
var valueFunction = new ValueFunction();
valueFunction.Value = value.Clone();
return valueFunction;
}
public static DefaultValueFunction CreateDefaultValueFunction(IValue value)
{
var valueFunction = new DefaultValueFunction();
valueFunction.Value = value.Clone();
return valueFunction;
}
public static OperatorPart CreateValueOpPart(Guid id, ValueFunction defaultFunction, bool isMultiInput)
{
return new OperatorPart(id, defaultFunction) { Type = defaultFunction.Value.Type, IsMultiInput = isMultiInput };
}
public static Operator CreateEmptyOperator()
{
var metaOp = new MetaOperator(Guid.NewGuid()) { Name = "Empty" };
return metaOp.CreateOperator(Guid.NewGuid());
}
public static void RemoveAllEventHandlerFrom<T>(T instance) where T : class
{
var type = instance.GetType();
foreach (var eventInfo in type.GetEvents())
{
var eventFieldInfo = type.GetField(eventInfo.Name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField);
if (eventFieldInfo == null)
continue;
var eventFieldValue = (Delegate) eventFieldInfo.GetValue(instance);
if (eventFieldValue == null)
continue;
var invocationList = eventFieldValue.GetInvocationList();
for (int i = 0; i < invocationList.Count(); ++i)
{
eventInfo.RemoveEventHandler(instance, eventFieldValue);
}
}
}
public static IEnumerable<MethodInfo> GetSubscribedMethods<T>(T instance) where T : class
{
return from eventInfo in instance.GetType().GetEvents()
let eventFieldInfo = instance.GetType().GetField(eventInfo.Name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField)
let eventFieldValue = (Delegate)eventFieldInfo.GetValue(instance)
from subscribedDelegate in eventFieldValue.GetInvocationList()
select subscribedDelegate.Method;
}
public static IEnumerable<Tuple<Assembly, Type[]>> GetAssembliesAndTypesOfCurrentDomain()
{
var asmAndTypes = new List<Tuple<Assembly, Type[]>>();
try
{
var currentDomainAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var asm in currentDomainAssemblies)
{
try
{
asmAndTypes.Add(Tuple.Create(asm, asm.GetTypes()));
}
catch (ReflectionTypeLoadException)
{
//Logger.Debug("Could not load assembly {0} in order to get its types.", asm.FullName);
}
}
}
catch (AppDomainUnloadedException exception)
{
Logger.Error("Error getting assemblies of current domain: {0} - {1}", exception.Message, exception.InnerException);
}
return asmAndTypes;
}
public static IEnumerable<T> GetValues<T>()
{
return Enum.GetValues(typeof(T)).Cast<T>();
}
public static bool IsEqual(float lhs, float rhs, float epsilon = 0.001f)
{
return Math.Abs(lhs - rhs) < epsilon;
}
public static void Swap<T>(ref T lhs, ref T rhs)
{
T temp = lhs;
lhs = rhs;
rhs = temp;
}
public static T Clamp<T>(T val, T min, T max) where T : IComparable<T>
{
return (val.CompareTo(min) < 0) ? min
: (val.CompareTo(max) > 0) ? max
: val;
}
public static void MemSet<T>(T[] array, T value)
{
for (int i = 0; i < array.Length; ++i)
{
array[i] = value;
}
}
public static float SmoothStep(float t)
{
return t*t*t*(t*(t*6 - 15) + 10);
}
public static double getAngleDifference(double a1, double a2)
{
var d = Math.Abs(a1 - a2);
return d > 180 ? 360 - d : d;
}
// t within [0, 1]
public static float Lerp(float a, float b, float t)
{
return a*(1.0f - t) + b*t;
}
public static string CharAtToUpper(string text, int index)
{
return CharAtTo(text, index, t => t.ToUpper());
}
public static string CharAtToLower(string text, int index)
{
return CharAtTo(text, index, t => t.ToLower());
}
private static string CharAtTo(string text, int index, Func<string, string> charManipulator)
{
if ((index < 0) || (index >= text.Length))
return text;
var nextChar = text.Substring(index, 1);
text = text.Remove(index, 1);
return text.Insert(index, charManipulator(nextChar));
}
public static T FromString<T>(string text)
{
return (T) TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(text);
}
public static double RadToDegree(double rad)
{
return rad*180.0/Math.PI;
}
public static double DegreeToRad(double degree)
{
return degree*Math.PI/180.0;
}
public static void DisposeObj<T>(ref T obj) where T : class, IDisposable
{
if (obj != null)
{
obj.Dispose();
obj = null;
}
}
public static void CollectAllMetaOperators(this OperatorPart operatorPart, HashSet<MetaOperator> collectedMetaOperators)
{
var collectedOperators = new HashSet<Operator>();
CollectAllOperators(operatorPart, collectedOperators);
foreach (var op in collectedOperators)
{
collectedMetaOperators.Add(op.Definition);
}
}
public static void CollectAllOperators(this OperatorPart operatorPart, HashSet<Operator> collectedOperators)
{
var op = operatorPart.Parent;
if (!collectedOperators.Contains(op))
{
// new op, add
collectedOperators.Add(op);
var outputsToTraverse = from internalOp in op.InternalOps
from output in internalOp.Outputs
select output;
foreach (var output in outputsToTraverse)
{
output.CollectAllOperators(collectedOperators);
}
}
foreach (var opPart in operatorPart.Connections)
{
if (!collectedOperators.Contains(opPart.Parent))
opPart.CollectAllOperators(collectedOperators);
}
}
public static void CopyDirectory(string sourcePath, string destPath, string searchPattern)
{
if (!Directory.Exists(destPath))
{
Directory.CreateDirectory(destPath);
}
foreach (string file in Directory.GetFiles(sourcePath, searchPattern))
{
string dest = Path.Combine(destPath, Path.GetFileName(file));
File.Copy(file, dest);
}
foreach (string folder in Directory.GetDirectories(sourcePath, searchPattern))
{
string dest = Path.Combine(destPath, Path.GetFileName(folder));
CopyDirectory(folder, dest, searchPattern);
}
}
public static Vector3 ToVector3(this Vector4 vec)
{
return new Vector3(vec.X/vec.W, vec.Y/vec.W, vec.Z/vec.W);
}
public static Vector2 EvaluateVector2(OperatorPartContext context, List<OperatorPart> inputs, int startIdx)
{
return new Vector2(inputs[startIdx].Eval(context).Value,
inputs[startIdx + 1].Eval(context).Value);
}
public static Vector3 EvaluateVector3(OperatorPartContext context, List<OperatorPart> inputs, int startIdx)
{
return new Vector3(inputs[startIdx].Eval(context).Value,
inputs[startIdx + 1].Eval(context).Value,
inputs[startIdx + 2].Eval(context).Value);
}
public static Vector4 EvaluateVector4(OperatorPartContext context, List<OperatorPart> inputs, int startIdx)
{
return new Vector4(inputs[startIdx].Eval(context).Value,
inputs[startIdx + 1].Eval(context).Value,
inputs[startIdx + 2].Eval(context).Value,
inputs[startIdx + 3].Eval(context).Value);
}
public static string RemoveSpecialCharacters(string str, char replaceChar = ' ')
{
var sb = new StringBuilder();
foreach (char c in str)
{
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') | c == '.' || c == '_')
{
sb.Append(c);
}
else
{
sb.Append(replaceChar);
}
}
return sb.ToString();
}
// Returns titles like "Op" -> "Op (2)" -> "Op (3)"
public static String GetDuplicatedTitle(String name)
{
Regex rgx = new Regex(@"(.+) \((\d+)\)");
MatchCollection matches = rgx.Matches(name);
if (matches.Count == 1)
{
int orgId = Convert.ToInt32(matches[0].Groups[2].Value);
return String.Format("{0} ({1})", matches[0].Groups[1].Value, orgId + 1);
}
else
{
return name + " (2)";
}
}
internal static string AdjustOpPartNameForCode(string inputName)
{
inputName = inputName.Replace(" ", "");
int groupSeparatorIndex = inputName.LastIndexOf('.');
if (groupSeparatorIndex >= 0)
{
inputName = inputName.Remove(groupSeparatorIndex, 1);
inputName = CharAtToUpper(inputName, groupSeparatorIndex);
}
return inputName;
}
public static string GetCompleteVersionString()
{
return String.Format("T2 - {0}.{1} ({2}, {3})", Constants.VersionAsString, BuildProperties.Build,
BuildProperties.Branch, BuildProperties.CommitShort);
}
public static float Noise(int x, int seed)
{
int n = x + seed * 137;
n = (n << 13) ^ n;
return (float)(1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
//public static float Lerp(float a, float b, float t)
//{
// return a + t * (b - a);
//}
public static float Fade(float t)
{
return t * t * t * (t * (t * 6 - 15) + 10);
}
public static float Interpolate(float a, float b, float t)
{
float ft = t * 3.1415927f;
float f = (float)(1.0 - Math.Cos(ft)) * 0.5f;
return (float)(a * (1.0f - f) + b * f);
}
public static float PerlinNoise(float u, float seed, int octaves)
{
var noiseSum = 0.0f;
var period = 1f;
var zoom = 1f;
for (var a = 0; a < octaves - 1; a++)
{
var frequency = (float)Math.Pow(2, a);
var amplitude = (float)Math.Pow(period, a);
var v = u * frequency / zoom + seed * 12.468f;
noiseSum += Lerp(Noise((int)v, (int)seed),
Noise((int)v + 1, (int)seed),
Fade(v - (float)Math.Floor(v))
) * amplitude;
}
return noiseSum;
}
public static Vector3 PerlinNoise3(float u, float seed = 1, int octaves = 2)
{
var noiseSum = Vector3.Zero;
var period = 1f;
for (var a = 0; a < octaves - 1; a++)
{
var frequency = (float) Math.Pow(2, a);
var amplitude = (float) Math.Pow(period, a);
var vInt = (int) (u*frequency);
var vInt1 = vInt + 1;
var n1 = new Vector3(
Noise(vInt, (int) seed),
Noise(vInt, (int) (seed + 12.1f)),
Noise(vInt, (int) (seed + 1314.1f))
);
var n2 = new Vector3(
Noise(vInt1, (int) seed),
Noise(vInt1, (int) (seed + 12.1f)),
Noise(vInt1, (int) (seed + 1314.1f))
);
noiseSum += Vector3.Lerp(n1, n2, Fade(u - (float) Math.Floor(u)))*amplitude;
}
return noiseSum;
}
}
public static class CrashReporter
{
public static String GetFormattedStackTrace(Exception ex)
{
String s = ex.GetType() + "\n" + new String('-', ex.GetType().ToString().Length) + "\n" + ex.Message + "\n\n";
foreach (var line in ex.StackTrace.Split('\n'))
{
//Original stack trace line looks like this:
// at Framefield.Tooll.ConnectionLine.CreateLineGeometry() in c:\self.demos\tooll2\Tooll\ConnectionLine.cs:line 303
Match m = Regex.Match(line, @"\s+at\s+(.*)\s+in\s+(.*):line\s+(\d+).*");
if (m.Success)
{
String function = m.Groups[1].ToString();
String filename = m.Groups[2].ToString().Split('\\').Last().PadLeft(27);
String lineNumber = m.Groups[3].ToString().PadLeft(4);
s += filename + " " + lineNumber + " " + function + "\n";
}
else
{
s += line.Replace(" at ", "".PadLeft(40 - 8));
}
}
return s;
}
public static void WriteCrashReport(System.Exception ex)
{
String titleDate = DateTime.Now.ToString("yyyy'-'MM'-'dd HH'-'mm'-'ss");
String messageTitle = Utilities.RemoveSpecialCharacters(ex.Message);
Directory.CreateDirectory(@"Log/CrashReports");
using (var writer = new StreamWriter("Log/CrashReports/Crash " + titleDate + " - " + messageTitle.Substring(0, Math.Min(30, ex.Message.Length)) + ".txt"))
{
writer.Write(ComposeCrashReport(ex));
}
}
public static String ComposeCrashReport(System.Exception ex)
{
String buffer = "";
buffer += "Date:".PadRight(15) + DateTime.Now + "\n";
buffer += "Version:".PadRight(15) + Constants.VersionAsString + '\n';
buffer += "\n";
if (ex.InnerException != null)
{
buffer += GetFormattedStackTrace(ex.InnerException) + "\n";
}
buffer += "\n";
buffer += GetFormattedStackTrace(ex) + "\n";
return buffer;
}
public static String GetGitLog()
{
string output;
try
{
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.Arguments = "log --stat --summary -3 --no-color";
p.StartInfo.FileName = "c:\\Program Files (x86)\\Git\\bin\\git.exe";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
catch
{
output = "Git status not available";
}
return output;
}
}
public struct PropertyStasher<T> : IDisposable
{
public PropertyStasher(T obj, params string[] args)
{
_object = obj;
_type = typeof(T);
_propertyStack = new Stack<Tuple<string, Object>>();
foreach (var propName in args)
{
PushProperty(propName);
}
}
public void Dispose()
{
int count = _propertyStack.Count;
for (int i = 0; i < count; ++i)
{
PopProperty();
}
}
private T _object;
private Type _type;
private Stack<Tuple<string, Object>> _propertyStack;
private void PushProperty(string propertyName)
{
var propInfo = _type.GetProperty(propertyName);
_propertyStack.Push(Tuple.Create(propertyName, propInfo.GetValue(_object, null)));
}
private void PopProperty()
{
var nameAndValue = _propertyStack.Pop();
var propInfo = _type.GetProperty(nameAndValue.Item1);
propInfo.SetValue(_object, nameAndValue.Item2, null);
}
}
public class SmoothInterpolator
{
public SmoothInterpolator(double defaultValue = 0.0, double acceleration = 200.0, double delta = Double.NaN)
{
_value = defaultValue;
Acceleration = acceleration;
Precision = Double.IsNaN(delta) ? acceleration/100000.0 : delta;
}
private const double MAX_TIME_FRAGMENT = 0.1;
public double Acceleration { get; set; }
public double Precision { get; set; }
private double _value = 0;
private double _valueEnd;
private bool _running = true;
private double _time = 0;
private double _lastTime = 0.0;
private double _speed = 0.0;
private double _min = Double.NaN;
private double _max = Double.NaN;
private double _maxSpeed = Double.PositiveInfinity;
private double _borderFriction = 0.5;
public double GetValue(double time)
{
if (_lastTime == time)
return _value;
_lastTime = time;
// ignore first call
if (_time == 0)
{
_time = time;
return _value;
}
double timeFragment = time - _time;
timeFragment = Math.Max(-MAX_TIME_FRAGMENT, Math.Min(timeFragment, MAX_TIME_FRAGMENT));
//if (timeFragment > MAX_TIME_FRAGMENT)
// timeFragment = MAX_TIME_FRAGMENT;
_time = time;
if (!_running)
return _value;
// calculate optimal speed
double distanceBrake = _speed*_speed/Acceleration;
double distance = _valueEnd - _value;
if (Math.Abs(distance) < Precision)
{
// and abs(_speed) * _acceleration * 2.4 < _delta:
_speed = 0.0;
_value = _valueEnd;
_running = false;
}
else if (distance < 0)
{
// wrong direction
if (_speed > 0)
{
_speed -= Acceleration*timeFragment;
}
// accelerate neg
else if (Math.Abs(distance) > distanceBrake)
{
if (Math.Abs(_speed) < _maxSpeed)
{
_speed = Utilities.Clamp(_speed - Acceleration*timeFragment*0.8, -_maxSpeed, 0.0);
}
else
{
_speed *= 0.99;
}
}
//
else
{
if (Math.Abs(distance) < Precision*5.0 && Math.Abs(Acceleration) < Precision)
{
Acceleration *= 1.0 - (Math.Abs(distance) - Precision*5.0)/50.0;
}
_speed += Acceleration*timeFragment;
}
}
else if (distance > 0)
{
// wrong direction
if (_speed < 0)
{
_speed += Acceleration*timeFragment;
}
// accelerate neg
else if (Math.Abs(distance) > distanceBrake)
{
if (Math.Abs(_speed) < _maxSpeed)
{
_speed = Utilities.Clamp(_speed + Acceleration*timeFragment*0.8, 0.0, _maxSpeed);
}
else
{
_speed *= 0.99;
}
}
// deccalerate neg
else
{
if (Math.Abs(distance) < Precision*5.0 && Math.Abs(Acceleration) < Precision)
Acceleration *= 1.0 - (Math.Abs(distance) - Precision*5.0)/50.0;
_speed -= Acceleration*timeFragment;
}
}
//if _debug:
// note("value=%4.3f\tspeed=%4.3f\tdistance=%4.3f\tbrake=%4.3f\tdt=%4.3f\tvalueEnd=%4.3f maxSpeed=%4.3f" % (_value, _speed, distance, distanceBrake, timeFragment, _valueEnd, _maxSpeed))
_value += _speed*timeFragment;
if (!Double.IsNaN(_min) && _value < _min)
{
_speed *= -_borderFriction;
_value = _min + _borderFriction*(_value - _min);
if (_valueEnd > _min)
_valueEnd = _min;
}
if (!Double.IsNaN(_max) && _value > _max)
{
_speed *= -_borderFriction;
_value = _max - _borderFriction*(_value - _max);
if (_valueEnd < _max)
_valueEnd = _max;
}
_lastTime = time;
return _value;
}
/**
* set to fixed value and stop animation
*/
public void SetValue(double value)
{
_value = _valueEnd = value;
_speed = 0.0;
}
public void SetAcceleration(double acceleration, double delta = Double.NaN)
{
Acceleration = acceleration;
if (Double.IsNaN(delta))
{
Precision = acceleration/5000.0;
}
else
{
Precision = delta;
}
}
/// <summary>
/// set to fixed value and stop animation
/// </summary>
/// <param name="value"></param>
/// <param name="time"></param>
/// <param name="speed"></param>
/// <param name="maxSpeed"></param>
public void AnimateTo(double value, double time = Double.NaN, double speed = double.NaN,
double maxSpeed = Double.PositiveInfinity)
{
_maxSpeed = maxSpeed;
if (!Double.IsNaN(time))
_time = time;
_running = true;
_valueEnd = value;
if (!Double.IsNaN(speed))
_speed = speed;
}
/// <summary>
/// offset the target value (e.g. for scrolling for a fixed distance)
/// </summary>
/// <param name="?"></param>
/// <param name="?"></param>
/// <returns></returns>
public void OffsetTo(double value)
{
_running = true;
_valueEnd += value;
}
/// <summary>
/// Jumps Value during animation (e.g. for jump-cuts)
/// </summary>
/// <param name="offset"></param>
public void Offset(double offset)
{
_value += offset;
_running = true;
}
public bool IsRunning(double time)
{
var tmp = GetValue(time);
return _running;
}
/// <summary>
/// Use None to disable boundary.
/// </summary>
/// <param name="?"></param>
/// <param name="?"></param>
/// <param name="?"></param>
public void UseReflectBoundaries(double min, double max)
{
_min = min;
if (!Double.IsNaN(max) && !Double.IsNaN(min) && max < min)
max = min;
_max = max;
}
}
}