Page 1 of 1

Very strange bug in Line [SOLVED]

Posted: Sat Mar 12, 2016 4:35 am
by rkmore
I found the following strange behavior by mistake.

If you run the following code you get a result like the attached (the lines to not meet at the center). I fully realize that there is an error where I convert degrees to radians BUT that should not cause this behavior. The value of pCenter never changes and the sin and cos of ANY number is still in the range -1 to 1 so the resulting lines are definitely wrong.

Code: Select all

            Point pCenter = new Point(150, 150);
            Color pColor = Colors.Red;
            double pLineLength = 130;
            for (int i = 10; i < 360; i += 10)
            {
                double radians = i * 180.0 / Math.PI;
                double sin = Math.Sin(radians);
                double cos = Math.Cos(radians);
                Point pPoint = new Point(((cos * pLineLength) + pCenter.X),
                                ((sin * pLineLength) + pCenter.Y));
                Windows.UI.Xaml.Shapes.Line line = new Windows.UI.Xaml.Shapes.Line();
                line.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(pColor);
                line.X1 = pCenter.X;
                line.Y1 = pCenter.Y;
                line.X2 = pPoint.X;
                line.Y2 = pPoint.Y;
                CompassCanvas.Children.Add(line);
            }




Capture.PNG
Capture.PNG (21.49 KiB) Viewed 3100 times


Even if you fix the radians conversion so that the value if correct as follows.

Code: Select all

            Point pCenter = new Point(150, 150);
            Color pColor = Colors.Red;
            double pLineLength = 130;
            for (int i = 10; i < 360; i += 10)
            {
                double radians = i * Math.PI / 180.0;
                double sin = Math.Sin(radians);
                double cos = Math.Cos(radians);
                Point pPoint = new Point(((cos * pLineLength) + pCenter.X),
                                ((sin * pLineLength) + pCenter.Y));
                Windows.UI.Xaml.Shapes.Line line = new Windows.UI.Xaml.Shapes.Line();
                line.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(pColor);
                line.X1 = pCenter.X;
                line.Y1 = pCenter.Y;
                line.X2 = pPoint.X;
                line.Y2 = pPoint.Y;
                CompassCanvas.Children.Add(line);
            }


The resulting lines are STILL wrong but not as badly (which makes no sense at all to me)

Capture.PNG
Capture.PNG (21.49 KiB) Viewed 3100 times

Re: Very strange bug in Line

Posted: Mon Mar 14, 2016 3:00 am
by JS-Support @Userware
Thanks for your post. We are going to investigate this issue. I will keep you updated as soon as possible.

Regards,
JS-Support

Workaround

Posted: Sun May 15, 2016 4:06 am
by rkmore
Never did hear back on this one. If anyone else is having this problem here is a workaround until it is eventually hopefully addressed.

Code: Select all

        private void DrawLine(Canvas pCanvas, Point p1, Point p2, Color pColor)
        {
            double minX = System.Math.Min(p1.X, p2.X);
            double minY = Math.Min(p1.Y, p2.Y);
            Line line = new Line();
            Canvas.SetLeft(line, minX);
            Canvas.SetTop(line, minY);
            line.Stroke = new SolidColorBrush(pColor);
            line.X1 = p1.X - minX;
            line.Y1 = p1.Y - minY;
            line.X2 = p2.X - minX;
            line.Y2 = p2.Y - minY;
            pCanvas.Children.Add(line);
        }

Re: Very strange bug in Line

Posted: Sun May 15, 2016 8:53 pm
by JS-Support @Userware
Thanks for the workaround.

The bug is still being investigated. We will post a message here as soon as it is fixed.

Thank you.
Regards
JS-Support

Re: Very strange bug in Line

Posted: Mon May 30, 2016 7:30 am
by JS-Support @Userware
Hi,

We have fixed the issue. The fix will be available in the upcoming Beta 8.1.

Thanks.
Regards,
JS-Support