Here are the examples of the csharp api double.IsNaN(double) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2405 Examples
19
View Source File : RandomHelper.cs
License : MIT License
Project Creator : 1996v
License : MIT License
Project Creator : 1996v
public static object RandomValue(this Type t, bool stringValueAllowEmpty = true)
{
if (t.IsPrimitive)
{
if (t == typeof(byte))
{
return (byte)(Rand.Next(byte.MaxValue - byte.MinValue + 1) + byte.MinValue);
}
if (t == typeof(sbyte))
{
return (sbyte)(Rand.Next(sbyte.MaxValue - sbyte.MinValue + 1) + sbyte.MinValue);
}
if (t == typeof(short))
{
return (short)(Rand.Next(short.MaxValue - short.MinValue + 1) + short.MinValue);
}
if (t == typeof(ushort))
{
return (ushort)(Rand.Next(ushort.MaxValue - ushort.MinValue + 1) + ushort.MinValue);
}
if (t == typeof(int))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
if (t == typeof(uint))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToUInt32(bytes, 0);
}
if (t == typeof(long))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToInt64(bytes, 0);
}
if (t == typeof(ulong))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToUInt64(bytes, 0);
}
if (t == typeof(float))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
var f = BitConverter.ToSingle(bytes, 0);
if (float.IsNaN(f))
f = (float)RandomValue<short>();
return f;
}
if (t == typeof(double))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
var d = BitConverter.ToDouble(bytes, 0);
if (double.IsNaN(d))
d = (double)RandomValue<short>();
return d;
}
if (t == typeof(char))
{
var roll = Rand.Next(ASCII.Length);
return ASCII[roll];
}
if (t == typeof(bool))
{
return (Rand.Next(2) == 1);
}
throw new InvalidOperationException();
}
if (t == typeof(decimal))
{
return new decimal((int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), false, 28);
}
if (t == typeof(string))
{
int start = stringValueAllowEmpty ? 0 : 1;
var len = Rand.Next(start, 28);
var c = new char[len];
for (var i = 0; i < c.Length; i++)
{
c[i] = (char)typeof(char).RandomValue();
}
return new string(c);
}
if (t == typeof(DateTime))
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var bytes = new byte[4];
Rand.NextBytes(bytes);
var secsOffset = BitConverter.ToInt32(bytes, 0);
var retDate = epoch.AddSeconds(secsOffset);
return retDate;
}
if (t == typeof(TimeSpan))
{
return new TimeSpan(RandomValue<DateTime>().Ticks);
}
if (t == typeof(DataTable))
{
DataTable dt = new DataTable();
int coluCount = Rand.Next(10, 30);
for (int i = 0; i < coluCount; i++)
{
dt.Columns.Add(RandomHelper.RandomValue<string>(false), typeof(object));
}
int rowCount = Rand.Next(20, 50);
for (int i = 0; i < rowCount; i++)
{
var row = new object[coluCount];
for (int zi = 0; zi < coluCount; zi++)
{
row[zi] = RandomHelper.RandomValue<object>();
}
dt.Rows.Add(row);
}
return dt;
}
if (t.IsNullable())
{
// leave it unset
if (Rand.Next(2) == 0)
{
// null!
return Activator.CreateInstance(t);
}
var underlying = Nullable.GetUnderlyingType(t);
var val = underlying.RandomValue(stringValueAllowEmpty);
var cons = t.GetConstructor(new[] { underlying });
return cons.Invoke(new object[] { val });
}
if (t.IsEnum)
{
var allValues = Enum.GetValues(t);
var ix = Rand.Next(allValues.Length);
return allValues.GetValue(ix);
}
if (t.IsArray)
{
var valType = t.GetElementType();
var len = Rand.Next(20, 50);
var ret = Array.CreateInstance(valType, len);
//var add = t.GetMethod("SetValue");
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
ret.SetValue(elem, i);
}
return ret;
}
if (t.IsGenericType)
{
var defind = t.GetGenericTypeDefinition();
if (defind == typeof(HashSet<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("Contains");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
while (elem == null || (bool)contains.Invoke(ret, new object[] { elem }))
elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(Dictionary<,>))
{
var keyType = t.GetGenericArguments()[0];
var valType = t.GetGenericArguments()[1];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("ContainsKey");
var len = Rand.Next(20, 50);
if (keyType == typeof(Boolean))
len = 2;
for (var i = 0; i < len; i++)
{
var val = valType.RandomValue(stringValueAllowEmpty);
var key = keyType.RandomValue(stringValueAllowEmpty);
while (key == null || (bool)contains.Invoke(ret, new object[] { key }))
key = keyType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { key, val });
}
return ret;
}
if (defind == typeof(List<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(ArraySegment<>))
{
var valType = t.GetGenericArguments()[0];
var ary = valType.MakeArrayType().RandomValue(stringValueAllowEmpty);
var lenT = ary.GetType().GetProperty("Length");
var offset = Rand.Next(0, (int)lenT.GetValue(ary) - 1);
var len = (int)lenT.GetValue(ary) - offset;
return Activator.CreateInstance(t, ary, offset, len);
}
}
if (t == typeof(Guid))
return Guid.NewGuid();
if (t == typeof(object))
{
var code = Rand.Next(0, 9);
switch (code)
{
case 0:
return RandomValue<int>();
case 1:
return RandomValue<long>();
case 2:
return RandomValue<Char>();
case 3:
return RandomValue<DateTime>();
case 4:
return RandomValue<string>(stringValueAllowEmpty);
case 5:
return RandomValue<Guid>();
case 6:
return RandomValue<decimal>();
case 7:
return RandomValue<double>();
case 8:
return RandomValue<float>();
default:
return RandomValue<short>();
}
}
//model
var retObj = Activator.CreateInstance(t);
foreach (var p in t.GetFields())
{
//if (Rand.Next(5) == 0) continue;
var fieldType = p.FieldType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
foreach (var p in t.GetProperties())
{
//if (Rand.Next(5) == 0) continue;
if (p.CanWrite && p.CanRead)
{
var fieldType = p.PropertyType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
}
return retObj;
}
19
View Source File : RandomHelper.cs
License : MIT License
Project Creator : 1996v
License : MIT License
Project Creator : 1996v
public static object RandomValue(this Type t, bool stringValueAllowEmpty = true)
{
if (t.IsPrimitive)
{
if (t == typeof(byte))
{
return (byte)(Rand.Next(byte.MaxValue - byte.MinValue + 1) + byte.MinValue);
}
if (t == typeof(sbyte))
{
return (sbyte)(Rand.Next(sbyte.MaxValue - sbyte.MinValue + 1) + sbyte.MinValue);
}
if (t == typeof(short))
{
return (short)(Rand.Next(short.MaxValue - short.MinValue + 1) + short.MinValue);
}
if (t == typeof(ushort))
{
return (ushort)(Rand.Next(ushort.MaxValue - ushort.MinValue + 1) + ushort.MinValue);
}
if (t == typeof(int))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToInt32(bytes, 0);
}
if (t == typeof(uint))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
return BitConverter.ToUInt32(bytes, 0);
}
if (t == typeof(long))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToInt64(bytes, 0);
}
if (t == typeof(ulong))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
return BitConverter.ToUInt64(bytes, 0);
}
if (t == typeof(float))
{
var bytes = new byte[4];
Rand.NextBytes(bytes);
var f = BitConverter.ToSingle(bytes, 0);
if (float.IsNaN(f))
f = (float)RandomValue<short>();
return f;
}
if (t == typeof(double))
{
var bytes = new byte[8];
Rand.NextBytes(bytes);
var d= BitConverter.ToDouble(bytes, 0);
if (double.IsNaN(d))
d = (double)RandomValue<short>();
return d;
}
if (t == typeof(char))
{
var roll = Rand.Next(ASCII.Length);
return ASCII[roll];
}
if (t == typeof(bool))
{
return (Rand.Next(2) == 1);
}
throw new InvalidOperationException();
}
if (t == typeof(decimal))
{
return new decimal((int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), (int)typeof(int).RandomValue(), false, 28);
}
if (t == typeof(string))
{
int start = stringValueAllowEmpty ? 0 : 1;
var len = Rand.Next(start, 40);
var c = new char[len];
for (var i = 0; i < c.Length; i++)
{
c[i] = (char)typeof(char).RandomValue();
}
return new string(c);
}
if (t == typeof(DateTime))
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var bytes = new byte[4];
Rand.NextBytes(bytes);
var secsOffset = BitConverter.ToInt32(bytes, 0);
var retDate = epoch.AddSeconds(secsOffset);
return retDate;
}
if (t == typeof(TimeSpan))
{
return new TimeSpan(RandomValue<DateTime>().Ticks);
}
if (t == typeof(DataTable))
{
DataTable dt = new DataTable();
int coluCount = Rand.Next(10, 30);
for (int i = 0; i < coluCount; i++)
{
string n = RandomHelper.RandomValue<string>(false);
while(dt.Columns.Contains(n))
n = RandomHelper.RandomValue<string>(false);
dt.Columns.Add(n, typeof(object));
}
int rowCount = Rand.Next(20, 50);
for (int i = 0; i < rowCount; i++)
{
var row = new object[coluCount];
for (int zi = 0; zi < coluCount; zi++)
{
row[zi] = RandomHelper.RandomValue<object>();
}
dt.Rows.Add(row);
}
return dt;
}
if (t.IsNullable())
{
// leave it unset
if (Rand.Next(2) == 0)
{
// null!
return Activator.CreateInstance(t);
}
var underlying = Nullable.GetUnderlyingType(t);
var val = underlying.RandomValue(stringValueAllowEmpty);
var cons = t.GetConstructor(new[] { underlying });
return cons.Invoke(new object[] { val });
}
if (t.IsEnum)
{
var allValues = Enum.GetValues(t);
var ix = Rand.Next(allValues.Length);
return allValues.GetValue(ix);
}
if (t.IsArray)
{
var valType = t.GetElementType();
var len = Rand.Next(20, 50);
var ret = Array.CreateInstance(valType, len);
//var add = t.GetMethod("SetValue");
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
ret.SetValue(elem, i);
}
return ret;
}
if (t.IsGenericType)
{
var defind = t.GetGenericTypeDefinition();
if (defind == typeof(HashSet<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("Contains");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
while (elem == null || (bool)contains.Invoke(ret, new object[] { elem }))
elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(Dictionary<,>))
{
var keyType = t.GetGenericArguments()[0];
var valType = t.GetGenericArguments()[1];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var contains = t.GetMethod("ContainsKey");
var len = Rand.Next(20, 50);
if (keyType == typeof(Boolean))
len = 2;
for (var i = 0; i < len; i++)
{
var val = valType.RandomValue(stringValueAllowEmpty);
var key = keyType.RandomValue(stringValueAllowEmpty);
while (key == null || (bool)contains.Invoke(ret, new object[] { key }))
key = keyType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { key, val });
}
return ret;
}
if (defind == typeof(List<>))
{
var valType = t.GetGenericArguments()[0];
var ret = Activator.CreateInstance(t);
var add = t.GetMethod("Add");
var len = Rand.Next(20, 50);
for (var i = 0; i < len; i++)
{
var elem = valType.RandomValue(stringValueAllowEmpty);
add.Invoke(ret, new object[] { elem });
}
return ret;
}
if (defind == typeof(ArraySegment<>))
{
var valType = t.GetGenericArguments()[0];
var ary = valType.MakeArrayType().RandomValue(stringValueAllowEmpty);
var lenT = ary.GetType().GetProperty("Length");
var offset = Rand.Next(0, (int)lenT.GetValue(ary) - 1);
var len = (int)lenT.GetValue(ary) - offset;
return Activator.CreateInstance(t, ary, offset, len);
}
}
if (t == typeof(Guid))
return Guid.NewGuid();
if (t == typeof(object))
{
var code = Rand.Next(0, 9);
switch (code)
{
case 0:
return RandomValue<int>();
case 1:
return RandomValue<long>();
case 2:
return RandomValue<Char>();
case 3:
return RandomValue<DateTime>();
case 4:
return RandomValue<string>(stringValueAllowEmpty);
case 5:
return RandomValue<Guid>();
case 6:
return RandomValue<decimal>();
case 7:
return RandomValue<double>();
case 8:
return RandomValue<float>();
default:
return RandomValue<short>();
}
}
//model
var retObj = Activator.CreateInstance(t);
foreach (var p in t.GetFields())
{
//if (Rand.Next(5) == 0) continue;
var fieldType = p.FieldType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
foreach (var p in t.GetProperties())
{
//if (Rand.Next(5) == 0) continue;
if (p.CanWrite && p.CanRead)
{
var fieldType = p.PropertyType;
p.SetValue(retObj, fieldType.RandomValue(stringValueAllowEmpty));
}
}
return retObj;
}
19
View Source File : AccelCalculator.cs
License : MIT License
Project Creator : a1xd
License : MIT License
Project Creator : a1xd
private SimulatedMouseInput SimulateAngledInput(double angle, double magnitude)
{
SimulatedMouseInput mouseInputData;
var moveX = Math.Round(magnitude * Math.Cos(angle), 4);
var moveY = Math.Round(magnitude * Math.Sin(angle), 4);
if (moveX == 0)
{
mouseInputData.x = 0;
mouseInputData.y = (int)Math.Ceiling(moveY);
mouseInputData.time = mouseInputData.y / moveY;
}
else if (moveY == 0)
{
mouseInputData.x = (int)Math.Ceiling(moveX);
mouseInputData.y = 0;
mouseInputData.time = mouseInputData.x / moveX;
}
else
{
var ratio = moveY / moveX;
int ceilX = 0;
int ceilY = 0;
double biggerX = 0;
double biggerY = 0;
double roundedBiggerX = 0;
double roundedBiggerY = 0;
double roundedRatio = -1;
double factor = 10;
while (Math.Abs(roundedRatio - ratio) > 0.01 &&
biggerX < 25000 &&
biggerY < 25000)
{
roundedBiggerX = Math.Floor(biggerX);
roundedBiggerY = Math.Floor(biggerY);
ceilX = Convert.ToInt32(roundedBiggerX);
ceilY = Convert.ToInt32(roundedBiggerY);
roundedRatio = ceilX > 0 ? ceilY / ceilX : -1;
biggerX = moveX * factor;
biggerY = moveY * factor;
factor *= 10;
}
var ceilMagnitude = Magnitude(ceilX, ceilY);
var timeFactor = ceilMagnitude / magnitude;
mouseInputData.x = ceilX;
mouseInputData.y = ceilY;
mouseInputData.time = timeFactor;
if (mouseInputData.x == 1 && mouseInputData.time == 1)
{
Console.WriteLine("Oops");
}
}
mouseInputData.velocity = DecimalCheck(Velocity(mouseInputData.x, mouseInputData.y, mouseInputData.time));
if (double.IsNaN(mouseInputData.velocity))
{
Console.WriteLine("oopsie");
}
mouseInputData.angle = angle;
return mouseInputData;
}
19
View Source File : AccelCalculator.cs
License : MIT License
Project Creator : a1xd
License : MIT License
Project Creator : a1xd
public void CalculateDirectional(AccelChartData[] dataByAngle, ManagedAccel accel, Profile settings, IReadOnlyCollection<IReadOnlyCollection<SimulatedMouseInput>> simulatedInputData)
{
double maxRatio = 0.0;
double minRatio = Double.MaxValue;
double maxSlope = 0.0;
double minSlope = Double.MaxValue;
int angleIndex = 0;
foreach (var simulatedInputDataAngle in simulatedInputData)
{
double log = -2;
int index = 0;
int logIndex = 0;
double lastInputMagnitude = 0;
double lastOutputMagnitude = 0;
var data = dataByAngle[angleIndex];
foreach (var simulatedInputDatum in simulatedInputDataAngle)
{
if (simulatedInputDatum.velocity <= 0)
{
continue;
}
var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, 1, simulatedInputDatum.time);
var magnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time));
var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5);
var outDiff = Math.Round(magnitude - lastOutputMagnitude, 5);
if (inDiff == 0)
{
continue;
}
if (!data.VelocityPoints.ContainsKey(simulatedInputDatum.velocity))
{
data.VelocityPoints.Add(simulatedInputDatum.velocity, magnitude);
}
else
{
continue;
}
while (Math.Pow(10, log) < magnitude && logIndex < data.LogToIndex.Length)
{
data.LogToIndex[logIndex] = index;
log += 0.01;
logIndex++;
}
var ratio = DecimalCheck(magnitude / simulatedInputDatum.velocity);
var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : settings.sensitivity);
bool indexToMeasureExtrema = (angleIndex == 0) || (angleIndex == (Constants.AngleDivisions - 1));
if (angleIndex == 0 && double.IsNaN(ratio))
{
Console.WriteLine("oops");
}
if (indexToMeasureExtrema && (ratio > maxRatio))
{
maxRatio = ratio;
}
if (indexToMeasureExtrema && (ratio < minRatio))
{
minRatio = ratio;
}
if (indexToMeasureExtrema && (slope > maxSlope))
{
maxSlope = slope;
}
if (indexToMeasureExtrema && (slope < minSlope))
{
minSlope = slope;
}
if (!data.AccelPoints.ContainsKey(simulatedInputDatum.velocity))
{
data.AccelPoints.Add(simulatedInputDatum.velocity, ratio);
}
if (!data.GainPoints.ContainsKey(simulatedInputDatum.velocity))
{
data.GainPoints.Add(simulatedInputDatum.velocity, slope);
}
lastInputMagnitude = simulatedInputDatum.velocity;
lastOutputMagnitude = magnitude;
index += 1;
}
index--;
while (log <= 5.0)
{
data.LogToIndex[logIndex] = index;
log += 0.01;
logIndex++;
}
angleIndex++;
}
dataByAngle[0].MaxAccel = maxRatio;
dataByAngle[0].MinAccel = minRatio;
dataByAngle[0].MaxGain = maxSlope;
dataByAngle[0].MinGain = minSlope;
}
19
View Source File : CaretNavigationCommandHandler.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
static TextViewPosition GetUpDownCaretPosition(TextView textView, TextViewPosition caretPosition, CaretMovementType direction, VisualLine visualLine, TextLine textLine, bool enableVirtualSpace, ref double xPos)
{
// moving up/down happens using the desired visual X position
if (double.IsNaN(xPos))
xPos = visualLine.GetTextLineVisualXPosition(textLine, caretPosition.VisualColumn);
// now find the TextLine+VisualLine where the caret will end up in
VisualLine targetVisualLine = visualLine;
TextLine targetLine;
int textLineIndex = visualLine.TextLines.IndexOf(textLine);
switch (direction) {
case CaretMovementType.LineUp: {
// Move up: move to the previous TextLine in the same visual line
// or move to the last TextLine of the previous visual line
int prevLineNumber = visualLine.FirstDoreplacedentLine.LineNumber - 1;
if (textLineIndex > 0) {
targetLine = visualLine.TextLines[textLineIndex - 1];
} else if (prevLineNumber >= 1) {
DoreplacedentLine prevLine = textView.Doreplacedent.GetLineByNumber(prevLineNumber);
targetVisualLine = textView.GetOrConstructVisualLine(prevLine);
targetLine = targetVisualLine.TextLines[targetVisualLine.TextLines.Count - 1];
} else {
targetLine = null;
}
break;
}
case CaretMovementType.LineDown: {
// Move down: move to the next TextLine in the same visual line
// or move to the first TextLine of the next visual line
int nextLineNumber = visualLine.LastDoreplacedentLine.LineNumber + 1;
if (textLineIndex < visualLine.TextLines.Count - 1) {
targetLine = visualLine.TextLines[textLineIndex + 1];
} else if (nextLineNumber <= textView.Doreplacedent.LineCount) {
DoreplacedentLine nextLine = textView.Doreplacedent.GetLineByNumber(nextLineNumber);
targetVisualLine = textView.GetOrConstructVisualLine(nextLine);
targetLine = targetVisualLine.TextLines[0];
} else {
targetLine = null;
}
break;
}
case CaretMovementType.PageUp:
case CaretMovementType.PageDown: {
// Page up/down: find the target line using its visual position
double yPos = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.LineMiddle);
if (direction == CaretMovementType.PageUp)
yPos -= textView.RenderSize.Height;
else
yPos += textView.RenderSize.Height;
DoreplacedentLine newLine = textView.GetDoreplacedentLineByVisualTop(yPos);
targetVisualLine = textView.GetOrConstructVisualLine(newLine);
targetLine = targetVisualLine.GetTextLineByVisualYPosition(yPos);
break;
}
default:
throw new NotSupportedException(direction.ToString());
}
if (targetLine != null) {
double yPos = targetVisualLine.GetTextLineVisualYPosition(targetLine, VisualYPosition.LineMiddle);
int newVisualColumn = targetVisualLine.GetVisualColumn(new Point(xPos, yPos), enableVirtualSpace);
// prevent wrapping to the next line; TODO: could 'IsAtEnd' help here?
int targetLineStartCol = targetVisualLine.GetTextLineVisualStartColumn(targetLine);
if (newVisualColumn >= targetLineStartCol + targetLine.Length) {
if (newVisualColumn <= targetVisualLine.VisualLength)
newVisualColumn = targetLineStartCol + targetLine.Length - 1;
}
return targetVisualLine.GetTextViewPosition(newVisualColumn);
} else {
return caretPosition;
}
}
19
View Source File : InlineObjectRun.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public override TextEmbeddedObjectMetrics Format(double remainingParagraphWidth)
{
double baseline = TextBlock.GetBaselineOffset(element);
if (double.IsNaN(baseline))
baseline = desiredSize.Height;
return new TextEmbeddedObjectMetrics(desiredSize.Width, desiredSize.Height, baseline);
}
19
View Source File : InlineObjectRun.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public override Rect ComputeBoundingBox(bool rightToLeft, bool sideways)
{
if (this.element.IsArrangeValid) {
double baseline = TextBlock.GetBaselineOffset(element);
if (double.IsNaN(baseline))
baseline = desiredSize.Height;
return new Rect(new Point(0, -baseline), desiredSize);
} else {
return Rect.Empty;
}
}
19
View Source File : FdbConverters.cs
License : MIT License
Project Creator : abdullin
License : MIT License
Project Creator : abdullin
private static void RegisterDefaultConverters()
{
//TODO: there is too much generic type combinations! need to refactor this ...
RegisterUnsafe<bool, Slice>((value) => Slice.FromByte(value ? (byte)1 : default(byte)));
RegisterUnsafe<bool, byte[]>((value) => Slice.FromByte(value ? (byte)1 : default(byte)).GetBytes());
RegisterUnsafe<bool, string>((value) => value ? "true" : "false");
RegisterUnsafe<bool, sbyte>((value) => value ? (sbyte)1 : default(sbyte));
RegisterUnsafe<bool, byte>((value) => value ? (byte)1 : default(byte));
RegisterUnsafe<bool, short>((value) => value ? (short)1 : default(short));
RegisterUnsafe<bool, ushort>((value) => value ? (ushort)1 : default(ushort));
RegisterUnsafe<bool, int>((value) => value ? 1 : default(int));
RegisterUnsafe<bool, uint>((value) => value ? 1U : default(uint));
RegisterUnsafe<bool, long>((value) => value ? 1L : default(long));
RegisterUnsafe<bool, ulong>((value) => value ? 1UL : default(ulong));
RegisterUnsafe<bool, double>((value) => value ? 0.0d : 1.0d);
RegisterUnsafe<bool, float>((value) => value ? 0.0f : 1.0f);
RegisterUnsafe<int, Slice>((value) => Slice.FromInt32(value));
RegisterUnsafe<int, byte[]>((value) => Slice.FromInt32(value).GetBytes());
RegisterUnsafe<int, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<int, bool>((value) => value != 0);
RegisterUnsafe<int, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<int, byte>((value) => checked((byte)value));
RegisterUnsafe<int, short>((value) => checked((short)value));
RegisterUnsafe<int, ushort>((value) => checked((ushort)value));
RegisterUnsafe<int, uint>((value) => (uint)value);
RegisterUnsafe<int, long>((value) => value);
RegisterUnsafe<int, ulong>((value) => (ulong)value);
RegisterUnsafe<int, double>((value) => value);
RegisterUnsafe<int, float>((value) => checked((float)value));
RegisterUnsafe<int, FdbTupleAlias>((value) => (FdbTupleAlias)value);
RegisterUnsafe<uint, Slice>((value) => Slice.FromUInt64(value));
RegisterUnsafe<uint, byte[]>((value) => Slice.FromUInt64(value).GetBytes());
RegisterUnsafe<uint, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<uint, bool>((value) => value != 0);
RegisterUnsafe<uint, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<uint, byte>((value) => checked((byte)value));
RegisterUnsafe<uint, short>((value) => checked((short)value));
RegisterUnsafe<uint, ushort>((value) => checked((ushort)value));
RegisterUnsafe<uint, int>((value) => (int)value);
RegisterUnsafe<uint, long>((value) => value);
RegisterUnsafe<uint, ulong>((value) => value);
RegisterUnsafe<uint, double>((value) => value);
RegisterUnsafe<uint, float>((value) => checked((float)value));
RegisterUnsafe<long, Slice>((value) => Slice.FromInt64(value));
RegisterUnsafe<long, byte[]>((value) => Slice.FromInt64(value).GetBytes());
RegisterUnsafe<long, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<long, bool>((value) => value != 0);
RegisterUnsafe<long, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<long, byte>((value) => checked((byte)value));
RegisterUnsafe<long, short>((value) => checked((short)value));
RegisterUnsafe<long, ushort>((value) => checked((ushort)value));
RegisterUnsafe<long, int>((value) => checked((int)value));
RegisterUnsafe<long, uint>((value) => (uint)value);
RegisterUnsafe<long, ulong>((value) => (ulong)value);
RegisterUnsafe<long, double>((value) => checked((double)value));
RegisterUnsafe<long, float>((value) => checked((float)value));
RegisterUnsafe<long, TimeSpan>((value) => TimeSpan.FromTicks(value));
RegisterUnsafe<long, Uuid64>((value) => new Uuid64(value));
RegisterUnsafe<long, System.Net.IPAddress>((value) => new System.Net.IPAddress(value));
RegisterUnsafe<ulong, Slice>((value) => Slice.FromUInt64(value));
RegisterUnsafe<ulong, byte[]>((value) => Slice.FromUInt64(value).GetBytes());
RegisterUnsafe<ulong, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<ulong, bool>((value) => value != 0);
RegisterUnsafe<ulong, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<ulong, byte>((value) => checked((byte)value));
RegisterUnsafe<ulong, short>((value) => checked((short)value));
RegisterUnsafe<ulong, ushort>((value) => checked((ushort)value));
RegisterUnsafe<ulong, int>((value) => checked((int)value));
RegisterUnsafe<ulong, uint>((value) => checked((uint)value));
RegisterUnsafe<ulong, long>((value) => checked((long)value));
RegisterUnsafe<ulong, double>((value) => checked((double)value));
RegisterUnsafe<ulong, float>((value) => checked((float)value));
RegisterUnsafe<ulong, Uuid64>((value) => new Uuid64(value));
RegisterUnsafe<ulong, TimeSpan>((value) => TimeSpan.FromTicks(checked((long)value)));
RegisterUnsafe<short, Slice>((value) => Slice.FromInt32(value));
RegisterUnsafe<short, byte[]>((value) => Slice.FromInt32(value).GetBytes());
RegisterUnsafe<short, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<short, bool>((value) => value != 0);
RegisterUnsafe<short, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<short, byte>((value) => checked((byte)value));
RegisterUnsafe<short, ushort>((value) => checked((ushort)value));
RegisterUnsafe<short, int>((value) => value);
RegisterUnsafe<short, uint>((value) => checked((uint)value));
RegisterUnsafe<short, long>((value) => value);
RegisterUnsafe<short, ulong>((value) => checked((ulong)value));
RegisterUnsafe<short, double>((value) => value);
RegisterUnsafe<short, float>((value) => value);
RegisterUnsafe<short, FdbTupleAlias>((value) => (FdbTupleAlias)value);
RegisterUnsafe<ushort, Slice>((value) => Slice.FromUInt64(value));
RegisterUnsafe<ushort, byte[]>((value) => Slice.FromUInt64(value).GetBytes());
RegisterUnsafe<ushort, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<ushort, bool>((value) => value != 0);
RegisterUnsafe<ushort, byte>((value) => checked((byte)value));
RegisterUnsafe<ushort, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<ushort, short>((value) => checked((short)value));
RegisterUnsafe<ushort, int>((value) => value);
RegisterUnsafe<ushort, uint>((value) => value);
RegisterUnsafe<ushort, long>((value) => value);
RegisterUnsafe<ushort, ulong>((value) => value);
RegisterUnsafe<ushort, double>((value) => value);
RegisterUnsafe<ushort, float>((value) => value);
RegisterUnsafe<byte, Slice>((value) => Slice.FromInt32(value));
RegisterUnsafe<byte, byte[]>((value) => Slice.FromInt32(value).GetBytes());
RegisterUnsafe<byte, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<byte, bool>((value) => value != 0);
RegisterUnsafe<byte, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<byte, short>((value) => value);
RegisterUnsafe<byte, ushort>((value) => value);
RegisterUnsafe<byte, int>((value) => value);
RegisterUnsafe<byte, uint>((value) => value);
RegisterUnsafe<byte, long>((value) => value);
RegisterUnsafe<byte, ulong>((value) => value);
RegisterUnsafe<byte, double>((value) => value);
RegisterUnsafe<byte, float>((value) => value);
RegisterUnsafe<byte, FdbTupleAlias>((value) => (FdbTupleAlias)value);
RegisterUnsafe<sbyte, Slice>((value) => Slice.FromInt64(value));
RegisterUnsafe<sbyte, byte[]>((value) => Slice.FromInt64(value).GetBytes());
RegisterUnsafe<sbyte, string>((value) => value.ToString(CultureInfo.InvariantCulture)); //TODO: string table!
RegisterUnsafe<sbyte, bool>((value) => value != 0);
RegisterUnsafe<sbyte, byte>((value) => checked((byte)value));
RegisterUnsafe<sbyte, short>((value) => value);
RegisterUnsafe<sbyte, ushort>((value) => checked((ushort)value));
RegisterUnsafe<sbyte, int>((value) => value);
RegisterUnsafe<sbyte, uint>((value) => checked((uint)value));
RegisterUnsafe<sbyte, long>((value) => value);
RegisterUnsafe<sbyte, ulong>((value) => checked((ulong)value));
RegisterUnsafe<sbyte, double>((value) => value);
RegisterUnsafe<sbyte, float>((value) => value);
RegisterUnsafe<float, Slice>((value) => Slice.FromSingle(value));
RegisterUnsafe<float, byte[]>((value) => Slice.FromSingle(value).GetBytes());
RegisterUnsafe<float, string>((value) => value.ToString("R", CultureInfo.InvariantCulture));
RegisterUnsafe<float, bool>((value) => !(value == 0f || float.IsNaN(value)));
RegisterUnsafe<float, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<float, byte>((value) => checked((byte)value));
RegisterUnsafe<float, short>((value) => checked((short)value));
RegisterUnsafe<float, ushort>((value) => checked((ushort)value));
RegisterUnsafe<float, int>((value) => checked((int)value));
RegisterUnsafe<float, uint>((value) => (uint)value);
RegisterUnsafe<float, long>((value) => checked((long)value));
RegisterUnsafe<float, ulong>((value) => (ulong)value);
RegisterUnsafe<float, double>((value) => value);
RegisterUnsafe<double, Slice>((value) => Slice.FromDouble(value));
RegisterUnsafe<double, byte[]>((value) => Slice.FromDouble(value).GetBytes());
RegisterUnsafe<double, string>((value) => value.ToString("R", CultureInfo.InvariantCulture));
RegisterUnsafe<double, bool>((value) => !(value == 0d || double.IsNaN(value)));
RegisterUnsafe<double, sbyte>((value) => checked((sbyte)value));
RegisterUnsafe<double, byte>((value) => checked((byte)value));
RegisterUnsafe<double, short>((value) => checked((short)value));
RegisterUnsafe<double, ushort>((value) => checked((ushort)value));
RegisterUnsafe<double, int>((value) => checked((int)value));
RegisterUnsafe<double, uint>((value) => (uint)value);
RegisterUnsafe<double, long>((value) => checked((long)value));
RegisterUnsafe<double, ulong>((value) => (ulong)value);
RegisterUnsafe<double, float>((value) => checked((float)value));
RegisterUnsafe<string, Slice>((value) => Slice.FromString(value));
RegisterUnsafe<string, byte[]>((value) => Slice.FromString(value).GetBytes());
RegisterUnsafe<string, bool>((value) => !string.IsNullOrEmpty(value));
RegisterUnsafe<string, sbyte>((value) => string.IsNullOrEmpty(value) ? default(sbyte) : SByte.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, byte>((value) => string.IsNullOrEmpty(value) ? default(byte) : Byte.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, short>((value) => string.IsNullOrEmpty(value) ? default(short) : Int16.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, ushort>((value) => string.IsNullOrEmpty(value) ? default(ushort) : UInt16.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, int>((value) => string.IsNullOrEmpty(value) ? default(int) : Int32.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, uint>((value) => string.IsNullOrEmpty(value) ? default(uint) : UInt32.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, long>((value) => string.IsNullOrEmpty(value) ? default(long) : Int64.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, ulong>((value) => string.IsNullOrEmpty(value) ? default(ulong) : UInt64.Parse(value, CultureInfo.InvariantCulture));
RegisterUnsafe<string, float>((value) => string.IsNullOrEmpty(value) ? default(float) : Single.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture));
RegisterUnsafe<string, double>((value) => string.IsNullOrEmpty(value) ? default(double) : Double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture));
RegisterUnsafe<string, Guid>((value) => string.IsNullOrEmpty(value) ? default(Guid) : Guid.Parse(value));
RegisterUnsafe<string, Uuid128>((value) => string.IsNullOrEmpty(value) ? default(Uuid128) : Uuid128.Parse(value));
RegisterUnsafe<string, Uuid64>((value) => string.IsNullOrEmpty(value) ? default(Uuid64) : Uuid64.Parse(value));
RegisterUnsafe<string, System.Net.IPAddress>((value) => string.IsNullOrEmpty(value) ? default(System.Net.IPAddress) : System.Net.IPAddress.Parse(value));
RegisterUnsafe<byte[], Slice>((value) => Slice.Create(value));
RegisterUnsafe<byte[], string>((value) => value == null ? default(string) : value.Length == 0 ? String.Empty : System.Convert.ToBase64String(value));
RegisterUnsafe<byte[], bool>((value) => value != null && value.Length > 0);
RegisterUnsafe<byte[], sbyte>((value) => value == null ? default(sbyte) : Slice.Create(value).ToSByte());
RegisterUnsafe<byte[], byte>((value) => value == null ? default(byte) : Slice.Create(value).ToByte());
RegisterUnsafe<byte[], short>((value) => value == null ? default(short) : Slice.Create(value).ToInt16());
RegisterUnsafe<byte[], ushort>((value) => value == null ? default(ushort) : Slice.Create(value).ToUInt16());
RegisterUnsafe<byte[], int>((value) => value == null ? 0 : Slice.Create(value).ToInt32());
RegisterUnsafe<byte[], uint>((value) => value == null ? 0U : Slice.Create(value).ToUInt32());
RegisterUnsafe<byte[], long>((value) => value == null ? 0L : Slice.Create(value).ToInt64());
RegisterUnsafe<byte[], ulong>((value) => value == null ? 0UL : Slice.Create(value).ToUInt64());
RegisterUnsafe<byte[], Guid>((value) => value == null || value.Length == 0 ? default(Guid) : new Uuid128(value).ToGuid());
RegisterUnsafe<byte[], Uuid128>((value) => value == null || value.Length == 0 ? default(Uuid128) : new Uuid128(value));
RegisterUnsafe<byte[], Uuid64>((value) => value == null || value.Length == 0 ? default(Uuid64) : new Uuid64(value));
RegisterUnsafe<byte[], TimeSpan>((value) => value == null ? TimeSpan.Zero : TimeSpan.FromTicks(Slice.Create(value).ToInt64()));
RegisterUnsafe<byte[], System.Net.IPAddress>((value) => value == null || value.Length == 0 ? default(System.Net.IPAddress) : new System.Net.IPAddress(value));
RegisterUnsafe<Guid, Slice>((value) => Slice.FromGuid(value));
RegisterUnsafe<Guid, byte[]>((value) => Slice.FromGuid(value).GetBytes());
RegisterUnsafe<Guid, string>((value) => value.ToString("D", null));
RegisterUnsafe<Guid, Uuid128>((value) => new Uuid128(value));
RegisterUnsafe<Guid, bool>((value) => value != Guid.Empty);
RegisterUnsafe<Guid, System.Net.IPAddress>((value) => new System.Net.IPAddress(new Uuid128(value).ToByteArray()));
RegisterUnsafe<Uuid128, Slice>((value) => value.ToSlice());
RegisterUnsafe<Uuid128, byte[]>((value) => value.ToByteArray());
RegisterUnsafe<Uuid128, string>((value) => value.ToString("D", null));
RegisterUnsafe<Uuid128, Guid>((value) => value.ToGuid());
RegisterUnsafe<Uuid128, bool>((value) => value != Uuid128.Empty);
RegisterUnsafe<Guid, System.Net.IPAddress>((value) => new System.Net.IPAddress(value.ToByteArray()));
RegisterUnsafe<Uuid64, Slice>((value) => value.ToSlice());
RegisterUnsafe<Uuid64, byte[]>((value) => value.ToByteArray());
RegisterUnsafe<Uuid64, string>((value) => value.ToString("D", null));
RegisterUnsafe<Uuid64, long>((value) => value.ToInt64());
RegisterUnsafe<Uuid64, ulong>((value) => value.ToUInt64());
RegisterUnsafe<Uuid64, bool>((value) => value.ToInt64() != 0L);
RegisterUnsafe<TimeSpan, Slice>((value) => Slice.FromInt64(value.Ticks));
RegisterUnsafe<TimeSpan, byte[]>((value) => Slice.FromInt64(value.Ticks).GetBytes());
RegisterUnsafe<TimeSpan, long>((value) => value.Ticks);
RegisterUnsafe<TimeSpan, ulong>((value) => checked((ulong)value.Ticks));
RegisterUnsafe<TimeSpan, double>((value) => value.TotalSeconds);
RegisterUnsafe<TimeSpan, bool>((value) => value == TimeSpan.Zero);
RegisterUnsafe<System.Net.IPAddress, Slice>((value) => value != null ? Slice.Create(value.GetAddressBytes()) : Slice.Nil);
RegisterUnsafe<System.Net.IPAddress, byte[]>((value) => value != null ? value.GetAddressBytes() : null);
RegisterUnsafe<System.Net.IPAddress, string>((value) => value != null ? value.ToString() : null);
RegisterUnsafe<FdbTupleAlias, byte>((value) => (byte)value);
RegisterUnsafe<FdbTupleAlias, int>((value) => (int)value);
RegisterUnsafe<FdbTupleAlias, Slice>((value) => Slice.FromByte((byte)value));
//REVIEW: this should go in the Tuples layer !
RegisterUnsafe<Slice, byte[]>((value) => value.GetBytes());
RegisterUnsafe<Slice, string>((value) => value.ToUnicode());
RegisterUnsafe<Slice, bool>((value) => value.ToBool());
RegisterUnsafe<Slice, sbyte>((value) => value.ToSByte());
RegisterUnsafe<Slice, byte>((value) => value.ToByte());
RegisterUnsafe<Slice, short>((value) => value.ToInt16());
RegisterUnsafe<Slice, ushort>((value) => value.ToUInt16());
RegisterUnsafe<Slice, int>((value) => value.ToInt32());
RegisterUnsafe<Slice, uint>((value) => value.ToUInt32());
RegisterUnsafe<Slice, long>((value) => value.ToInt64());
RegisterUnsafe<Slice, ulong>((value) => value.ToUInt64());
RegisterUnsafe<Slice, Guid>((value) => value.ToGuid());
RegisterUnsafe<Slice, Uuid128>((value) => value.ToUuid128());
RegisterUnsafe<Slice, Uuid64>((value) => value.ToUuid64());
RegisterUnsafe<Slice, TimeSpan>((value) => TimeSpan.FromTicks(value.ToInt64()));
RegisterUnsafe<Slice, FdbTupleAlias>((value) => (FdbTupleAlias)value.ToByte());
RegisterUnsafe<Slice, System.Net.IPAddress>((value) => !value.IsNullOrEmpty ? new System.Net.IPAddress(value.GetBytes()) : null);
}
19
View Source File : FdbTupleParser.cs
License : MIT License
Project Creator : abdullin
License : MIT License
Project Creator : abdullin
public static void WriteDouble(ref TupleWriter writer, double value)
{
// The double is converted to its Big-Endian IEEE binary representation
// - If the sign bit is set, flip all the bits
// - If the sign bit is not set, just flip the sign bit
// This ensures that all negative numbers have their first byte < 0x80, and all positive numbers have their first byte >= 0x80
// Special case for NaN: All variants are normalized to float.NaN !
if (double.IsNaN(value)) value = double.NaN;
// note: we could use BitConverter.DoubleToInt64Bits(...), but it does the same thing, and also it does not exist for floats...
ulong bits;
unsafe { bits = *((ulong*)&value); }
if ((bits & 0x8000000000000000UL) != 0)
{ // negative
bits = ~bits;
}
else
{ // postive
bits |= 0x8000000000000000UL;
}
writer.Output.EnsureBytes(9);
var buffer = writer.Output.Buffer;
int p = writer.Output.Position;
buffer[p] = FdbTupleTypes.Double;
buffer[p + 1] = (byte)(bits >> 56);
buffer[p + 2] = (byte)(bits >> 48);
buffer[p + 3] = (byte)(bits >> 40);
buffer[p + 4] = (byte)(bits >> 32);
buffer[p + 5] = (byte)(bits >> 24);
buffer[p + 6] = (byte)(bits >> 16);
buffer[p + 7] = (byte)(bits >> 8);
buffer[p + 8] = (byte)(bits);
writer.Output.Position = p + 9;
}
19
View Source File : CreateRealTime3DUniformMeshChart.xaml.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void OnStart()
{
if (!IsLoaded) return;
string whatData = (string)DataCombo.SelectedItem;
int w = 0, h = 0;
if (whatData == "3D Sinc 10 x 10") w = h = 10;
if (whatData == "3D Sinc 50 x 50") w = h = 50;
if (whatData == "3D Sinc 100 x 100") w = h = 100;
if (whatData == "3D Sinc 500 x 500") w = h = 500;
if (whatData == "3D Sinc 1k x 1k") w = h = 1000;
lock (_syncRoot)
{
OnStop();
}
var dataSeries = new UniformGridDataSeries3D<double>(w, h)
{
StartX = 0,
StartZ = 0,
StepX = 10 / (w - 1d),
StepZ = 10 / (h - 1d),
SeriesName = "Realtime Surface Mesh",
};
var frontBuffer = dataSeries.InternalArray;
var backBuffer = new GridData<double>(w, h).InternalArray;
int frames = 0;
_timer = new Timer();
_timer.Interval = 20;
_timer.Elapsed += (s, arg) =>
{
lock (_syncRoot)
{
double wc = w*0.5, hc = h*0.5;
double freq = Math.Sin(frames++*0.1)*0.1 + 0.1;
// Each set of dataSeries[i,j] schedules a redraw when the next Render event fires. Therefore, we suspend updates so that we can update the chart once
// Data generation (Sin, Sqrt below) is expensive. We parallelize it by using Parallel.For for the outer loop
// Equivalent of "for (int j = 0; j < h; j++)"
// This will result in more CPU usage, but we wish to demo the performance of the actual rendering, not the slowness of generating test data! :)
Parallel.For(0, h, i =>
{
var buf = frontBuffer;
for (int j = 0; j < w; j++)
{
// 3D Sinc function from http://www.mathworks.com/matlabcentral/cody/problems/1305-creation-of-2d-sinc-surface
// sin(pi*R*freq)/(pi*R*freq)
// R is distance from centre
double radius = Math.Sqrt((wc - i)*(wc - i) + (hc - j)*(hc - j));
var d = Math.PI*radius*freq;
var value = Math.Sin(d)/d;
buf[i][j] = double.IsNaN(value) ? 1.0 : value;
}
});
using (dataSeries.SuspendUpdates(false, true))
{
dataSeries.CopyFrom(frontBuffer);
var temp = backBuffer;
backBuffer = frontBuffer;
frontBuffer = temp;
}
}
};
SurfaceMesh.DataSeries = dataSeries;
_timer.Start();
StartButton.IsEnabled = false;
PauseButton.IsEnabled = true;
}
19
View Source File : CubicSpline.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public void Fit(double[] x, double[] y, double startSlope = double.NaN, double endSlope = double.NaN, bool debug = false)
{
if (Double.IsInfinity(startSlope) || Double.IsInfinity(endSlope))
{
throw new Exception("startSlope and endSlope cannot be infinity.");
}
// Save x and y for eval
this.xOrig = x;
this.yOrig = y;
int n = x.Length;
double[] r = new double[n]; // the right hand side numbers: wikipedia page overloads b
TriDiagonalMatrixF m = new TriDiagonalMatrixF(n);
double dx1, dx2, dy1, dy2;
// First row is different (equation 16 from the article)
if (double.IsNaN(startSlope))
{
dx1 = x[1] - x[0];
m.C[0] = 1.0f / dx1;
m.B[0] = 2.0f * m.C[0];
r[0] = 3 * (y[1] - y[0]) / (dx1 * dx1);
}
else
{
m.B[0] = 1;
r[0] = startSlope;
}
// Body rows (equation 15 from the article)
for (int i = 1; i < n - 1; i++)
{
dx1 = x[i] - x[i - 1];
dx2 = x[i + 1] - x[i];
m.A[i] = 1.0f / dx1;
m.C[i] = 1.0f / dx2;
m.B[i] = 2.0f * (m.A[i] + m.C[i]);
dy1 = y[i] - y[i - 1];
dy2 = y[i + 1] - y[i];
r[i] = 3 * (dy1 / (dx1 * dx1) + dy2 / (dx2 * dx2));
}
// Last row also different (equation 17 from the article)
if (double.IsNaN(endSlope))
{
dx1 = x[n - 1] - x[n - 2];
dy1 = y[n - 1] - y[n - 2];
m.A[n - 1] = 1.0f / dx1;
m.B[n - 1] = 2.0f * m.A[n - 1];
r[n - 1] = 3 * (dy1 / (dx1 * dx1));
}
else
{
m.B[n - 1] = 1;
r[n - 1] = endSlope;
}
// if (debug) Console.WriteLine("Tri-diagonal matrix:\n{0}", m.ToDisplayString(":0.0000", " "));
// if (debug) Console.WriteLine("r: {0}", ArrayUtil.ToString<double>(r));
// k is the solution to the matrix
double[] k = m.Solve(r);
// if (debug) Console.WriteLine("k = {0}", ArrayUtil.ToString<double>(k));
// a and b are each spline's coefficients
this.a = new double[n - 1];
this.b = new double[n - 1];
for (int i = 1; i < n; i++)
{
dx1 = x[i] - x[i - 1];
dy1 = y[i] - y[i - 1];
a[i - 1] = k[i - 1] * dx1 - dy1; // equation 10 from the article
b[i - 1] = -k[i] * dx1 + dy1; // equation 11 from the article
}
// if (debug) Console.WriteLine("a: {0}", ArrayUtil.ToString<double>(a));
// if (debug) Console.WriteLine("b: {0}", ArrayUtil.ToString<double>(b));
}
19
View Source File : EEGExampleView.xaml.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void CompositionTarget_Rendering(object sender, EventArgs e)
{
if (StopButton.IsChecked != true && ResetButton.IsChecked != true)
{
// Compute the render time
double frameTime = _stopWatch.ElapsedMilliseconds;
double delta = frameTime - _lastFrameTime;
double fps = 1000.0 / delta;
// Push the fps to the movingaverage, we want to average the FPS to get a more reliable reading
_fpsAverage.Push(fps);
// Render the fps to the screen
fpsCounter.Text = double.IsNaN(_fpsAverage.Current) ? "-" : string.Format("{0:0}", _fpsAverage.Current);
// Render the total point count (all series) to the screen
var eegExampleViewModel = (DataContext as EEGExampleViewModel);
pointCount.Text = eegExampleViewModel != null ? eegExampleViewModel.PointCount.ToString() : "Na";
_lastFrameTime = frameTime;
}
}
19
View Source File : Victim.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public sealed override void CalculateTarget()
{
Point aggressorPos = Aggressor.Pos;
Point defenderPos = Defender.Pos;
Point threatAxis = new Point((aggressorPos.X - Pos.X), (aggressorPos.Y - Pos.Y));
Point flightAxis = new Point(-threatAxis.Y, threatAxis.X); // 90 degrees to Threat
double length = Math.Sqrt(flightAxis.X * flightAxis.X + flightAxis.Y * flightAxis.Y);
if (length == 0 || defenderPos == aggressorPos)
{
Target = defenderPos;
}
else
{
Point safeVector = new Point((defenderPos.X - aggressorPos.X), (defenderPos.Y - aggressorPos.Y));
double denom = (flightAxis.X*safeVector.Y - flightAxis.Y*safeVector.X);
double q = denom == 0 ? 1 : (safeVector.X*threatAxis.Y - safeVector.Y*threatAxis.X)/denom;
if (q < 1 || double.IsNaN(q))
{
q = 1; // Make sure we're at least *behind* the defender, rather than just in line
}
Target = new Point(Pos.X + q * flightAxis.X, Pos.Y + q*flightAxis.Y);
}
}
19
View Source File : RealTimePerformanceDemoView.xaml.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void OnSciChartRendered(object sender, EventArgs e)
{
// Compute the render time
double frameTime = _stopWatch.ElapsedMilliseconds;
double delta = frameTime - _lastFrameTime;
double fps = 1000.0 / delta;
double fpsAverageBefore = _fpsAverage.Current;
// Push the fps to the movingaverage, we want to average the FPS to get a more reliable reading
if (!double.IsInfinity(fps))
{
_fpsAverage.Push(fps);
}
double fpsAverageAfter = _fpsAverage.Current;
// Render the fps to the screen
if (Math.Abs(fpsAverageAfter - fpsAverageBefore) >= 0.1)
FpsCounter.Text = double.IsNaN(_fpsAverage.Current) ? "-" : string.Format("{0:0}", _fpsAverage.Current);
// Render the total point count (all series) to the screen
int numPoints = 3 * _mainSeries.Count;
PointCount.Text = string.Format("{0:n0}", numPoints);
if (numPoints > MaxCount)
{
this.PauseButton_Click(this, null);
}
_lastFrameTime = frameTime;
}
19
View Source File : MovingAverage.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public static IEnumerable<MacdPoint> Macd(this IEnumerable<double> inputStream, int slow, int fast, int signal)
{
var maSlow = new MovingAverage(slow);
var maFast = new MovingAverage(fast);
var maSignal = new MovingAverage(signal);
foreach (var item in inputStream)
{
double macd = maSlow.Push(item).Current - maFast.Push(item).Current;
double signalLine = double.IsNaN(macd) ? double.NaN : maSignal.Push(macd).Current;
double divergence = double.IsNaN(macd) || double.IsNaN(signalLine) ? double.NaN : macd - signalLine;
yield return new MacdPoint() { Macd = macd, Signal = signalLine, Divergence = divergence };
}
}
19
View Source File : MovingAverage.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public static IEnumerable<double> Rsi(this IEnumerable<PriceBar> inputStream, int period)
{
var averageGain = new MovingAverage(period);
var averageLoss = new MovingAverage(period);
var previous = inputStream.First();
foreach (var item in inputStream)
{
double gain = item.Close > previous.Close ? item.Close - previous.Close : 0.0;
double loss = previous.Close > item.Close ? previous.Close - item.Close : 0.0;
averageGain.Push(gain);
averageLoss.Push(loss);
double relativeStrength = double.IsNaN(averageGain.Current) || double.IsNaN(averageLoss.Current) ? double.NaN : averageGain.Current/averageLoss.Current;
previous = item;
yield return double.IsNaN(relativeStrength) ? double.NaN : 100.0 - (100.0/(1.0 + relativeStrength));
}
}
19
View Source File : MovingAverage.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public MovingAverage Update(double value)
{
double lostValue = _circularBuffer[_circIndex];
_circularBuffer[_circIndex] = value;
// Maintain totals for Push function
// skip NaN
_total += double.IsNaN(value) ? 0d :value;
_total -= lostValue;
// If not yet filled, just return. Current value should be double.NaN
if (!_filled)
{
_current = double.NaN;
return this;
}
// Compute the average
double average = 0.0;
for (int i = 0; i < _circularBuffer.Length; i++)
{
average += _circularBuffer[i];
}
_current = average * _oneOverLength;
return this;
}
19
View Source File : MovingAverage.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public MovingAverage Push(double value)
{
// Apply the circular buffer
if (++_circIndex == _length)
{
_circIndex = 0;
}
double lostValue = _circularBuffer[_circIndex];
_circularBuffer[_circIndex] = value;
// Compute the average
// Skip NaN
_total += double.IsNaN(value) ? 0d : value;
_total -= lostValue;
// If not yet filled, just return. Current value should be double.NaN
if (!_filled && _circIndex != _length -1)
{
_current = double.NaN;
return this;
}
else
{
// Set a flag to indicate this is the first time the buffer has been filled
_filled = true;
}
_current = _total * _oneOverLength;
return this;
}
19
View Source File : MovingAverage.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public static IEnumerable<double> Rsi(this IEnumerable<PriceBar> inputStream, int period)
{
var averageGain = new MovingAverage(period);
var averageLoss = new MovingAverage(period);
var previous = inputStream.First();
foreach (var item in inputStream.Skip(1))
{
double gain = item.Close > previous.Close ? item.Close - previous.Close : 0.0;
double loss = previous.Close > item.Close ? previous.Close - item.Close : 0.0;
averageGain.Push(gain);
averageLoss.Push(loss);
double relativeStrength = double.IsNaN(averageGain.Current) || double.IsNaN(averageLoss.Current) ? double.NaN : averageGain.Current / averageLoss.Current;
previous = item;
yield return double.IsNaN(relativeStrength) ? double.NaN : 100.0 - (100.0 / (1.0 + relativeStrength));
}
}
19
View Source File : MovingAverage.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public MovingAverage Update(double value)
{
double lostValue = _circularBuffer[_circIndex];
_circularBuffer[_circIndex] = value;
// Maintain totals for Push function
// skip NaN
_total += double.IsNaN(value) ? 0d : value;
_total -= lostValue;
// If not yet filled, just return. Current value should be double.NaN
if (!_filled)
{
_current = double.NaN;
return this;
}
// Compute the average
double average = 0.0;
for (int i = 0; i < _circularBuffer.Length; i++)
{
average += _circularBuffer[i];
}
_current = average * _oneOverLength;
return this;
}
19
View Source File : MovingAverage.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public MovingAverage Push(double value)
{
// Apply the circular buffer
if (++_circIndex == _length)
{
_circIndex = 0;
}
double lostValue = _circularBuffer[_circIndex];
_circularBuffer[_circIndex] = value;
// Compute the average
// Skip NaN
_total += double.IsNaN(value) ? 0d : value;
_total -= lostValue;
// If not yet filled, just return. Current value should be double.NaN
if (!_filled && _circIndex != _length - 1)
{
_current = double.NaN;
return this;
}
else
{
// Set a flag to indicate this is the first time the buffer has been filled
_filled = true;
}
_current = _total * _oneOverLength;
return this;
}
19
View Source File : ActionChain.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public ActionChain AddDelaySeconds(double timeInSeconds)
{
if (Double.IsNaN(timeInSeconds))
{
Console.WriteLine("WARNING: ActionChain.AddDelaySeconds(" + timeInSeconds + ")");
return this;
}
if (timeInSeconds <= 0)
return this;
AddAction(WorldManager.DelayManager, new DelayAction(timeInSeconds));
return this;
}
19
View Source File : Creature_Navigation.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static float GetAngle(Vector3 dir)
{
var rads = Math.Atan2(dir.Y, dir.X);
if (double.IsNaN(rads)) return 0.0f;
var angle = rads * 57.2958f;
return (float)angle;
}
19
View Source File : Creature_Navigation.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static float GetAngle(Vector3 a, Vector3 b)
{
var cosTheta = a.Dot2D(b);
var rads = Math.Acos(cosTheta);
if (double.IsNaN(rads)) return 0.0f;
var angle = rads * (180.0f / Math.PI);
return (float)angle;
}
19
View Source File : EvaluationResult.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
private static Boolean AbstractEqual(
Object canonicalLeftValue,
Object canonicalRightValue)
{
CoerceTypes(ref canonicalLeftValue, ref canonicalRightValue, out var leftKind, out var rightKind);
// Same kind
if (leftKind == rightKind)
{
switch (leftKind)
{
// Null, Null
case ValueKind.Null:
return true;
// Number, Number
case ValueKind.Number:
var leftDouble = (Double)canonicalLeftValue;
var rightDouble = (Double)canonicalRightValue;
if (Double.IsNaN(leftDouble) || Double.IsNaN(rightDouble))
{
return false;
}
return leftDouble == rightDouble;
// String, String
case ValueKind.String:
var leftString = (String)canonicalLeftValue;
var rightString = (String)canonicalRightValue;
return String.Equals(leftString, rightString, StringComparison.OrdinalIgnoreCase);
// Boolean, Boolean
case ValueKind.Boolean:
var leftBoolean = (Boolean)canonicalLeftValue;
var rightBoolean = (Boolean)canonicalRightValue;
return leftBoolean == rightBoolean;
// Object, Object
case ValueKind.Object:
case ValueKind.Array:
return Object.ReferenceEquals(canonicalLeftValue, canonicalRightValue);
}
}
return false;
}
19
View Source File : EvaluationResult.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
private static Boolean AbstractGreaterThan(
Object canonicalLeftValue,
Object canonicalRightValue)
{
CoerceTypes(ref canonicalLeftValue, ref canonicalRightValue, out var leftKind, out var rightKind);
// Same kind
if (leftKind == rightKind)
{
switch (leftKind)
{
// Number, Number
case ValueKind.Number:
var leftDouble = (Double)canonicalLeftValue;
var rightDouble = (Double)canonicalRightValue;
if (Double.IsNaN(leftDouble) || Double.IsNaN(rightDouble))
{
return false;
}
return leftDouble > rightDouble;
// String, String
case ValueKind.String:
var leftString = (String)canonicalLeftValue;
var rightString = (String)canonicalRightValue;
return String.Compare(leftString, rightString, StringComparison.OrdinalIgnoreCase) > 0;
// Boolean, Boolean
case ValueKind.Boolean:
var leftBoolean = (Boolean)canonicalLeftValue;
var rightBoolean = (Boolean)canonicalRightValue;
return leftBoolean && !rightBoolean;
}
}
return false;
}
19
View Source File : EvaluationResult.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
private static Boolean AbstractLessThan(
Object canonicalLeftValue,
Object canonicalRightValue)
{
CoerceTypes(ref canonicalLeftValue, ref canonicalRightValue, out var leftKind, out var rightKind);
// Same kind
if (leftKind == rightKind)
{
switch (leftKind)
{
// Number, Number
case ValueKind.Number:
var leftDouble = (Double)canonicalLeftValue;
var rightDouble = (Double)canonicalRightValue;
if (Double.IsNaN(leftDouble) || Double.IsNaN(rightDouble))
{
return false;
}
return leftDouble < rightDouble;
// String, String
case ValueKind.String:
var leftString = (String)canonicalLeftValue;
var rightString = (String)canonicalRightValue;
return String.Compare(leftString, rightString, StringComparison.OrdinalIgnoreCase) < 0;
// Boolean, Boolean
case ValueKind.Boolean:
var leftBoolean = (Boolean)canonicalLeftValue;
var rightBoolean = (Boolean)canonicalRightValue;
return !leftBoolean && rightBoolean;
}
}
return false;
}
19
View Source File : NumberContextData.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public override JToken ToJToken()
{
if (Double.IsNaN(m_value) || m_value == Double.PositiveInfinity || m_value == Double.NegativeInfinity)
{
return (JToken)m_value;
}
var floored = Math.Floor(m_value);
if (m_value == floored && m_value <= (Double)Int32.MaxValue && m_value >= (Double)Int32.MinValue)
{
var flooredInt = (Int32)floored;
return (JToken)flooredInt;
}
else if (m_value == floored && m_value <= (Double)Int64.MaxValue && m_value >= (Double)Int64.MinValue)
{
var flooredInt = (Int64)floored;
return (JToken)flooredInt;
}
else
{
return (JToken)m_value;
}
}
19
View Source File : PropertyValidation.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
private static void ValidateDouble(String propertyName, Double propertyValue)
{
if (Double.IsInfinity(propertyValue) || Double.IsNaN(propertyValue))
{
throw new VssPropertyValidationException("value", CommonResources.DoubleValueOutOfRange(propertyName, propertyValue));
}
// SQL Server support: - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308
if (propertyValue < s_minNegative ||
(propertyValue < 0 && propertyValue > s_maxNegative) ||
propertyValue > s_maxPositive ||
(propertyValue > 0 && propertyValue < s_minPositive))
{
throw new VssPropertyValidationException("value", CommonResources.DoubleValueOutOfRange(propertyName, propertyValue));
}
}
19
View Source File : LexicalAnalyzer.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
private Token ReadNumberToken()
{
var startIndex = m_index;
do
{
m_index++;
}
while (m_index < m_expression.Length && (!TestTokenBoundary(m_expression[m_index]) || m_expression[m_index] == '.'));
var length = m_index - startIndex;
var str = m_expression.Substring(startIndex, length);
var d = ExpressionUtility.ParseNumber(str);
if (Double.IsNaN(d))
{
return CreateToken(TokenKind.Unexpected, str, startIndex);
}
return CreateToken(TokenKind.Number, str, startIndex, d);
}
19
View Source File : IExpressionNodeExtensions.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
private static void Match(
IExpressionNode node,
Stack<IExpressionNode>[] patterns,
Boolean[] result)
{
var nodeSegments = GetMatchSegments(node);
if (nodeSegments.Count == 0)
{
return;
}
var nodeNamedValue = nodeSegments.Peek() as NamedValue;
var originalNodeSegments = nodeSegments;
for (var i = 0; i < patterns.Length; i++)
{
var patternSegments = patterns[i];
var patternNamedValue = patternSegments.Peek() as NamedValue;
// Compare the named-value
if (String.Equals(nodeNamedValue.Name, patternNamedValue.Name, StringComparison.OrdinalIgnoreCase))
{
// Clone the stacks before mutating
nodeSegments = new Stack<IExpressionNode>(originalNodeSegments.Reverse());
nodeSegments.Pop();
patternSegments = new Stack<IExpressionNode>(patternSegments.Reverse());
patternSegments.Pop();
// Walk the stacks
while (true)
{
// Every pattern segment was matched
if (patternSegments.Count == 0)
{
result[i] = true;
break;
}
// Every node segment was matched. Treat the pattern as matched. There is not
// enough information to determine whether the property is required; replacedume it is.
// For example, consider the pattern "github.event" and the expression "toJson(github)".
// In this example the function requires the full structure of the named-value.
else if (nodeSegments.Count == 0)
{
result[i] = true;
break;
}
var nodeSegment = nodeSegments.Pop();
var patternSegment = patternSegments.Pop();
// The behavior of a wildcard varies depending on whether the left operand
// is an array or an object. For simplicity, treat the pattern as matched.
if (nodeSegment is Wildcard)
{
result[i] = true;
break;
}
// Treat a wildcard pattern segment as matching any literal segment
else if (patternSegment is Wildcard)
{
continue;
}
// Convert literals to string and compare
var nodeLiteral = nodeSegment as Literal;
var nodeEvaluationResult = EvaluationResult.CreateIntermediateResult(null, nodeLiteral.Value);
var nodeString = nodeEvaluationResult.ConvertToString();
var patternLiteral = patternSegment as Literal;
var patternEvaluationResult = EvaluationResult.CreateIntermediateResult(null, patternLiteral.Value);
var patternString = patternEvaluationResult.ConvertToString();
if (String.Equals(nodeString, patternString, StringComparison.OrdinalIgnoreCase))
{
continue;
}
// Convert to number and compare
var nodeNumber = nodeEvaluationResult.ConvertToNumber();
if (!Double.IsNaN(nodeNumber) && nodeNumber >= 0d && nodeNumber <= (Double)Int32.MaxValue)
{
var patternNumber = patternEvaluationResult.ConvertToNumber();
if (!Double.IsNaN(patternNumber) && patternNumber >= 0 && patternNumber <= (Double)Int32.MaxValue)
{
nodeNumber = Math.Floor(nodeNumber);
patternNumber = Math.Floor(patternNumber);
if (nodeNumber == patternNumber)
{
continue;
}
}
}
// Not matched
break;
}
}
}
}
19
View Source File : ToolbarManager.cs
License : GNU General Public License v3.0
Project Creator : Adam-Wilkinson
License : GNU General Public License v3.0
Project Creator : Adam-Wilkinson
public void UpdatePositions(Rect bounds)
{
double width = double.IsNaN(grip.Width) ? 0.0 : grip.Width;
grip.RenderTransformOrigin = new RelativePoint(new Point(0, 0), RelativeUnit.Relative);
if (Orientation == Orientation.Vertical)
{
grip.RenderTransform = new MatrixTransform(MatrixHelper.Rotation(Math.PI / 2, new Vector(bounds.Width / 2, bounds.Width / 2)));
grip.Arrange(new Rect(bounds.X, bounds.Y, width, bounds.Width));
childToolbar?.Arrange(new Rect(bounds.X, bounds.Y + width, bounds.Width, Math.Max(0.0, bounds.Height - width)));
}
else
{
grip.RenderTransform = new MatrixTransform(MatrixHelper.Rotation(0));
grip.Arrange(new Rect(bounds.X, bounds.Y, width, bounds.Height));
childToolbar?.Arrange(new Rect(bounds.X + width, bounds.Y, Math.Max(0.0, bounds.Width - width), bounds.Height));
}
}
19
View Source File : VideoPlayerRenderer.cs
License : MIT License
Project Creator : adamfisher
License : MIT License
Project Creator : adamfisher
private async Task UpdateSource(VideoPlayer oldElement = null)
{
try
{
var newSource = Element?.Source;
if (oldElement != null)
{
var oldSource = oldElement.Source;
if (!oldSource.Equals(newSource))
return;
}
Element.SetValue(VideoPlayer.IsLoadingPropertyKey, true);
var videoSourceHandler = VideoSourceHandler.Create(newSource);
var path = await videoSourceHandler.LoadVideoAsync(newSource, new CancellationToken());
Log.Info($"Video Source: {path}");
if (!string.IsNullOrEmpty(path))
{
if (_currentTimeObserver != null)
_playerControl.Player.RemoveTimeObserver(_currentTimeObserver);
if (_didPlayToEndTimeNotificationObserver != null)
NSNotificationCenter.DefaultCenter.RemoveObserver(_didPlayToEndTimeNotificationObserver);
// Update video source.
Element.SetValue(VideoPlayer.CurrentTimePropertyKey, TimeSpan.Zero);
var pathUrl = newSource is UriVideoSource ? NSUrl.FromString(path) : NSUrl.FromFilename(path);
_playerControl.Player.Currenreplacedem?.RemoveObserver(FromObject(this), "status");
_playerControl.Player.ReplaceCurrenreplacedemWithPlayerItem(AVPlayerItem.FromUrl(pathUrl));
_playerControl.Player.Currenreplacedem.AddObserver(this, (NSString)"status", 0, Handle);
Element.OnPlayerStateChanged(CreateVideoPlayerStateChangedEventArgs(PlayerState.Initialized));
_didPlayToEndTimeNotificationObserver = NSNotificationCenter.DefaultCenter.AddObserver(
AVPlayerItem.DidPlayToEndTimeNotification, DidPlayToEndTimeNotification, _playerControl.Player.Currenreplacedem);
_currentTimeObserver = _playerControl.Player.AddPeriodicTimeObserver(CMTime.FromSeconds(1, 1), null,
time => Element?.SetValue(VideoPlayer.CurrentTimePropertyKey,
double.IsNaN(time.Seconds) ? TimeSpan.Zero : TimeSpan.FromSeconds(time.Seconds)));
}
}
catch(Exception ex)
{
Log.Error(ex);
Element.SetValue(VideoPlayer.IsLoadingPropertyKey, false);
}
}
19
View Source File : VideoPlayerRenderer.cs
License : MIT License
Project Creator : adamfisher
License : MIT License
Project Creator : adamfisher
private VideoPlayerEventArgs CreateVideoPlayerEventArgs()
{
var playerItem = _playerControl.Player.Currenreplacedem;
if (playerItem != null)
{
var currentTime = !double.IsNaN(playerItem.CurrentTime.Seconds) ? playerItem.CurrentTime.Seconds : 0;
var duration = !double.IsNaN(playerItem.Duration.Seconds) ? playerItem.Duration.Seconds : 0;
return new VideoPlayerEventArgs(
TimeSpan.FromSeconds(currentTime),
TimeSpan.FromSeconds(duration),
_playerControl.Player.Rate
);
}
return null;
}
19
View Source File : ValidateHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static bool IsInRangeOfDouble(object value)
{
var v = (double)value;
return !(double.IsNaN(v) || double.IsInfinity(v));
}
19
View Source File : ValidateHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static bool IsInRangeOfNegDouble(object value, bool includeZero = false)
{
var v = (double)value;
return !(double.IsNaN(v) || double.IsInfinity(v)) && (includeZero ? v <= 0 : v < 0);
}
19
View Source File : ValidateHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static bool IsInRangeOfPosDoubleIncludeZero(object value)
{
var v = (double)value;
return !(double.IsNaN(v) || double.IsInfinity(v)) && v >= 0;
}
19
View Source File : AduTimeSelector.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
private void CreateExtraItem(ObservableCollection<AduTimeButton> list)
{
double height = this.ItemHeight;
if (this.Owner != null)
{
height = this.Owner.DropDownHeight;
}
else
{
height = double.IsNaN(this.Height) ? height : this.Height;
}
for (int i = 0; i < (height - this.ItemHeight) / this.ItemHeight; i++)
{
AduTimeButton timeButton = new AduTimeButton();
timeButton.SetValue(AduTimeButton.HeightProperty, this.ItemHeight);
timeButton.SetValue(AduTimeButton.IsEnabledProperty, false);
timeButton.SetValue(AduTimeButton.IsSelectedProperty, false);
list.Add(timeButton);
}
}
19
View Source File : HCTimeBarNew.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
private void Update()
{
if (_canvreplacedpe == null) return;
_speBlockList.Clear();
_canvreplacedpe.Children.Clear();
_speCount = (int)(ActualWidth / 800 * 9) | 1;
var itemWidthOld = _itemWidth;
_itemWidth = ActualWidth / _speCount;
_totalOffsetX = _itemWidth / itemWidthOld * _totalOffsetX % ActualWidth;
if (double.IsNaN(_totalOffsetX))
{
_totalOffsetX = 0;
}
var rest = (_totalOffsetX + _tempOffsetX) % _itemWidth;
var sub = rest <= 0 || double.IsNaN(rest) ? _speCount / 2 : _speCount / 2 - 1;
for (var i = 0; i < _speCount; i++)
{
var block = new HCSpeTextBlock
{
Time = TimeConvert(SelectedTime).AddMilliseconds((i - sub) * _timeSpeList[_speIndex]),
TextAlignment = TextAlignment.Center,
TimeFormat = "HH:mm"
};
_speBlockList.Add(block);
_canvreplacedpe.Children.Add(block);
}
if (_speIndex == 6)
{
SetSpeTimeFormat("HH:mm:ss");
}
ShowSpeStr = ActualWidth > 320;
for (var i = 0; i < _speCount; i++)
{
var item = _speBlockList[i];
item.X = _itemWidth * i;
item.MoveX((_itemWidth - item.Width) / 2);
}
UpdateSpeBlock();
UpdateMouseFollowBlockPos();
}
19
View Source File : ValidateHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static bool IsInRangeOfPosDouble(object value, bool includeZero = false)
{
var v = (double)value;
return !(double.IsNaN(v) || double.IsInfinity(v)) && (includeZero ? v >= 0 : v > 0);
}
19
View Source File : ArithmeticHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static Point CalSafePoint(FrameworkElement element, FrameworkElement showElement, Thickness thickness = default(Thickness))
{
if (element == null || showElement == null) return default(Point);
var point = element.PointToScreen(new Point(0, 0));
if (point.X < 0) point.X = 0;
if (point.Y < 0) point.Y = 0;
var maxLeft = SystemParameters.WorkArea.Width -
((double.IsNaN(showElement.Width) ? showElement.ActualWidth : showElement.Width) +
thickness.Left + thickness.Right);
var maxTop = SystemParameters.WorkArea.Height -
((double.IsNaN(showElement.Height) ? showElement.ActualHeight : showElement.Height) +
thickness.Top + thickness.Bottom);
return new Point(maxLeft > point.X ? point.X : maxLeft, maxTop > point.Y ? point.Y : maxTop);
}
19
View Source File : ArithmeticHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static Rect GetLayoutRect(FrameworkElement element)
{
var num1 = element.ActualWidth;
var num2 = element.ActualHeight;
if (element is Image || element is MediaElement)
if (element.Parent is Canvas)
{
num1 = double.IsNaN(element.Width) ? num1 : element.Width;
num2 = double.IsNaN(element.Height) ? num2 : element.Height;
}
else
{
num1 = element.RenderSize.Width;
num2 = element.RenderSize.Height;
}
var width = element.Visibility == Visibility.Collapsed ? 0.0 : num1;
var height = element.Visibility == Visibility.Collapsed ? 0.0 : num2;
var margin = element.Margin;
var layoutSlot = LayoutInformation.GetLayoutSlot(element);
var x = 0.0;
var y = 0.0;
switch (element.HorizontalAlignment)
{
case HorizontalAlignment.Left:
x = layoutSlot.Left + margin.Left;
break;
case HorizontalAlignment.Center:
x = (layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - width / 2.0;
break;
case HorizontalAlignment.Right:
x = layoutSlot.Right - margin.Right - width;
break;
case HorizontalAlignment.Stretch:
x = Math.Max(layoutSlot.Left + margin.Left,
(layoutSlot.Left + margin.Left + layoutSlot.Right - margin.Right) / 2.0 - width / 2.0);
break;
}
switch (element.VerticalAlignment)
{
case VerticalAlignment.Top:
y = layoutSlot.Top + margin.Top;
break;
case VerticalAlignment.Center:
y = (layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - height / 2.0;
break;
case VerticalAlignment.Bottom:
y = layoutSlot.Bottom - margin.Bottom - height;
break;
case VerticalAlignment.Stretch:
y = Math.Max(layoutSlot.Top + margin.Top,
(layoutSlot.Top + margin.Top + layoutSlot.Bottom - margin.Bottom) / 2.0 - height / 2.0);
break;
}
return new Rect(x, y, width, height);
}
19
View Source File : ArithmeticHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static bool IsValidDoubleValue(object value)
{
var d = (double)value;
if (!double.IsNaN(d))
return !double.IsInfinity(d);
return false;
}
19
View Source File : FluidMoveBehavior.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
private static bool IsEmptyRect(Rect rect)
{
if (!rect.IsEmpty && !double.IsNaN(rect.Left)) return double.IsNaN(rect.Top);
return true;
}
19
View Source File : MouseDragElementBehavior.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
private void UpdatePosition(Point point)
{
if (!_settingPosition && replacedociatedObject != null)
{
var transformOffset = GetTransformOffset(replacedociatedObject.TransformToVisual(RootElement));
var x = double.IsNaN(point.X) ? 0.0 : point.X - transformOffset.X;
var y = double.IsNaN(point.Y) ? 0.0 : point.Y - transformOffset.Y;
ApplyTranslation(x, y);
}
}
19
View Source File : MouseDragElementBehaviorEx.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
private void UpdatePosition(Point point)
{
if (_settingPosition || replacedociatedObject == null)
return;
var transformOffset = GetTransformOffset(replacedociatedObject.TransformToVisual(RootElement));
ApplyTranslation(double.IsNaN(point.X) ? 0.0 : point.X - transformOffset.X,
double.IsNaN(point.Y) ? 0.0 : point.Y - transformOffset.Y);
}
19
View Source File : MathHelper.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
public static bool IsFiniteDouble(double x) => !double.IsInfinity(x) && !double.IsNaN(x);
19
View Source File : HCTimeBarNew.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
private void UpdateMouseFollowBlockPos()
{
var p = Mouse.GetPosition(this);
var mlliseconds = (p.X - ActualWidth / 2) / _itemWidth * _timeSpeList[_speIndex];
if (double.IsNaN(mlliseconds) || double.IsInfinity(mlliseconds)) return;
_textBlockMove.Text = mlliseconds < 0
? (SelectedTime - TimeSpan.FromMilliseconds(-mlliseconds)).ToString(TimeFormat)
: (SelectedTime + TimeSpan.FromMilliseconds(mlliseconds)).ToString(TimeFormat);
_textBlockMove.Margin = new Thickness(p.X - _textBlockMove.ActualWidth / 2, 2, 0, 0);
}
19
View Source File : AngleBorder.cs
License : GNU General Public License v3.0
Project Creator : aduskin
License : GNU General Public License v3.0
Project Creator : aduskin
private void ArrangeChildRight(Thickness padding)
{
double x = padding.Left;
double y = padding.Top;
if (!Double.IsNaN(this.Height) && this.Height != 0)
{
y = (this.Height - (Child.DesiredSize.Height)) / 2;
}
Child.Arrange(new Rect(new Point(x, y), Child.DesiredSize));
}
19
View Source File : Familiar.cs
License : GNU General Public License v3.0
Project Creator : aedenthorn
License : GNU General Public License v3.0
Project Creator : aedenthorn
public override void MovePosition(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation)
{
lastPosition = base.Position;
if (xVelocity != 0f || yVelocity != 0f)
{
if (double.IsNaN((double)xVelocity) || double.IsNaN((double)yVelocity))
{
xVelocity = 0f;
yVelocity = 0f;
}
Microsoft.Xna.Framework.Rectangle nextPosition = GetBoundingBox();
nextPosition.X += (int)xVelocity;
nextPosition.Y -= (int)yVelocity;
if (!currentLocation.isCollidingPosition(nextPosition, viewport, false, DamageToFarmer, isGlider, this))
{
position.X += xVelocity;
position.Y -= yVelocity;
if (Slipperiness < 1000)
{
xVelocity -= xVelocity / (float)Slipperiness;
yVelocity -= yVelocity / (float)Slipperiness;
if (Math.Abs(xVelocity) <= 0.05f)
{
xVelocity = 0f;
}
if (Math.Abs(yVelocity) <= 0.05f)
{
yVelocity = 0f;
}
}
if (!isGlider && invincibleCountdown > 0)
{
slideAnimationTimer -= time.ElapsedGameTime.Milliseconds;
if (slideAnimationTimer < 0 && (Math.Abs(xVelocity) >= 3f || Math.Abs(yVelocity) >= 3f))
{
slideAnimationTimer = 100 - (int)(Math.Abs(xVelocity) * 2f + Math.Abs(yVelocity) * 2f);
ModEntry.mp.broadcastSprites(currentLocation, new TemporaryAnimatedSprite[]
{
new TemporaryAnimatedSprite(6, base.getStandingPosition() + new Vector2(-32f, -32f), Color.White * 0.75f, 8, Game1.random.NextDouble() < 0.5, 20f, 0, -1, -1f, -1, 0)
{
scale = 0.75f
}
});
}
}
}
else if (isGlider || Slipperiness >= 8)
{
bool[] array = Utility.horizontalOrVerticalCollisionDirections(nextPosition, this, false);
if (array[0])
{
xVelocity = -xVelocity;
position.X += (float)Math.Sign(xVelocity);
rotation += (float)(3.1415926535897931 + (double)Game1.random.Next(-10, 11) * 3.1415926535897931 / 500.0);
}
if (array[1])
{
yVelocity = -yVelocity;
position.Y -= (float)Math.Sign(yVelocity);
rotation += (float)(3.1415926535897931 + (double)Game1.random.Next(-10, 11) * 3.1415926535897931 / 500.0);
}
if (Slipperiness < 1000)
{
xVelocity -= xVelocity / (float)Slipperiness / 4f;
yVelocity -= yVelocity / (float)Slipperiness / 4f;
if (Math.Abs(xVelocity) <= 0.05f)
{
xVelocity = 0f;
}
if (Math.Abs(yVelocity) <= 0.051f)
{
yVelocity = 0f;
}
}
}
else
{
xVelocity -= xVelocity / (float)Slipperiness;
yVelocity -= yVelocity / (float)Slipperiness;
if (Math.Abs(xVelocity) <= 0.05f)
{
xVelocity = 0f;
}
if (Math.Abs(yVelocity) <= 0.05f)
{
yVelocity = 0f;
}
}
if (isGlider)
{
return;
}
}
if (moveUp)
{
if (((!Game1.eventUp || Game1.IsMultiplayer) && !currentLocation.isCollidingPosition(nextPosition(0), viewport, false, DamageToFarmer, isGlider, this)) || isCharging)
{
position.Y -= (float)(base.speed + base.addedSpeed);
if (!ignoreMovementAnimations)
{
Sprite.AnimateUp(time, 0, "");
}
base.FacingDirection = 0;
faceDirection(0);
}
else
{
Microsoft.Xna.Framework.Rectangle tmp = nextPosition(0);
tmp.Width /= 4;
bool leftCorner = currentLocation.isCollidingPosition(tmp, viewport, false, DamageToFarmer, isGlider, this);
tmp.X += tmp.Width * 3;
bool rightCorner = currentLocation.isCollidingPosition(tmp, viewport, false, DamageToFarmer, isGlider, this);
if (leftCorner && !rightCorner && !currentLocation.isCollidingPosition(nextPosition(1), viewport, false, DamageToFarmer, isGlider, this))
{
position.X += (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
else if (rightCorner && !leftCorner && !currentLocation.isCollidingPosition(nextPosition(3), viewport, false, DamageToFarmer, isGlider, this))
{
position.X -= (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
if (!currentLocation.isTilePreplacedable(nextPosition(0), viewport) || !base.willDestroyObjectsUnderfoot)
{
Halt();
}
else if (base.willDestroyObjectsUnderfoot)
{
new Vector2((float)(base.getStandingX() / 64), (float)(base.getStandingY() / 64 - 1));
if (currentLocation.characterDestroyObjectWithinRectangle(nextPosition(0), true))
{
currentLocation.playSound("stoneCrack", NetAudio.SoundContext.Default);
position.Y -= (float)(base.speed + base.addedSpeed);
}
else
{
blockedInterval += time.ElapsedGameTime.Milliseconds;
}
}
if (onCollision != null)
{
onCollision(currentLocation);
}
}
}
else if (moveRight)
{
if (((!Game1.eventUp || Game1.IsMultiplayer) && !currentLocation.isCollidingPosition(nextPosition(1), viewport, false, DamageToFarmer, isGlider, this)) || isCharging)
{
position.X += (float)(base.speed + base.addedSpeed);
if (!ignoreMovementAnimations)
{
Sprite.AnimateRight(time, 0, "");
}
base.FacingDirection = 1;
faceDirection(1);
}
else
{
Microsoft.Xna.Framework.Rectangle tmp2 = nextPosition(1);
tmp2.Height /= 4;
bool topCorner = currentLocation.isCollidingPosition(tmp2, viewport, false, DamageToFarmer, isGlider, this);
tmp2.Y += tmp2.Height * 3;
bool bottomCorner = currentLocation.isCollidingPosition(tmp2, viewport, false, DamageToFarmer, isGlider, this);
if (topCorner && !bottomCorner && !currentLocation.isCollidingPosition(nextPosition(2), viewport, false, DamageToFarmer, isGlider, this))
{
position.Y += (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
else if (bottomCorner && !topCorner && !currentLocation.isCollidingPosition(nextPosition(0), viewport, false, DamageToFarmer, isGlider, this))
{
position.Y -= (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
if (!currentLocation.isTilePreplacedable(nextPosition(1), viewport) || !base.willDestroyObjectsUnderfoot)
{
Halt();
}
else if (base.willDestroyObjectsUnderfoot)
{
new Vector2((float)(base.getStandingX() / 64 + 1), (float)(base.getStandingY() / 64));
if (currentLocation.characterDestroyObjectWithinRectangle(nextPosition(1), true))
{
currentLocation.playSound("stoneCrack", NetAudio.SoundContext.Default);
position.X += (float)(base.speed + base.addedSpeed);
}
else
{
blockedInterval += time.ElapsedGameTime.Milliseconds;
}
}
if (onCollision != null)
{
onCollision(currentLocation);
}
}
}
else if (moveDown)
{
if (((!Game1.eventUp || Game1.IsMultiplayer) && !currentLocation.isCollidingPosition(nextPosition(2), viewport, false, DamageToFarmer, isGlider, this)) || isCharging)
{
position.Y += (float)(base.speed + base.addedSpeed);
if (!ignoreMovementAnimations)
{
Sprite.AnimateDown(time, 0, "");
}
base.FacingDirection = 2;
faceDirection(2);
}
else
{
Microsoft.Xna.Framework.Rectangle tmp3 = nextPosition(2);
tmp3.Width /= 4;
bool leftCorner2 = currentLocation.isCollidingPosition(tmp3, viewport, false, DamageToFarmer, isGlider, this);
tmp3.X += tmp3.Width * 3;
bool rightCorner2 = currentLocation.isCollidingPosition(tmp3, viewport, false, DamageToFarmer, isGlider, this);
if (leftCorner2 && !rightCorner2 && !currentLocation.isCollidingPosition(nextPosition(1), viewport, false, DamageToFarmer, isGlider, this))
{
position.X += (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
else if (rightCorner2 && !leftCorner2 && !currentLocation.isCollidingPosition(nextPosition(3), viewport, false, DamageToFarmer, isGlider, this))
{
position.X -= (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
if (!currentLocation.isTilePreplacedable(nextPosition(2), viewport) || !base.willDestroyObjectsUnderfoot)
{
Halt();
}
else if (base.willDestroyObjectsUnderfoot)
{
new Vector2((float)(base.getStandingX() / 64), (float)(base.getStandingY() / 64 + 1));
if (currentLocation.characterDestroyObjectWithinRectangle(nextPosition(2), true))
{
currentLocation.playSound("stoneCrack", NetAudio.SoundContext.Default);
position.Y += (float)(base.speed + base.addedSpeed);
}
else
{
blockedInterval += time.ElapsedGameTime.Milliseconds;
}
}
if (onCollision != null)
{
onCollision(currentLocation);
}
}
}
else if (moveLeft)
{
if (((!Game1.eventUp || Game1.IsMultiplayer) && !currentLocation.isCollidingPosition(nextPosition(3), viewport, false, DamageToFarmer, isGlider, this)) || isCharging)
{
position.X -= (float)(base.speed + base.addedSpeed);
base.FacingDirection = 3;
if (!ignoreMovementAnimations)
{
Sprite.AnimateLeft(time, 0, "");
}
faceDirection(3);
}
else
{
Microsoft.Xna.Framework.Rectangle tmp4 = nextPosition(3);
tmp4.Height /= 4;
bool topCorner2 = currentLocation.isCollidingPosition(tmp4, viewport, false, DamageToFarmer, isGlider, this);
tmp4.Y += tmp4.Height * 3;
bool bottomCorner2 = currentLocation.isCollidingPosition(tmp4, viewport, false, DamageToFarmer, isGlider, this);
if (topCorner2 && !bottomCorner2 && !currentLocation.isCollidingPosition(nextPosition(2), viewport, false, DamageToFarmer, isGlider, this))
{
position.Y += (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
else if (bottomCorner2 && !topCorner2 && !currentLocation.isCollidingPosition(nextPosition(0), viewport, false, DamageToFarmer, isGlider, this))
{
position.Y -= (float)base.speed * ((float)time.ElapsedGameTime.Milliseconds / 64f);
}
if (!currentLocation.isTilePreplacedable(nextPosition(3), viewport) || !base.willDestroyObjectsUnderfoot)
{
Halt();
}
else if (base.willDestroyObjectsUnderfoot)
{
new Vector2((float)(base.getStandingX() / 64 - 1), (float)(base.getStandingY() / 64));
if (currentLocation.characterDestroyObjectWithinRectangle(nextPosition(3), true))
{
currentLocation.playSound("stoneCrack", NetAudio.SoundContext.Default);
position.X -= (float)(base.speed + base.addedSpeed);
}
else
{
blockedInterval += time.ElapsedGameTime.Milliseconds;
}
}
if (onCollision != null)
{
onCollision(currentLocation);
}
}
}
else if (!ignoreMovementAnimations)
{
if (moveUp)
{
Sprite.AnimateUp(time, 0, "");
}
else if (moveRight)
{
Sprite.AnimateRight(time, 0, "");
}
else if (moveDown)
{
Sprite.AnimateDown(time, 0, "");
}
else if (moveLeft)
{
Sprite.AnimateLeft(time, 0, "");
}
}
if ((blockedInterval < 3000 || (float)blockedInterval > 3750f) && blockedInterval >= 5000)
{
base.speed = 4;
isCharging = true;
blockedInterval = 0;
}
if (DamageToFarmer > 0 && Game1.random.NextDouble() < 0.00033333333333333332)
{
if (base.Name.Equals("Shadow Guy") && Game1.random.NextDouble() < 0.3)
{
if (Game1.random.NextDouble() < 0.5)
{
currentLocation.playSound("grunt", NetAudio.SoundContext.Default);
return;
}
currentLocation.playSound("shadowpeep", NetAudio.SoundContext.Default);
return;
}
else if (!base.Name.Equals("Shadow Girl"))
{
if (base.Name.Equals("Ghost"))
{
currentLocation.playSound("ghost", NetAudio.SoundContext.Default);
return;
}
if (!base.Name.Contains("Slime"))
{
base.Name.Contains("Jelly");
}
}
}
}
See More Examples