Different behaviour in reversed and non-reversed CoordinateSequence

7 views
Skip to first unread message

Kalle Jalkanen

unread,
Apr 27, 2011, 8:18:08 AM4/27/11
to nettopol...@googlegroups.com
Hi,

I've written a method to compute the Minkowski Sum of a polygon and I've based my code on the Buffer code.
I use CoordinateSequences in my code and I happen to reverse this sequence. When noding these sequences
I get in trouble when Slice.GetOverlappingTriples is called on a reversed CoordinateSequence.

The code in GetOverlappingTriples looks like this:

           IEnumerator<TItem> it = items.GetEnumerator();                     

            Boolean moveNext = typeof (TItem).IsValueType ? it.Current.Equals(default(TItem)) : it.Current == null;
            if(moveNext)
            {
                if ( !it.MoveNext() ) yield break;
            }


CoordinateSequence.GetEnumerator returns a List<T> enumerator if non reversed and a Stack<T> if reversed. 
According to documentation it.Current is undefined until MoveNext is called. For the list it.Current works ok and returns null, but for the stack it throws an exception.

I got this working by inserting MoveNext

            IEnumerator<TItem> it = items.GetEnumerator();
            
            if (!it.MoveNext()) yield break; // <-------------------- CODE added

            Boolean moveNext = typeof (TItem).IsValueType ? it.Current.Equals(default(TItem)) : it.Current == null;
            if(moveNext)
            {
                if ( !it.MoveNext() ) yield break;
            }


I'm not sure if this is the correct way to fix, but as it is now it is not working for a reversed CoordinateSequence.

I'm using branch v2.11.


Regards,

Kalle

FObermaier

unread,
May 26, 2011, 11:53:03 AM5/26/11
to NetTopologySuite
Hello Kalle,
I finally got around to look at your issue with the v2.11 branch.
I removed the IndexComputer/ForwardIndex/ReverseIndex thing (was not
happy with it anyway) so your issue should be resolved as of rev 607.
cheers
FObermaier
Reply all
Reply to author
Forward
0 new messages