Exemplo n.º 1
0
        public static PointF calculateDerivedPosition(PointF point, double range, double bearing)
        {
            double EarthRadius = 6371000; // m

            double latA            = DoubleExtensions.ToRadians(point.X);
            double lonA            = DoubleExtensions.ToRadians(point.Y);
            double angularDistance = range / EarthRadius;
            double trueCourse      = DoubleExtensions.ToRadians(bearing);

            double lat = Math.Asin(
                Math.Sin(latA) * Math.Cos(angularDistance) +
                Math.Cos(latA) * Math.Sin(angularDistance)
                * Math.Cos(trueCourse));

            double dlon = Math.Atan2(
                Math.Sin(trueCourse) * Math.Sin(angularDistance)
                * Math.Cos(latA),
                Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));

            double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;

            lat = lat.ToDegrees();
            lon = lon.ToDegrees();

            PointF newPoint = new PointF((float)lat, (float)lon);

            return(newPoint);
        }
Exemplo n.º 2
0
 public override void Draw(GameTime gt)
 {
     if (timerEndScaling.Enabled)
     {
         TheBall.Transform.Scale = DoubleExtensions.ToFloat(_getBallScale());
     }
 }
Exemplo n.º 3
0
        public static void updateInnerLines(LineSegment3d line, LineSegment3d prepareline, double dist, List <LineSegment3d> innerlines)
        {
            bool haveLinesOverlapped = false;

            foreach (LineSegment3d innerLine in innerlines)
            {
                if (WallRecognizer.isSegmentsProjectionOverlapped(prepareline, innerLine))
                {
                    haveLinesOverlapped = true;
                    break;
                }
            }

            if (haveLinesOverlapped)
            {
                // update the innerlines
                List <LineSegment3d> preparelines = new List <LineSegment3d>();
                foreach (LineSegment3d innerLine in innerlines)
                {
                    if (WallRecognizer.isSegmentsProjectionOverlapped(prepareline, innerLine))
                    {
                        Line3d innerline3d = WallRecognizer.toLine3d(innerLine.StartPoint, innerLine.EndPoint);
                        double innerDist   = innerline3d.GetDistanceTo(line.StartPoint);
                        if (DoubleExtensions.Larger(innerDist, dist))
                        {
                            if (!preparelines.Contains(prepareline))
                            {
                                preparelines.Add(prepareline);
                            }
                        }
                        else
                        {
                            if (!preparelines.Contains(innerLine))
                            {
                                preparelines.Add(innerLine);
                            }
                        }
                    }
                    else
                    {
                        if (!preparelines.Contains(innerLine))
                        {
                            preparelines.Add(innerLine);
                        }
                    }
                }

                // copy preparelines to innerlines
                innerlines.Clear();
                foreach (LineSegment3d innerLine in preparelines)
                {
                    innerlines.Add(innerLine);
                }
            }
            else
            {
                innerlines.Add(prepareline);
            }
        }
        public void PositiveOutsideRangeRadianTest()
        {
            const int    I        = 456;
            const double Expected = I * Math.PI / 180;
            var          actual   = DoubleExtensions.ToRadians(I);

            Assert.AreEqual(Expected, actual);
        }
        public void SuccessfulDegreeTest()
        {
            var degrees = Enumerable.Range(0, 360);

            foreach (var i in degrees)
            {
                var input    = i;
                var expected = i * 180 / Math.PI;
                var actual   = DoubleExtensions.ToDegrees(input);
                Assert.AreEqual(expected, actual);
            }
        }
        public void SuccessfulRadianTest()
        {
            var numbers = Enumerable.Range(0, 360);

            foreach (var i in numbers)
            {
                var input    = i;
                var expected = i * Math.PI / 180;
                var actual   = DoubleExtensions.ToRadians(input);
                Assert.AreEqual(expected, actual);
            }
        }
        public void TestMax()
        {
            var first    = this.GetInput();
            var second   = this.GetInput();
            var expected = new double[first.Length];

            for (int i = 0; i < first.Length; i++)
            {
                expected[i] = first[i] > second[i] ? first[i] : second[i];
            }

            var result = DoubleExtensions.Max(first, second);

            Assert.Equal(expected, result);
        }
Exemplo n.º 8
0
        public static List <LineSegment3d> getWallline(LineSegment3d line, IEnumerable <LineSegment3d> entities)
        {
            double width = maxWallWidth + 1;

            // step 1: get the parallel lines in the loop: skip the colinear line
            var dir           = line.Direction;
            var parallelLines = new List <LineSegment3d>();

            foreach (LineSegment3d tmpLine in entities)
            {
                if (line != tmpLine)
                {
                    if (dir.IsParallelTo(tmpLine.Direction) &&
                        (!tmpLine.IsOn(line.StartPoint) || tmpLine.IsOn(line.EndPoint))) // check if colinear line
                    {
                        parallelLines.Add(WallRecognizer.toLineSegment3d(tmpLine.StartPoint, tmpLine.EndPoint));
                    }
                }
            }

            List <LineSegment3d> innerlines = new List <LineSegment3d>();

            // step 2: get poper innerlines
            foreach (LineSegment3d line1 in parallelLines)
            {
                Line3d line3d = WallRecognizer.toLine3d(line1.StartPoint, line1.EndPoint);
                // skip the colinear line and the two lines should be projection overlapped
                if (!line3d.IsOn(line.StartPoint) && WallRecognizer.isSegmentsProjectionOverlapped(line1, line))
                {
                    double dist = line3d.GetDistanceTo(line.StartPoint);
                    if (DoubleExtensions.Larger(500, dist))
                    {
                        updateInnerLines(line, line1, dist, innerlines);
                    }

                    /*// pixel to millemeter
                     * dist = (dist * MILLIMETER_TO_METER) / PIXEL_TO_M_FACTOR;
                     * // the dist should > minWallWidth & < maxWallWidth
                     * if (DoubleExtensions.Larger(dist, minWallWidth) && DoubleExtensions.Larger(maxWallWidth, dist))
                     * {
                     *  //width = Math.Round(dist);
                     *  updateInnerLines(line1, dist, innerlines);
                     * }*/
                }
            }

            return(innerlines);
        }
        public void TestMultiplySimd()
        {
            var first    = this.GetInput();
            var second   = this.GetInput();
            var expected = new double[first.Length];

            for (int i = 0; i < first.Length; i++)
            {
                expected[i] = first[i] * second[i];
            }

            var result = new double[first.Length];

            DoubleExtensions.MultiplySimd(first, second, result);

            Assert.Equal(expected, result);
        }
Exemplo n.º 10
0
        public static WallInfor getWallinfors(List <LineSegment3d> outLines, List <LineSegment3d> allLines)
        {
            WallInfor wallInfor = new WallInfor();
            // step1: get the biggest length of outline
            var index  = 0;
            var length = outLines[index].Length;
            int size   = outLines.Count;

            for (int i = 1; i < size; i++)
            {
                if (DoubleExtensions.Larger(outLines[i].Length, length))
                {
                    index  = i;
                    length = outLines[index].Length;
                }
            }

            var currentWallInfor = wallInfor;

            // step2: get the outline wall infor
            for (int i = 0; i < size; i++)
            {
                var line = outLines[(i + index) % size];
                // skip the line if it is in part exist wall infor
                if (!isPartOfWallinfor(line, wallInfor))
                {
                    List <LineSegment3d> innerlines = WallRecognizer.getWallline(line, allLines);
                    // set the wall infor
                    currentWallInfor.outline    = line;
                    currentWallInfor.innerlines = innerlines;
                    currentWallInfor.next       = new WallInfor();
                    currentWallInfor            = currentWallInfor.next;
                }
            }

            return(wallInfor);
        }
Exemplo n.º 11
0
        protected override Tuple <double, double> CalculateSizesOnAttachOrResize(
            VisibilityAction?change, Tuple <double, double> lastSizeOrNull = null)
        {
            var theoretAvailSpace = Window.InnerWidth; //TODO change to equivalent of Container.GetAvailableHeightForFormElement();
            var factAvailSpace    = theoretAvailSpace - Splitter.GetBoundingClientRect().Width;

            var leftWdth  = FirstPanel.GetBoundingClientRect().Width;
            var rightWdth = SecondPanel.GetBoundingClientRect().Width;

            Logger.Debug(GetType(), "lastSize change={0} hidden?={1} lastSize={2} avail={3}",
                         change, Hidden, lastSizeOrNull?.Item1 + lastSizeOrNull?.Item2, factAvailSpace);

            if (lastSizeOrNull != null && change == VisibilityAction.Showing &&
                DoubleExtensions.AreApproximatellyTheSame(
                    lastSizeOrNull.Item1 + lastSizeOrNull.Item2, factAvailSpace, 1.1))
            {
                Logger.Debug(GetType(), "reusing lastSize");

                leftWdth  = lastSizeOrNull.Item1;
                rightWdth = lastSizeOrNull.Item2;
            }
            else if (Hidden)
            {
                Logger.Debug(GetType(), "hiding reusing all available space");

                if (Hideable == Hideability.First)
                {
                    leftWdth  = 0;
                    rightWdth = factAvailSpace;
                }
                else if (Hideable == Hideability.Second)
                {
                    leftWdth  = factAvailSpace;
                    rightWdth = 0;
                }
            }
            else
            {
                //showing or resize or attach
                Logger.Debug(GetType(), "not reusing lastSize");
                var res = ComputeSpace(leftWdth, rightWdth, factAvailSpace);

                leftWdth  = res.Item1;
                rightWdth = res.Item2;
            }

            if (!Hidden)
            {
                leftWdth  = Math.Max(leftWdth, MinPanelSizePx);
                rightWdth = Math.Max(rightWdth, MinPanelSizePx);

                //make sure that panels are visible on show
                var ratio = leftWdth / (leftWdth + rightWdth);
                leftWdth  = factAvailSpace * ratio;
                rightWdth = factAvailSpace - leftWdth;
            }

            Logger.Debug(GetType(), "CalculateSizesInitial(id={0})  availSpace={1} splitterHeight={2} outcome=({3},{4})",
                         Container.Id, theoretAvailSpace, Splitter.GetBoundingClientRect().Width, leftWdth, rightWdth);

            return(Tuple.Create(leftWdth, rightWdth));
        }
Exemplo n.º 12
0
        protected override Tuple <double, double> CalculateSizesOnAttachOrResize(
            VisibilityAction?change, Tuple <double, double> lastSizeOrNull = null)
        {
            var theoretAvailSpace = Container.GetAvailableHeightForFormElement();
            var factAvailSpace    = theoretAvailSpace - Splitter.GetBoundingClientRect().Height;

            var upperHght = FirstPanel.GetBoundingClientRect().Height;
            var lowerHght = SecondPanel.GetBoundingClientRect().Height;

            Logger.Debug(GetType(), "lastSize change={0} hidden?={1} lastSize={2} avail={3}",
                         change, Hidden, lastSizeOrNull?.Item1 + lastSizeOrNull?.Item2, factAvailSpace);

            if (lastSizeOrNull != null && change == VisibilityAction.Showing &&
                DoubleExtensions.AreApproximatellyTheSame(
                    lastSizeOrNull.Item1 + lastSizeOrNull.Item2, factAvailSpace, 1.1))
            {
                Logger.Debug(GetType(), "reusing lastSize");

                upperHght = lastSizeOrNull.Item1;
                lowerHght = lastSizeOrNull.Item2;
            }
            else if (Hidden)
            {
                Logger.Debug(GetType(), "hiding reusing all available space");

                if (Hideable == Hideability.First)
                {
                    upperHght = 0;
                    lowerHght = factAvailSpace;
                }
                else if (Hideable == Hideability.Second)
                {
                    upperHght = factAvailSpace;
                    lowerHght = 0;
                }
            }
            else
            {
                //showing or resize or attach
                Logger.Debug(GetType(), "not reusing lastSize");
                var res = ComputeSpace(upperHght, lowerHght, factAvailSpace);

                upperHght = res.Item1;
                lowerHght = res.Item2;
            }

            if (!Hidden)
            {
                upperHght = Math.Max(upperHght, MinPanelSizePx);
                lowerHght = Math.Max(lowerHght, MinPanelSizePx);

                //make sure that panels are visible on show
                var ratio = upperHght / (upperHght + lowerHght);
                upperHght = factAvailSpace * ratio;
                lowerHght = factAvailSpace - upperHght;
            }

            Logger.Debug(GetType(), "CalculateSizesInitial(id={0}) availSpace={1} splitterHeight={2} outcome=({3},{4})",
                         Container.Id, theoretAvailSpace, Splitter.GetBoundingClientRect().Height, upperHght, lowerHght);

            return(Tuple.Create(upperHght, lowerHght));
        }
Exemplo n.º 13
0
 public void ToByteStringTest()
 {
     Assert.AreEqual(DoubleExtensions.ToByteString(-255.255), "1100000001101111111010000010100011110101110000101000111101011100");
 }