Paragraph adjust optimization - inspired by #1490

This commit is contained in:
niksedk 2016-01-22 16:28:09 +01:00
parent 8e7a395a00
commit c382a71a5e
2 changed files with 14 additions and 8 deletions

View File

@ -115,11 +115,8 @@ namespace Nikse.SubtitleEdit.Core
if (StartTime.IsMaxTime) if (StartTime.IsMaxTime)
return; return;
double seconds = StartTime.TimeSpan.TotalSeconds * factor + adjustmentInSeconds; StartTime.TotalMilliseconds = StartTime.TotalMilliseconds * factor + (adjustmentInSeconds * TimeCode.BaseUnit);
StartTime.TimeSpan = TimeSpan.FromSeconds(seconds); EndTime.TotalMilliseconds = EndTime.TotalMilliseconds * factor + (adjustmentInSeconds * TimeCode.BaseUnit);
seconds = EndTime.TimeSpan.TotalSeconds * factor + adjustmentInSeconds;
EndTime.TimeSpan = TimeSpan.FromSeconds(seconds);
} }
public void CalculateFrameNumbersFromTimeCodes(double frameRate) public void CalculateFrameNumbersFromTimeCodes(double frameRate)

View File

@ -38,17 +38,19 @@ namespace Test.Logic
[TestMethod] [TestMethod]
public void TestAdjust1() public void TestAdjust1()
{ {
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0,1,1,1) }; var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0,1,1,1), EndTime = new TimeCode(0, 1, 3, 1) };
p.Adjust(1, 10); p.Adjust(1, 10);
Assert.AreEqual(new TimeCode(0,1,11,1).TotalMilliseconds, p.StartTime.TotalMilliseconds); Assert.AreEqual(new TimeCode(0, 1, 11, 1).TotalMilliseconds, p.StartTime.TotalMilliseconds);
Assert.AreEqual(new TimeCode(0, 1, 13, 1).TotalMilliseconds, p.EndTime.TotalMilliseconds);
} }
[TestMethod] [TestMethod]
public void TestAdjust2() public void TestAdjust2()
{ {
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 1, 1) }; var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 1, 1), EndTime = new TimeCode(0, 1, 4, 1) };
p.Adjust(2, 10); p.Adjust(2, 10);
Assert.AreEqual(new TimeCode(0, 2, 12, 2).TotalMilliseconds, p.StartTime.TotalMilliseconds); Assert.AreEqual(new TimeCode(0, 2, 12, 2).TotalMilliseconds, p.StartTime.TotalMilliseconds);
Assert.AreEqual(new TimeCode(0, 2, 18, 2).TotalMilliseconds, p.EndTime.TotalMilliseconds);
} }
[TestMethod] [TestMethod]
@ -59,5 +61,12 @@ namespace Test.Logic
Assert.AreEqual(1, p.StartTime.TotalSeconds); Assert.AreEqual(1, p.StartTime.TotalSeconds);
} }
[TestMethod]
public void TestDuration()
{
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 0, 0), EndTime = new TimeCode(0, 1, 1, 1) };
Assert.AreEqual(p.Duration.TotalMilliseconds, 1001);
}
} }
} }