Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SayMore/Transcription/Model/TimeTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public BoundaryModificationResult ChangeSegmentsEndBoundary(AnnotationSegment se
/// ------------------------------------------------------------------------------------
public bool GetIsAcceptableSegmentLength(float start, float end)
{
return end - start >= Settings.Default.MinimumSegmentLengthInMilliseconds / 1000f;
return Math.Round(end * 1000 - start * 1000) >= Settings.Default.MinimumSegmentLengthInMilliseconds;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What sort of error was occurring? If this is the necessary fix, probably a comment is needed, lest it be put back later by someone wishing to make it more readable.

}

/// ------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,27 @@ public static Rectangle GetButtonRectangleForSegment(Rectangle rcSegment, int bo
{
Debug.Assert(buttonSizes.Count == 1 || indexOfFirstRightAlignedButton < buttonSizes.Count);

if (rcSegment.IsEmpty)
return Rectangle.Empty;

var btnWidth = buttonSizes[index].Width;
var btnHeight = buttonSizes[index].Height;

if (rcSegment.IsEmpty || btnWidth + (kMinimalHorizontalMargin * 2) > rcSegment.Width)
return Rectangle.Empty; // No way to fit the button, even with minimal margins
var testWidth = btnWidth + (kMinimalHorizontalMargin * 2);
if (testWidth > rcSegment.Width)
{
// try shrinking the button to fit the space available
var diffX = testWidth - rcSegment.Width;

// only allow 20% reduction in size
if (diffX / (float)btnWidth > 0.2)
return Rectangle.Empty;

// reduce the height by the same percent
var diffY = (int)Math.Ceiling(diffX * (float)btnHeight / btnWidth);
btnWidth -= diffX;
btnHeight -= diffY;
}

// Set the default top
var buttonRectangleTop = rcSegment.Bottom - bottomMargin - btnHeight;
Expand Down
6 changes: 3 additions & 3 deletions src/SayMoreTests/Transcription/Model/TierCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ public void InsertTierSegment_BoundaryIsSameAsExisting_ReturnsNotSuccess()
[Test]
public void InsertTierSegment_BoundaryIsTooCloseToPrevious_ReturnsNotSuccess()
{
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _collection.InsertTierSegment(10.49f));
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _collection.InsertTierSegment(10.459f));
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _collection.InsertTierSegment(30.4f));
}

/// ------------------------------------------------------------------------------------
[Test]
public void InsertTierSegment_BoundaryIsTooCloseToNext_ReturnsNotSuccess()
{
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _collection.InsertTierSegment(19.501f));
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _collection.InsertTierSegment(29.501f));
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _collection.InsertTierSegment(19.541f));
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _collection.InsertTierSegment(29.541f));
}

/// ------------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions src/SayMoreTests/Transcription/Model/TimeTierTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,23 +787,23 @@ public void ChangeSegmentsEndBoundary_WhenSegmentIsNotLast_RenamesSegAnnotationF
public void InsertSegmentBoundary_NewBoundaryTooCloseToPrecedingBoundary_ReturnsNotSuccess()
{
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _tier.InsertSegmentBoundary(20.4f));
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _tier.InsertSegmentBoundary(20.49f));
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _tier.InsertSegmentBoundary(20.45f));
}

/// ------------------------------------------------------------------------------------
[Test]
public void InsertSegmentBoundary_NewBoundaryTooCloseToFollowingBoundary_ReturnsNotSuccess()
{
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _tier.InsertSegmentBoundary(29.501f));
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _tier.InsertSegmentBoundary(29.51f));
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _tier.InsertSegmentBoundary(29.541f));
Assert.AreEqual(BoundaryModificationResult.NextSegmentWillBeTooShort, _tier.InsertSegmentBoundary(29.55f));
}

/// ------------------------------------------------------------------------------------
[Test]
public void InsertSegmentBoundary_WhenNoSegmentsAndNewBoundaryTooSmall_ReturnsNotSuccess()
{
_tier.Segments.Clear();
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _tier.InsertSegmentBoundary(0.4999f));
Assert.AreEqual(BoundaryModificationResult.SegmentWillBeTooShort, _tier.InsertSegmentBoundary(0.4599f));
}

/// ------------------------------------------------------------------------------------
Expand Down Expand Up @@ -902,7 +902,7 @@ public void CanBoundaryMoveLeft_MoveWillYieldNewNegativeBoundary_ReturnsFalse()
public void CanBoundaryMoveLeft_MoveWillResultInTooShortSegment_ReturnsFalse()
{
Assert.IsFalse(_tier.CanBoundaryMoveLeft(12f, 2.0f));
Assert.IsFalse(_tier.CanBoundaryMoveLeft(12f, 1.501f));
Assert.IsFalse(_tier.CanBoundaryMoveLeft(12f, 1.541f));
}

/// ------------------------------------------------------------------------------------
Expand Down Expand Up @@ -933,7 +933,7 @@ public void CanBoundaryMoveRight_MoveWillPutNewBoundaryOnLimit_ReturnsTrue()
public void CanBoundaryMoveRight_MoveWillResultInTooShortSegment_ReturnsFalse()
{
Assert.IsFalse(_tier.CanBoundaryMoveRight(28f, 2.01f, 100f));
Assert.IsFalse(_tier.CanBoundaryMoveRight(28f, 1.501f, 100f));
Assert.IsFalse(_tier.CanBoundaryMoveRight(28f, 1.541f, 100f));
}

/// ------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Moq;
using NUnit.Framework;
using SayMore.Model.Files;
Expand Down Expand Up @@ -1061,7 +1059,7 @@ public void GetButtonRectangleForSegment_SingleButtonTooWide_EmptyRectangle(
int buttonWidth, int buttonHeight, int bottomMargin)
{
// Note: Current design should prevent this.
var rect = new Rectangle(0, 0, buttonWidth + SegmenterDlgBase.kMinimalHorizontalMargin * 2 - 1, buttonHeight + bottomMargin);
var rect = new Rectangle(0, 0, buttonWidth + SegmenterDlgBase.kMinimalHorizontalMargin * 2 - (int)(buttonWidth * 0.2) - 1, buttonHeight + bottomMargin);
Assert.AreEqual(Rectangle.Empty,
SegmenterDlgBase.GetButtonRectangleForSegment(rect, bottomMargin, new[] {new Size(buttonWidth, buttonHeight)}, 1000, 0));
}
Expand Down Expand Up @@ -1127,7 +1125,7 @@ public void GetButtonRectangleForSegment_SingleButtonFitsEasilyWithNormalMargins

/// ------------------------------------------------------------------------------------
[TestCase(32, -8, 0, ExpectedResult = 1)] // 36 pixels visible in segment. Entire button visible.
[TestCase(10, -12, 2, ExpectedResult = 0)] // 12 pixels visible in segment. Entire button visible, no visible left margin
[TestCase(10, -12, 2, ExpectedResult = -1)] // 12 pixels visible in segment. Entire button visible, no visible left margin
[TestCase(20, -28, 12, ExpectedResult = -10)] // 16 pixels visible in segment. 20-10 = 10 pixels of button visible. (Don't bother with reduced margins.)
public int GetButtonRectangleForSegment_SingleButtonFitsInRectangleThatIsScrolledTooFarLeftToAllowFullLeftMargin_ReducedOrClippedLeftPosition(
int buttonWidth, int boundingRectangleLeft, int extraWidth)
Expand Down