Very strange bug in Line [SOLVED]

Please report bugs here. If you are unsure whether something is a bug or an expected behavior, please post it on the "Technical Support" forum instead, and wait for a moderator to handle/move the post.
rkmore
Posts: 55
Joined: Mon Dec 07, 2015 1:53 pm

Very strange bug in Line [SOLVED]

Postby rkmore » Sat Mar 12, 2016 4:35 am

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 7927 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 7927 times
Attachments
Capture2.PNG
Capture2.PNG (22.54 KiB) Viewed 7927 times

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Very strange bug in Line

Postby JS-Support @Userware » Mon Mar 14, 2016 3:00 am

Thanks for your post. We are going to investigate this issue. I will keep you updated as soon as possible.

Regards,
JS-Support

rkmore
Posts: 55
Joined: Mon Dec 07, 2015 1:53 pm

Workaround

Postby rkmore » Sun May 15, 2016 4:06 am

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);
        }

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Very strange bug in Line

Postby JS-Support @Userware » Sun May 15, 2016 8:53 pm

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

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Very strange bug in Line

Postby JS-Support @Userware » Mon May 30, 2016 7:30 am

Hi,

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

Thanks.
Regards,
JS-Support


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 30 guests

 

 

cron