97 |
#endif |
#endif |
98 |
public sealed class Region : MarshalByRefObject, IDisposable |
public sealed class Region : MarshalByRefObject, IDisposable |
99 |
{ |
{ |
100 |
|
// Internal byte representation of the region |
101 |
|
private RegionData rgnData; |
102 |
// Overall extent of the region |
// Overall extent of the region |
103 |
private RectangleF extent; |
private RectangleF extent; |
104 |
// rectangles that make up the region sorted top to bottom, left to right |
// rectangles that make up the region sorted top to bottom, left to right |
107 |
// Constructors. |
// Constructors. |
108 |
public Region() |
public Region() |
109 |
{ |
{ |
110 |
|
rgnData = new RegionData() ; |
111 |
MakeInfinite(); |
MakeInfinite(); |
112 |
} |
} |
113 |
|
|
|
[TODO] |
|
114 |
public Region(GraphicsPath path) |
public Region(GraphicsPath path) |
115 |
{ |
{ |
116 |
if(path == null) |
if(path == null) |
117 |
{ |
{ |
118 |
throw new ArgumentNullException("path"); |
throw new ArgumentNullException("path"); |
119 |
} |
} |
120 |
// TODO |
rgnData = new RegionData( path ); |
121 |
} |
} |
122 |
|
|
123 |
public Region(Rectangle rect) : this( (RectangleF)rect) |
public Region(Rectangle rect) : this( (RectangleF)rect) |
125 |
|
|
126 |
public Region(RectangleF rect) |
public Region(RectangleF rect) |
127 |
{ |
{ |
128 |
|
rgnData = new RegionData( rect ); |
129 |
if (rect.Width < 0) |
if (rect.Width < 0) |
130 |
rect = new RectangleF(rect.Right, rect.Top, -rect.Width, rect.Height); |
rect = new RectangleF(rect.Right, rect.Top, -rect.Width, rect.Height); |
131 |
if (rect.Height < 0) |
if (rect.Height < 0) |
142 |
// extent is already empty(0,0,0,0) |
// extent is already empty(0,0,0,0) |
143 |
rects = new RectangleF[0]; |
rects = new RectangleF[0]; |
144 |
} |
} |
|
|
|
145 |
} |
} |
146 |
|
|
147 |
private Region(int initialRectSize) |
private Region(int initialRectSize) |
149 |
rects = new RectangleF[initialRectSize]; |
rects = new RectangleF[initialRectSize]; |
150 |
} |
} |
151 |
|
|
152 |
[TODO] |
public Region(RegionData otherRgnData) |
|
public Region(RegionData rgnData) |
|
153 |
{ |
{ |
154 |
if(rgnData == null) |
if(otherRgnData == null) |
155 |
{ |
{ |
156 |
throw new ArgumentNullException("rgnData"); |
throw new ArgumentNullException("rgnData"); |
157 |
} |
} |
158 |
// TODO |
Region r = otherRgnData.ConstructRegion ( otherRgnData ) ; |
159 |
|
this.rects = r.rects ; |
160 |
|
this.extent = r.extent ; |
161 |
|
this.rgnData = r.GetRegionData() ; |
162 |
} |
} |
163 |
|
|
164 |
// Helpers, to replace missing "Math" class in some profiles. |
// Helpers, to replace missing "Math" class in some profiles. |
211 |
public Region Clone() |
public Region Clone() |
212 |
{ |
{ |
213 |
Region newRegion = new Region(); |
Region newRegion = new Region(); |
214 |
|
newRegion.rgnData = rgnData.Clone(); |
215 |
newRegion.rects = (RectangleF[])rects.Clone(); |
newRegion.rects = (RectangleF[])rects.Clone(); |
216 |
newRegion.extent = extent; |
newRegion.extent = extent; |
217 |
return newRegion; |
return newRegion; |
235 |
|
|
236 |
public void Complement(Region region) |
public void Complement(Region region) |
237 |
{ |
{ |
238 |
|
rgnData.Complement( region ) ; |
239 |
Region subtract = Subtract(region, this); |
Region subtract = Subtract(region, this); |
240 |
extent = subtract.extent; |
extent = subtract.extent; |
241 |
rects = subtract.rects; |
rects = subtract.rects; |
301 |
|
|
302 |
public void Exclude(Region region) |
public void Exclude(Region region) |
303 |
{ |
{ |
304 |
|
rgnData.Exclude( region ) ; |
305 |
Region subtract = Subtract(this, region); |
Region subtract = Subtract(this, region); |
306 |
extent = subtract.extent; |
extent = subtract.extent; |
307 |
rects = subtract.rects; |
rects = subtract.rects; |
328 |
} |
} |
329 |
|
|
330 |
// Get the raw region data for this region. |
// Get the raw region data for this region. |
|
[TODO] |
|
331 |
public RegionData GetRegionData() |
public RegionData GetRegionData() |
332 |
{ |
{ |
333 |
return null; |
return rgnData; |
334 |
} |
} |
335 |
|
|
336 |
// Get an array of rectangles that represents this region. |
// Get an array of rectangles that represents this region. |
373 |
|
|
374 |
public void Intersect(Region region) |
public void Intersect(Region region) |
375 |
{ |
{ |
376 |
|
rgnData.Intersect(region); |
377 |
Intersect(this, region); |
Intersect(this, region); |
378 |
} |
} |
379 |
|
|
499 |
// Make this region empty. |
// Make this region empty. |
500 |
public void MakeEmpty() |
public void MakeEmpty() |
501 |
{ |
{ |
502 |
|
rgnData.MakeEmpty() ; |
503 |
rects = new RectangleF[0]; |
rects = new RectangleF[0]; |
504 |
extent = Rectangle.Empty; |
extent = Rectangle.Empty; |
505 |
} |
} |
507 |
// Make this region infinite. |
// Make this region infinite. |
508 |
public void MakeInfinite() |
public void MakeInfinite() |
509 |
{ |
{ |
510 |
|
rgnData.MakeInfinite() ; |
511 |
const float maxCoord = 4194304; //Math.Pow(2, 22) |
const float maxCoord = 4194304; //Math.Pow(2, 22) |
512 |
extent = new RectangleF(-maxCoord, -maxCoord, 2 * maxCoord, 2 * maxCoord); |
extent = new RectangleF(-maxCoord, -maxCoord, 2 * maxCoord, 2 * maxCoord); |
513 |
rects = new RectangleF[1] { extent }; |
rects = new RectangleF[1] { extent }; |
517 |
[TODO] |
[TODO] |
518 |
public void Transform(Matrix matrix) |
public void Transform(Matrix matrix) |
519 |
{ |
{ |
520 |
// TODO |
rgnData.Transform( matrix ) ; |
521 |
|
// TODO: other state variables |
522 |
} |
} |
523 |
|
|
524 |
// Translate this matrix by a specific amount. |
// Translate this matrix by a specific amount. |
529 |
|
|
530 |
public void Translate(float dx, float dy) |
public void Translate(float dx, float dy) |
531 |
{ |
{ |
532 |
|
rgnData.Translate( dx, dy ) ; |
533 |
for( int i = 0; i < rects.Length; i++) |
for( int i = 0; i < rects.Length; i++) |
534 |
rects[i].Offset(dx, dy); |
rects[i].Offset(dx, dy); |
535 |
if (rects.Length>0) |
if (rects.Length>0) |
554 |
|
|
555 |
public void Union(Region region) |
public void Union(Region region) |
556 |
{ |
{ |
557 |
|
rgnData.Union( region ); |
558 |
Union (this, region); |
Union (this, region); |
559 |
} |
} |
560 |
|
|
1282 |
|
|
1283 |
public void Xor(Region region) |
public void Xor(Region region) |
1284 |
{ |
{ |
1285 |
|
rgnData.Xor( region ) ; |
1286 |
Region reg1 = Subtract(this, region); |
Region reg1 = Subtract(this, region); |
1287 |
Union(reg1, Subtract(region, this)); |
Union(reg1, Subtract(region, this)); |
1288 |
extent = reg1.extent; |
extent = reg1.extent; |