Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2006, 05:42 PM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dataview bug? or code error..



Hi all,
I'm trying to compute a convex hull from a set of points using Jarvis' March. As part of the algorithm I'm computing for each point, its angle in relation to the other points. I compute this information in the datatable and then sort it using a dataview. Sometimes the dataview sorts correctly, sometimes it .. doesn't? I'll find most of the rows sorted correctly according to angle, but maybe three rows in strange places. This throws off the whole algorithm obviously. Anyone know what's going on? I appreciate any help at all.

Code:
            do
            {
                for (i = 0; i < dv.Count; i++)
                {
                    if(m_dt2.Rows.Count < 2)
                        dv[i][2] = getAngle(basePoint.X, basePoint.Y, Convert.ToInt32(dv[i][0].ToString()), Convert.ToInt32(dv[i][1].ToString()));
                    else
                    {
                        a = new Point(Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-2][0]), Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-2][1]));
                        b = new Point(Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-1][0]), Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-1][1]));
                        c = new Point(Convert.ToInt16(dv[i][0].ToString()), Convert.ToInt16(dv[i][1].ToString()));
                        ab = Math.Sqrt(((b.X - a.X)*(b.X - a.X)) + ((b.Y - a.Y)*(b.Y - a.Y)));
                        bc = Math.Sqrt(((c.X - b.X)*(c.X - b.X)) + ((c.Y - b.Y)*(c.Y - b.Y)));
                        ac = Math.Sqrt(((c.X - a.X)*(c.X - a.X)) + ((c.Y - a.Y)*(c.Y - a.Y)));
                        dv[i][2] = Convert.ToDouble(Math.Acos((ab*ab+bc*bc-ac*ac)/(2*ab*bc)));
                    }
                }

                if(m_dt2.Rows.Count < 2)
                    dv.Sort = "angle ASC";
                else
                    dv.Sort = "angle DESC";
                dgPoints.DataSource = dv;
                Push(Convert.ToInt32(dv[0][0].ToString()), Convert.ToInt32(dv[0][1].ToString()));
                basePoint = new Point(Convert.ToInt32(dv[0][0].ToString()),Convert.ToInt32(dv[0][1].ToString()));
                dv[0].Delete();
            }while(basePoint.X != baseX && basePoint.Y != baseY);


 
Old November 20th, 2006, 03:03 PM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fixed. The problem was that I was rebinding the dataview to the datagrid during each iteration. For some reason this was giving a wacky sort order.






Similar Threads
Thread Thread Starter Forum Replies Last Post
a big bug on a code busteronline ASP.NET 1.0 and 1.1 Basics 0 September 15th, 2008 09:11 AM
Forum Caching Bug in VB Code Scott663 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 March 27th, 2008 08:24 PM
Bug in the Poll VB code? thuyvncr BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 April 21st, 2007 08:43 PM
Is this code correct for a Dataview rayncarnation ASP.NET 1.0 and 1.1 Basics 0 November 7th, 2005 05:55 PM
Variable value error / bug ? James Diamond Pro VB 6 5 May 24th, 2004 08:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.