Fixed floating point comparisons

This commit is contained in:
Flamefire committed 2013-04-23 15:42:32 +02:00
1 parent 9d481cabc1
commit 5cd47f0537
13 files changed
+32 -32

No files matched your search

+4 -4
View File
@@ -105,7 +105,7 @@ namespace VocaluxeLib.Menu
public bool IsAlive
{
get { return _Age < _MaxAge || _MaxAge == 0f; }
get { return _Age < _MaxAge || Math.Abs(_MaxAge) < float.Epsilon; }
}
#endregion public vars
@@ -218,7 +218,7 @@ namespace VocaluxeLib.Menu
if (Math.Round(Y) < maxy)
{
float vdx = 0f;
if (_Vx != 0)
if (Math.Abs(_Vx) > float.Epsilon)
vdx = (float)Math.Sin(currentTime / _Vx * Math.PI);
X += _Vx * timediff * (0.5f + vdx);
@@ -242,7 +242,7 @@ namespace VocaluxeLib.Menu
// update size
if (_Vsize != 0f)
if (Math.Abs(_Vsize) > float.Epsilon)
{
float size = _Size;
switch (_Type)
@@ -275,7 +275,7 @@ namespace VocaluxeLib.Menu
}
// update rotation
if (_Vr != 0f)
if (Math.Abs(_Vr) > 0.01)
{
float r = currentTime * _Vr / 60f;
_Angle = _Rotation + 360f * (r - (float)Math.Floor(r));
+2 -2
View File
@@ -503,11 +503,11 @@ namespace VocaluxeLib.Menu
writer.WriteElementString("TextH", TextH.ToString("#0.00"));
writer.WriteComment("<TextRelativeX>: Text relative x-position");
if (TextRelativeX != 0)
if (Math.Abs(TextRelativeX) > 0.01)
writer.WriteElementString("TextRelativeX", TextRelativeX.ToString("#0.00"));
writer.WriteComment("<TextRelativeY>: Text relative y-position");
if (TextRelativeY != 0)
if (Math.Abs(TextRelativeY) > 0.01)
writer.WriteElementString("TextRelativeY", TextRelativeY.ToString("#0.00"));
writer.WriteComment("<TextMaxW>: Maximum text width (if exists)");
+5 -5
View File
@@ -74,7 +74,7 @@ namespace VocaluxeLib.Menu
get { return _X; }
set
{
if (_X != value)
if (Math.Abs(_X - value) > 0.01)
{
_X = value;
_PositionNeedsUpdate = true;
@@ -89,7 +89,7 @@ namespace VocaluxeLib.Menu
get { return _Y; }
set
{
if (_Y != value)
if (Math.Abs(_Y - value) > 0.01)
{
_Y = value;
_PositionNeedsUpdate = true;
@@ -110,7 +110,7 @@ namespace VocaluxeLib.Menu
get { return _Height; }
set
{
if (_Height != value)
if (Math.Abs(_Height - value) > 0.01)
{
_Height = value;
_PositionNeedsUpdate = true;
@@ -124,7 +124,7 @@ namespace VocaluxeLib.Menu
get { return _MaxWidth; }
set
{
if (_MaxWidth != value)
if (Math.Abs(_MaxWidth - value) > 0.01)
{
_MaxWidth = value;
if (_MaxWidth > 0)
@@ -143,7 +143,7 @@ namespace VocaluxeLib.Menu
get { return _Bounds; }
set
{
if (_Bounds.X != value.X || _Bounds.Y != value.Y || _Bounds.W != value.W || _Bounds.H != value.H || _Bounds.Z != value.Z)
if (Math.Abs(_Bounds.X - value.X) > 0.01 || Math.Abs(_Bounds.Y - value.Y) > 0.01 || Math.Abs(_Bounds.W - value.W) > 0.01 || Math.Abs(_Bounds.H - value.H) > 0.01 || Math.Abs(_Bounds.Z - value.Z) > 0.01)
{
_Bounds = value;
_PositionNeedsUpdate = true;
+1 -1
View File
@@ -316,7 +316,7 @@ namespace VocaluxeLib.Menu.SingNotes
float beats = line.LastNoteBeat - line.FirstNoteBeat + 1;
if (beats == 0)
if (beats < 1)
return;
SColorF color = new SColorF(
+1 -1
View File
@@ -988,7 +988,7 @@ namespace VocaluxeLib.Menu.SongMenu
}
}
if (PreviewStart == 0f)
if (Math.Abs(PreviewStart) < 0.001)
{
if (Medley.Source == EMedleySource.Calculated)
PreviewStart = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
@@ -616,7 +616,7 @@ namespace VocaluxeLib.Menu.SongMenu
float startposition = CBase.Songs.GetVisibleSong(_Actsong).PreviewStart;
if (startposition == 0f)
if (Math.Abs(startposition) < 0.001)
startposition = CBase.Sound.GetLength(stream) / 4f;
CBase.Sound.SetPosition(stream, startposition);
@@ -423,7 +423,7 @@ namespace VocaluxeLib.Menu.SongMenu
_MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag;
float time = CBase.Sound.GetLength(_SongStream);
if (song.Finish != 0)
if (Math.Abs(song.Finish) > 0.001)
time = song.Finish;
time -= song.Start;