|
Exactly what I would have recommended. The better algorithms can even deal with concave polygons or 'holes'.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
There is a better algorithm than adding triangles
It is quite straight forward you need calculate two sums
sum1 = sum of ( pt[i].x * pt[i+1 % n].y)
sum2 = sum of ( pt[i+1 % n].x * pt[i].y)
then the area is sum1 - sum2
http://www.mathopenref.com/coordpolygonarea.html[^]
|
|
|
|
|
Excellent.
|
|
|
|
|
Be aware that this method does not work with polygons with crossovers. Mind you, that is true of simplistic triangulators too.
This is a good link if the OP does not need the triangulated form for other purposes (e.g. collision detection).
|
|
|
|
|
Excellent answer, and an interesting site, thanks +5 !
It appears this algorithm will work on polygons that have areas that "go inward," as long as they do not cross.
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
I need to get the free physical memory available so I don't get OutOfMemory Exception.
I have tried GlobalMemoryStatusEx but it seems the windows swaps out ram to virtual and the value is unreliable and ultimately results in out of memory also.
Any thoughts?
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|
|
You might want to have a look at MemoryFailPoint Class[^].
Creating an instance of a MemoryFailPoint class creates a memory gate. A memory gate is a check for sufficient resources prior to initiating an activity requiring a large amount of memory. Failing the check throws an InsufficientMemoryException[^] that avoids starting an operation, reducing the possibility of an application failing during execution due to lack of resources. This allows an application to decrease its performance in an effort to avoid an OutOfMemoryException[^] and any state corruption that may result from improper handling of an OutOfMemoryException[^] in arbitrary locations in code.
0100000101101110011001000111001011101001
|
|
|
|
|
Getting the free Physical memory will not necessarily help avoid an OutOfMemory exception - .NET is perfectly happy using virtual memory.
Have a look at this article: it covers the OOM problem in some depth. http://msdn.microsoft.com/en-us/magazine/cc163528.aspx[^]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
And running out of physical memory is not the only way to throw an OutOfMemory exception. Try running the handle pool dry and you'll do the same thing, even though there's plenty of free memory.
You can do this by creating and NOT disposing of Brushs, Pens, Graphics objects, Forms shown with ShowDialog, ...
|
|
|
|
|
I'm a relatively new c# programmer (transitioning from C++)and am working with a grid application. I've successfully bound the grid to a data structure but would now like to get rid of 0s in the rows. There must be an easy way to tell the grid to show nothing if the default value (or user input is 0) but I haven't found it. Also, I'd like to know if there's an easy way to do data validation on individual columns (ie non-negative int, double, etc.) Thank you.
|
|
|
|
|
Tom Paronis wrote: There must be an easy way to tell the grid to show nothing if the default value
(or user input is 0) but I haven't found it.
There's an event that you could use; CellFormatting[^], and there's a how to[^] article on MSDN explaining formatting that would be helpfull.
There's also a walktrough[^] available on MSDN.
Bastard Programmer from Hell
|
|
|
|
|
Thanks. This is the second time I've been bailed out by the Bastard programmer from Hell. I owe you a drink.
|
|
|
|
|
You're welcome, and thanks for the coffee
|
|
|
|
|
Using 0 for your default value is quite dangerous (0 is often a valid input). If you're using a floating point type, NaN is quite good for 'missing data', and this should be what you use in your data model. For integer types you can either specify a special value or use int? and use null for missing. You can then use the CellFormatting tip to show a blank cell when the actual value matches your designated 'null' value.
|
|
|
|
|
Thanks. I've just developed an abhorrence over the years of seeing a whole lot of 0s on the screen when all it means is that the user hasn't filled the data in yet.
|
|
|
|
|
Greetings Gurus,
Come across a problem I don't seem able to solve and was hoping someone could point me in the right direction.
I am building a Windows service which records Event log entries in a sql db. Running it as a console application works fine but when I try and move the code into a service structure I get errors.
My code
public partial class GetInfo : ServiceBase
{
public ServiceName()
{
InitializeComponent();
}
static AutoResetEvent appsignal, syssignal, secsignal;
public static void Main()
{
What should I use in place of "public static void Main"?
I would like to keep this out of the "Onstart" region because I want it to initialise before the service's timer.
Can you help?
|
|
|
|
|
|
Hi again André,
The actual service works (it pulls 2 other sets of metrics of the machine as well). The problem is that the event log watcher doesn't log events to the sql db. No errors, builds fine, works as a console app but just wont log the event log entries.
The link you sent was one that I had used when initially building the base service but thanks for the assist anyway
|
|
|
|
|
It can be failing silently in your code and thus wouldn't log the errors to your DB. You need to add logging to a file (for debugging I mean, not for your real production code) or something more "bullet proof" then a DB. Just off the top of my head, I'd guess its a permissions issue coming from the service.
|
|
|
|
|
Hi Sledge,
I have "try/catch" and the beginning and end of each eventlogwatcher segment as well as console.writelines. No errors are caught by "try/catch" but also there is no printout from the console.writeline.
Its not permissions because all the code surrounding the eventlog watcher runs and reports perfectly.
Its just this one segment that seems to do nothing while everything around performs as expected.
|
|
|
|
|
hello guys.. I have a struct in class A. In one of its function, I returned this struct. I tried something like this (all the getters and setters are there properly)
class A
{
struct MyStruct
{};
public MyStruct func()
{
MyStruct struc = new MyStruct();
return struc;
}
}
class B
{
struct MyStruct
{};
A = new A();
MyStruct result = new MyStruct();
result = A.func();
}
But I get the error
Cannot implicitly convert type 'A.MyStruct' to 'B.MyStruct'. Whats wrong with it? thnx
|
|
|
|
|
You have defined MyStruct in both class A and class B. That means that the compiler will see them as different even if their internal structure is the same.
Define MyStruct outside of the class boundaries only once and your issue will go away.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
thnx..it solved my problem. But let me tell you that I did following
A.MyStruct result = new A.MyStruct();
Is it OK to do so?
|
|
|
|
|
Absolutely, it can be done that way as well.
My personal thought on the matter is that unless A.MyStruct is required to be tightly coupled to class A, it should stand on it's own outside of the class, but like I said earlier, what you have done is perfectly valid.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
class A and class B both have nested structs named MyStruct defined. In class B you have MyStruct result = new MyStruct(); If you intend to use A.MyStruct objects in class B then you need to be explicit:
A.MyStruct result = new A.MyStruct();
Mark Salsbery
|
|
|
|