Click here to Skip to main content
15,891,375 members
Home / Discussions / C#
   

C#

 
GeneralRe: How this below code works Pin
indian14311-Jan-10 13:40
indian14311-Jan-10 13:40 
GeneralRe: How this below code works Pin
DaveyM6911-Jan-10 14:11
professionalDaveyM6911-Jan-10 14:11 
GeneralRe: How this below code works Pin
indian14311-Jan-10 14:27
indian14311-Jan-10 14:27 
QuestionBoolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 10:14
aespielberg11-Jan-10 10:14 
AnswerRe: Boolean value changes without being modified, don't know why. Pin
Luc Pattyn11-Jan-10 10:56
sitebuilderLuc Pattyn11-Jan-10 10:56 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 11:08
aespielberg11-Jan-10 11:08 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Luc Pattyn11-Jan-10 11:24
sitebuilderLuc Pattyn11-Jan-10 11:24 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 11:41
aespielberg11-Jan-10 11:41 
Sure. Yeah, I normally do go step by step, but with this error (which seems so bizarre), other than the delegates, I really didn't know what to check...anyway, still, I'm using no threading or timers, although there are two threads running...I can't remember if there are normally two threads running, which is why I was wondering if delegates used threads. The Debug window is printing:

The thread 'vshost.RunParkingWindow' (0x1930) has exited with code 0 (0x0).
The thread '<no name="">' (0x1e48) has exited with code 0 (0x0).
The program '[7760] Computational Geometry.vshost.exe: Managed' has exited with code 0 (0x0).

Although any time I do a call to this method it prints:
The thread '<no name="">' (0x540) has exited with code 0 (0x0).

After termination, so I guess delegates use threading after all...but shouldn't they be running synchronously, and have the rest of the code block until the delegate terminates?

Anyway, here's the code:

public double PolygonArea2
       {
           get{
               //check: at least 3 points.

               #region invariant check
               if (size < 3)
               {
                   throw new Exception("Cannot compute area, \"Polygon\" does not have at least 3 points");
               }
               #endregion

               if (currAreaValid)
               {
                   return area;
               }
               //else:

               //iterative method: sum point triplets as signed areas...set to area
               area = (Double)(Fold(area2FoldHelper, (Object)(new Double()), this[0]).First);
               currAreaValid = true;
               return area;
           }
       }

       private static Tuple<Object, Point> area2FoldHelper(Point currentPoint, Object totalArea, Point bound)
       {

           //increase the current area by the next triplet of points' area:
           if (currentPoint.Next.Next == bound || currentPoint.Next == bound.Next)
           {
               return new Tuple<Object, Point>(totalArea, bound);
           }

           Double areaToAdd = ((Double)totalArea) + Globals.Area2(currentPoint, currentPoint.Next, currentPoint.Next.Next);
           return new Tuple<Object, Point>((Object)areaToAdd, bound);
       }

  public Tuple<Object, Point> Fold(FoldDelegate fdel, Object initObjVal, Point initPoint)
       {
           Tuple<Object, Point> tuple = new Tuple<Object, Point>(initObjVal, initPoint);

           for (int i = 0; i < size; i++)
           {
               tuple = fdel(vertices, tuple.First, tuple.Second);
               vertices = vertices.Next;
           }

           return tuple;
       }


That is all in class Polygon/Polytope (Polygon extends Polytope...for what it's worth, only the Fold method is in the Polytope class)

Here's from static class Global, X = 0, Y = 1, and Coords is an array that represents the coordinates:

//gets twice the signed area of a triangle
      public static double Area2(Point a, Point b, Point c)
      {
          return (b.Coords[X] - a.Coords[X]) * (c.Coords[Y] - a.Coords[Y]) -
                 (c.Coords[X] - a.Coords[X]) * (b.Coords[Y] - a.Coords[Y]);
      }


The tuple implementation I think is very simple and doesn't need to be shown, but if you want it, let me know.

Thanks,
Andy
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Luc Pattyn11-Jan-10 12:06
sitebuilderLuc Pattyn11-Jan-10 12:06 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 12:23
aespielberg11-Jan-10 12:23 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Luc Pattyn11-Jan-10 13:08
sitebuilderLuc Pattyn11-Jan-10 13:08 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 13:24
aespielberg11-Jan-10 13:24 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
aespielberg11-Jan-10 13:34
aespielberg11-Jan-10 13:34 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Luc Pattyn11-Jan-10 13:50
sitebuilderLuc Pattyn11-Jan-10 13:50 
GeneralRe: Boolean value changes without being modified, don't know why. Pin
Daniel Grunwald12-Jan-10 6:20
Daniel Grunwald12-Jan-10 6:20 
QuestionHow do I set the "Apply onto" option in NTFS file security rights using c#? Pin
arnold_w11-Jan-10 9:12
arnold_w11-Jan-10 9:12 
AnswerRe: How do I set the "Apply onto" option in NTFS file security rights using c#? [modified] Pin
arnold_w12-Jan-10 2:52
arnold_w12-Jan-10 2:52 
GeneralRe: How do I set the &quot;Apply onto&quot; option in NTFS file security rights using c#? Pin
batrado_®8-Feb-10 1:42
batrado_®8-Feb-10 1:42 
QuestionSend video capture over LAN Pin
shutupsquare11-Jan-10 8:58
shutupsquare11-Jan-10 8:58 
AnswerRe: Send video capture over LAN Pin
Alex Manolescu11-Jan-10 9:49
Alex Manolescu11-Jan-10 9:49 
QuestionFinding * characters in a string Pin
sleepyman11-Jan-10 8:52
sleepyman11-Jan-10 8:52 
AnswerRe: Finding * characters in a string Pin
Alex Manolescu11-Jan-10 9:31
Alex Manolescu11-Jan-10 9:31 
GeneralRe: Finding * characters in a string Pin
PIEBALDconsult11-Jan-10 14:54
mvePIEBALDconsult11-Jan-10 14:54 
AnswerRe: Finding * characters in a string Pin
Luc Pattyn11-Jan-10 9:48
sitebuilderLuc Pattyn11-Jan-10 9:48 
GeneralRe: Finding * characters in a string Pin
sleepyman12-Jan-10 8:11
sleepyman12-Jan-10 8:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.