Click here to Skip to main content
15,891,567 members

Comments by grgran (Top 3 by date)

grgran 19-Dec-16 10:51am View    
It would seem to me that particularly irregular polygons could produce sums greater than 2pi, because "wedges" (triangles formed by the test point and edge points) could overlap. Imagine a shape where a "left" edge point connected to a point into the polygon inside and near the "right" edge. I wish I could draw here :-)
grgran 19-Dec-16 10:44am View    
Thumbs up for doing this in COBOL :-) !
grgran 29-Nov-10 18:14pm View    
Deleted
Thanks for sharing. You might want to consider some changes. For example the StringBuilder class now has a Clear method so you should be able to remove that for 4.0 code. You might also consider some optimization for anything that does a ToString() like SubString(). Consider this (untested, but the ideas should be clear):

///
/// Returns a substrings the specified StringBuilder, like String.Substring().
///

/// <param name="sb">The StringBuilder source.</param>
/// <param name="startIndex">The start index.</param>
/// <param name="length">The length.</param>
/// <returns>
public static string Substring(this StringBuilder sb, int startIndex, int length) {
if (sb == null) {
sb = new StringBuilder();
// or throw ArgumentNullException
}
if (length == 0) { return String.Empty; }
if (length > (sb.Length / 2)) { // just a guess, prob'ly needs a more dynamic algo
return sb.ToString(startIndex, length);
}
if (startIndex < 0) { throw new ArgumentException(); }
if (length < 0) { throw new ArgumentException(); }
var end = (startIndex + length) - 1; // end is never < 0
if (end > sb.Length) {
end = sb.Length - 1;
length = end - startIndex;
// or throw ArgumentException
}
var chars = new char[length];
int k = 0;
for (int i = startIndex; i <= end; i++) {
chars[k++] = sb[i];
}
return new String(chars);
}

This adds some safety checks and would provide better performance when short substrings are required from large stringbuilders.

Cheers