mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +01:00
Paragraph adjust optimization - inspired by #1490
This commit is contained in:
parent
8e7a395a00
commit
c382a71a5e
@ -115,11 +115,8 @@ namespace Nikse.SubtitleEdit.Core
|
||||
if (StartTime.IsMaxTime)
|
||||
return;
|
||||
|
||||
double seconds = StartTime.TimeSpan.TotalSeconds * factor + adjustmentInSeconds;
|
||||
StartTime.TimeSpan = TimeSpan.FromSeconds(seconds);
|
||||
|
||||
seconds = EndTime.TimeSpan.TotalSeconds * factor + adjustmentInSeconds;
|
||||
EndTime.TimeSpan = TimeSpan.FromSeconds(seconds);
|
||||
StartTime.TotalMilliseconds = StartTime.TotalMilliseconds * factor + (adjustmentInSeconds * TimeCode.BaseUnit);
|
||||
EndTime.TotalMilliseconds = EndTime.TotalMilliseconds * factor + (adjustmentInSeconds * TimeCode.BaseUnit);
|
||||
}
|
||||
|
||||
public void CalculateFrameNumbersFromTimeCodes(double frameRate)
|
||||
|
@ -38,17 +38,19 @@ namespace Test.Logic
|
||||
[TestMethod]
|
||||
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);
|
||||
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]
|
||||
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);
|
||||
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]
|
||||
@ -59,5 +61,12 @@ namespace Test.Logic
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user