mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Improve rounding - thx OmrSi :)
This commit is contained in:
parent
d19b259771
commit
85d0b121fa
@ -4,21 +4,29 @@ using Nikse.SubtitleEdit.Core.SubtitleFormats;
|
|||||||
|
|
||||||
namespace Test.Logic.SubtitleFormats
|
namespace Test.Logic.SubtitleFormats
|
||||||
{
|
{
|
||||||
|
[TestClass]
|
||||||
public class SubtitleFormatFunctionsTest
|
public class SubtitleFormatFunctionsTest
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void MillisecondsToFrames1()
|
public void MillisecondsToFrames1()
|
||||||
{
|
{
|
||||||
var x = SubtitleFormat.MillisecondsToFrames(500, 25);
|
var frames = SubtitleFormat.MillisecondsToFrames(500, 25);
|
||||||
Assert.AreEqual(x, 13);
|
Assert.AreEqual(13, frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void MillisecondsToFrames2()
|
||||||
|
{
|
||||||
|
var frames = SubtitleFormat.MillisecondsToFrames(499, 25);
|
||||||
|
Assert.AreEqual(12, frames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void FramesToMilliseconds1()
|
public void FramesToMilliseconds1()
|
||||||
{
|
{
|
||||||
Configuration.Settings.General.CurrentFrameRate = 25.0;
|
Configuration.Settings.General.CurrentFrameRate = 25.0;
|
||||||
var x = SubtitleFormat.FramesToMilliseconds(1);
|
var ms = SubtitleFormat.FramesToMilliseconds(1);
|
||||||
Assert.AreEqual(x, 40);
|
Assert.AreEqual(ms, 40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,7 +425,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
|||||||
|
|
||||||
public static int MillisecondsToFrames(double milliseconds, double frameRate)
|
public static int MillisecondsToFrames(double milliseconds, double frameRate)
|
||||||
{
|
{
|
||||||
return (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(frameRate)));
|
return (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(frameRate)), MidpointRounding.AwayFromZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetFrameForCalculation(double frameRate)
|
public static double GetFrameForCalculation(double frameRate)
|
||||||
|
Loading…
Reference in New Issue
Block a user