private float GetInchesFromRuler(float pixels, bool fromRight, bool useBounds, bool useActualBounds) { float inches = fromRight ? ConvertEx.PixelsToInches(GetActualRulerRightPixel() - pixels, _Dpi) : ConvertEx.PixelsToInches(pixels - Padding.Left, _Dpi); if (SnapToRuler) { const float rulerStep = (1f / RulerSteps); float remainder = inches % rulerStep; if (remainder != 0) { const float halfStep = rulerStep / 2; inches = (inches - remainder) + (remainder > halfStep ? rulerStep : 0); } } if (useBounds) { float maxInches = useActualBounds ? GetActualRulerLength() : _RulerLength; if (inches < 0) { inches = 0; } else if (inches > maxInches) { inches = maxInches; } } return(inches); }
public void PixelsToInchesTest() { const float expected = 1F; float actual = ConvertEx.PixelsToInches(DPI, DPI); Assert.AreEqual(expected, actual); }