15,891,473 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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