Esempio n. 1
0
        public void EqualsTestOutOfRange()
        {
            var fd1 = new FiniteDouble(double.NaN);

            Assert.IsTrue(fd1.Equals(new FiniteDouble(double.PositiveInfinity)));
            Assert.IsTrue(fd1 == new FiniteDouble(double.PositiveInfinity));
        }
Esempio n. 2
0
        public void EqualsTestInRange()
        {
            var fd1 = new FiniteDouble(41.758);

            Assert.IsTrue(fd1.Equals(new FiniteDouble(41.758)));
            Assert.IsTrue(fd1 == new FiniteDouble(41.758));
        }
        public WaveformDimensions(TuneDuration coverageArea, double canvasWidth,
                                  double leftPadding, double rightPadding, double zoomedInLeftPadding, double zoomedInRightPadding) : this()
        {
            var safeCanvasWidth = new FiniteDouble(canvasWidth);
            var safeZoom        = Math.Max(1d, new FiniteDouble(coverageArea.Zoom, 1.0));

            this.LeftPadding = safeZoom > 1
                ? zoomedInLeftPadding
                : leftPadding;
            this.RightPadding = safeZoom > 1
                ? zoomedInRightPadding
                : rightPadding;
            this.RenderedWidth = Math.Max(0, (safeCanvasWidth - this.LeftPadding - this.RightPadding));
            this.CompleteWidth = this.RenderedWidth * safeZoom;
            this.StartsAtPx    = coverageArea.HiddenBefore(this.CompleteWidth);
        }
        /// <summary>
        /// Initialize the instance with explicit position, length, and zoom.
        /// </summary>
        /// <param name="position">Position within the channel in units</param>
        /// <param name="length">Length of the channel in the same units</param>
        /// <param name="zoom">Zoom on the channel (zoom >= 1)</param>
        public TuneDuration(double position, double length, double zoom)
        {
            this.Length = Math.Max(0.0, new FiniteDouble(length).Value());
            this.Zoom   = Math.Max(1.0, new FiniteDouble(zoom, 1.0).Value());
            double currentPosition = new FiniteDouble(this.Length <= 0.0 ? 0.0 : Math.Min(this.Length, position) / this.Length, 0.0d).Value();
            double fullArea        = 1.0d / this.Zoom;
            double halfArea        = fullArea / 2.0d;
            double windowStart     = currentPosition - halfArea; // this can mean < 0
            double windowEnd       = currentPosition + halfArea; // this can mean > 1

            // I want to preferably see the end
            if (1 - fullArea <= currentPosition)
            {
                windowStart = 1 - fullArea;
                windowEnd   = 1;
            }
            if (windowStart < 0.0d)
            {
                windowStart = 0.0d;
                windowEnd   = windowStart + fullArea;
            }
            if (windowEnd > 1.0d)
            {
                windowEnd   = 1.0d;
                windowStart = windowEnd - fullArea;
            }

            var windowBetween0and1   = windowStart >= 0.0d && windowEnd <= 1.0d;
            var windowStartBeforeEnd = windowEnd > windowStart;

            if (!windowBetween0and1 || !windowStartBeforeEnd)
            {
                throw new Exception($"Assertion failed: {windowStart} and {windowEnd} are suspect!");
            }
            this.Start = windowStart;
            this.End   = windowEnd;
        }