Not A Rectangle

  • Thread starter Thread starter woodBeeProgrammer
  • Start date Start date
W

woodBeeProgrammer

this is a repost of a languishing query. is there a conventional value for
"NAR" (Not A Rectangle) that Rectangle may be initialized to, sort of like
NAN for doubles?

Thanks in advance!!
 
woodBeeProgrammer said:
is there a conventional value for "NAR" (Not A
Rectangle) that Rectangle may be initialized to,
sort of like NAN for doubles?

Rectangle is a reference type, so you can set it to null.

If that isn't good enough, I suppose you could inherit from Rectangle
(assuming it isn't a sealed class) and add an extra member to the derived
class to indicate whether the rectangle is initialised.

P.
 
this is a repost of a languishing query. is there a conventional value
for
"NAR" (Not A Rectangle) that Rectangle may be initialized to, sort of like
NAN for doubles?

You could use an empty rectangle to denote a 'Not A Rectangle'. If the
x,y,width and height properties are zero, the IsEmpty property returns true.

n!
 
umm, i believe Rectangle is a value type (struct System.Drawing.Rectangle).

the obvious initialization of X=Y=Length=Height= 0 is problematic because it
is potentially a reasonable value (i think).

a better NAR choice would be something like Length = -1, which i can do for
myself, but i'd think this must be a standard problem with a standard
answer..

yes?? no??
 
There is really nothing called an "invalid" rectangle. It depends on
interpretation.

However, the framework provides IsEmpty that will return true if x, y, width
and height are all 0s.

Negative values are perfectly valid values for Width and height of a
rectangle (imagine you're drawing a rband rectangle - going past the left of
the starting point will yeild a rectangle with negative width)

-vJ
 
It's a value type. However, you can create a boxed reference of type object,
and set the reference to null or to a valid triangle. Kinda nasty if you
take into account the boxing perf hits. Best bet is to set a no-area
rectangle value (like 0,0,0,0) to mean "not-a-rectangle".

-Rob Teixeira [MVP]
 
Back
Top