Jump to content

  • Log In with Google      Sign In   
  • Create Account

Grain

Member Since 08 Apr 2004
Offline Last Active Yesterday, 01:47 AM

Posts I've Made

In Topic: Digits of Pi

20 November 2013 - 12:13 AM

I like thing that are evenly spaced, or symmetrical or balanced. Irrational and prime numbers bother me just because you can't make them line up evenly with things.

In Topic: Large array allocation & out of memory error

29 September 2013 - 02:25 AM

Oh, that BitArray did it! Thanks!

In Topic: Check if a List<T>.Enumerator is valid

01 September 2013 - 03:25 AM

What is the purpose of the 0-or-1 neighbor element?

 Same idea as a linked list. Only this can potentially branch. 
 

Why do you keep track of the enumerator manually?

Is there some method of keeping track of it automatically?
 

What kind of traversal are you trying to perform?

Move to the first child first, then to any of it's children/neighbors next ect, return to the parent when you reach the end, repeat for the next child until there are no more children, move to the neighbor.

public class FileParseElement
    {
        string token;
        FileParseElement Neighbor;
        List<FileParseElement> Children;
        List<FileParseElement>.Enumerator CurrentChild;


        public static FileParseElement BuildFullObjectStructure(ref List<string>.Enumerator ittr){...}
        public static FileParseElement BuildObjectSet(ref List<string>.Enumerator ittr){...}
        public string Token
        {
            get { return token; }
        }
        
        
        public FPE_Iterator GetIterator()
        {
            return new FPE_Iterator(this) { };
        }

        public class FPE_Iterator  //this IS a nested class 
        {
            FileParseElement Head;
            Stack<FileParseElement> ParrentStack;

            public FPE_Iterator(FileParseElement FPE)
            {
                ParrentStack = new Stack<FileParseElement>();
                Head = FPE;
            }

            public FileParseElement Current
            {
                get { return Head; }
            }

            public bool Movenext()
            {
                if (Head.Children != null)
                {
                    if (Head.CurrentChild != new List<FileParseElement>.Enumerator()) //compiler doesn't allow this
                    {
                        ParrentStack.Push(Head);
                        Head = Head.Children.GetEnumerator().Current;
                        return true;
                    }
                }
 
                if (Head.Neighbor != null  /*&& I have no children or finished tracversing them*/)
                {
                    Head = Head.Neighbor;
                    return true;
                }
                else
                {
                     //pop a parent off the stack and assign it to Head
                     return false;
                }
            } 
       } 
    }

Movenext() is what I'm working on now. It's far from compleet


In Topic: Check if a List<T>.Enumerator is valid

31 August 2013 - 05:49 PM

I have a custom container class that is arranged like a tree. Each element can have up-to 1 neighbor element and any number of children elements, these children are stored in a standard library List<T>.

 

Each element also has a  List<T>.Enumerator so that when I iterate through this container and come to the end of a branch and then back up it will remember which branch it was last down and go to the next branch next, if it exists.  Now not all all elements have children, in fact most don't, so for those I don't even bother creating a List<T> instance and there for don't have anything to attach the Enumerator to. 


In Topic: Vector Projection with zero length

20 August 2013 - 06:25 AM

I want to point out that the code in the OP is not very robust: If the input is the vector (0, epsilon) --where epsilon is a number so small that its square is 0--, the code will still divide by zero.

How about this then? 

        public static Vector2 Project(this Vector2 A, Vector2 B)
        {
            float DotOverDot = Vector2.Dot(A, B) / Vector2.Dot(A, A);
            if (float.IsNaN(DotOverDot) || float.IsInfinity(DotOverDot))
                return Vector2.Zero;
            else
                return Vector2.Multiply(A, DotOverDot);                
        }

PARTNERS