33using System.Runtime.InteropServices;
37 [StructLayout(LayoutKind.Sequential, Size = BoundingRectangle.Size)]
38 [AdvBrowsableOrder(
"Min,Max")]
39#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
49 FromVectors(ref matrix, rect.Corners(), out result);
62 if (first.
X > second.
X)
64 result.
Max.
X = first.
X;
65 result.
Min.
X = second.
X;
69 result.
Max.
X = second.
X;
70 result.
Min.
X = first.
X;
72 if (first.
Y > second.
Y)
74 result.
Max.
Y = first.
Y;
75 result.
Min.
Y = second.
Y;
79 result.
Max.
Y = second.
Y;
80 result.
Min.
Y = first.
Y;
86 if (first.X > second.X)
88 result.Max.X = first.X;
89 result.Min.X = second.X;
93 result.Max.X = second.X;
94 result.Min.X = first.X;
96 if (first.Y > second.Y)
98 result.Max.Y = first.Y;
99 result.Min.Y = second.Y;
103 result.Max.Y = second.Y;
104 result.Min.Y = first.Y;
121 if (vectors ==
null) {
throw new ArgumentNullException(
"vectors"); }
122 if (vectors.Length == 0) {
throw new ArgumentOutOfRangeException(
"vectors"); }
123 result.Max = vectors[0];
124 result.
Min = vectors[0];
125 for (
int index = 1; index < vectors.Length; ++index)
128 if (current.
X > result.Max.X)
130 result.
Max.
X = current.
X;
132 else if (current.
X < result.Min.X)
134 result.Min.X = current.
X;
136 if (current.
Y > result.Max.Y)
138 result.Max.Y = current.
Y;
140 else if (current.
Y < result.Min.Y)
142 result.Min.Y = current.
Y;
148 if (vectors ==
null) {
throw new ArgumentNullException(
"vectors"); }
149 if (vectors.Length == 0) {
throw new ArgumentOutOfRangeException(
"vectors"); }
153 result.
Max = current;
154 result.
Min = current;
155 for (
int index = 1; index < vectors.Length; ++index)
158 if (current.X > result.Max.X)
160 result.
Max.
X = current.X;
162 else if (current.X < result.Min.X)
164 result.Min.X = current.X;
166 if (current.Y > result.Max.Y)
168 result.Max.Y = current.Y;
170 else if (current.Y < result.Min.Y)
172 result.Min.Y = current.Y;
178 if (vectors ==
null) {
throw new ArgumentNullException(
"vectors"); }
179 if (vectors.Length == 0) {
throw new ArgumentOutOfRangeException(
"vectors"); }
183 result.
Max = current;
184 result.
Min = current;
185 for (
int index = 1; index < vectors.Length; ++index)
188 if (current.X > result.Max.X)
190 result.
Max.
X = current.X;
192 else if (current.X < result.Min.X)
194 result.Min.X = current.X;
196 if (current.Y > result.Max.Y)
198 result.Max.Y = current.Y;
200 else if (current.Y < result.Min.Y)
202 result.Min.Y = current.Y;
205 result.Max.X += matrix.m02;
206 result.Max.Y += matrix.m12;
207 result.Min.X += matrix.m02;
208 result.Min.Y += matrix.m12;
225 Vector2D.
Max(ref first.Max, ref second.Max, out result.Max);
226 Vector2D.
Min(ref first.Min, ref second.Min, out result.Min);
243 Vector2D.
Min(ref first.Max, ref second.Max, out result.Max);
244 Vector2D.
Max(ref first.Min, ref second.Min, out result.Min);
255 result.Max.X = circle.Position.X + circle.Radius;
256 result.Max.Y = circle.Position.Y + circle.Radius;
257 result.Min.X = circle.Position.X - circle.Radius;
258 result.Min.Y = circle.Position.Y - circle.Radius;
264 FromCircle(ref matrix, ref radius, out result);
269 Scalar xRadius = matrix.m01 * matrix.m01 + matrix.m00 * matrix.m00;
270 xRadius = ((xRadius == 1) ? (radius) : (radius *
MathHelper.
Sqrt(xRadius)));
271 Scalar yRadius = matrix.m10 * matrix.m10 + matrix.m11 * matrix.m11;
272 yRadius = ((yRadius == 1) ? (radius) : (radius *
MathHelper.
Sqrt(yRadius)));
274 result.Max.X = matrix.m02 + xRadius;
275 result.Min.X = matrix.m02 - xRadius;
276 result.Max.Y = matrix.m12 + yRadius;
277 result.Min.Y = matrix.m12 - yRadius;
305 [InstanceConstructor(
"Min,Max")]
348 if (xDistance > 0 && yDistance > 0)
350 result =
MathHelper.
Sqrt(xDistance * xDistance + yDistance * yDistance);
354 result = Math.Max(xDistance, yDistance);
360 if (point.
X <=
Max.
X &&
375 if (point.X <=
Max.
X &&
390 if (this.Min.
X > rect.
Max.
X ||
391 this.Min.Y > rect.
Max.
Y ||
392 this.Max.X < rect.
Min.
X ||
393 this.Max.Y < rect.
Min.
Y)
398 this.Min.
X <= rect.
Min.
X &&
399 this.Min.Y <= rect.
Min.
Y &&
400 this.Max.X >= rect.
Max.
X &&
401 this.Max.Y >= rect.
Max.
Y)
412 if (this.Min.
X > rect.Max.X ||
413 this.Min.Y > rect.Max.Y ||
414 this.Max.X < rect.Min.X ||
415 this.Max.Y < rect.Min.Y)
420 this.Min.
X <= rect.Min.X &&
421 this.Min.Y <= rect.Min.Y &&
422 this.Max.X >= rect.Max.X &&
423 this.Max.Y >= rect.Max.Y)
458 if ((circle.Position.X + circle.Radius) <=
Max.
X &&
459 (circle.Position.X - circle.Radius) >=
Min.
X &&
460 (circle.Position.Y + circle.Radius) <=
Max.
Y &&
461 (circle.Position.Y - circle.Radius) >=
Min.
Y)
468 circle.Intersects(ref
this, out intersects);
488 if (polygon ==
null) {
throw new ArgumentNullException(
"polygon"); }
489 Vector2D[] vertexes = polygon.Vertexes;
491 for (
int index = 0; index < vertexes.Length && result !=
ContainmentType.Intersects; ++index)
494 Contains(ref vertexes[index], out con);
500 polygon.Intersects(ref
this, out test);
517 this.Min.
X < rect.
Max.
X &&
518 this.Max.
X > rect.
Min.
X &&
519 this.Max.
Y > rect.
Min.
Y &&
520 this.Min.
Y < rect.
Max.
Y;
536 if (polygon ==
null) {
throw new ArgumentNullException(
"polygon"); }
553 if (ray.Origin.X <
Min.
X && ray.Direction.X > 0)
555 distance = (
Min.
X - ray.Origin.X) / ray.Direction.X;
558 intersectValue = ray.Origin.Y + ray.Direction.Y * distance;
559 if (intersectValue >=
Min.
Y && intersectValue <=
Max.
Y &&
560 (result == -1 || distance < result))
566 if (ray.Origin.X >
Max.
X && ray.Direction.X < 0)
568 distance = (
Max.
X - ray.Origin.X) / ray.Direction.X;
571 intersectValue = ray.Origin.Y + ray.Direction.Y * distance;
572 if (intersectValue >=
Min.
Y && intersectValue <=
Max.
Y &&
573 (result == -1 || distance < result))
579 if (ray.Origin.Y <
Min.
Y && ray.Direction.Y > 0)
581 distance = (
Min.
Y - ray.Origin.Y) / ray.Direction.Y;
584 intersectValue = ray.Origin.X + ray.Direction.X * distance;
585 if (intersectValue >=
Min.
X && intersectValue <=
Max.
X &&
586 (result == -1 || distance < result))
592 if (ray.Origin.Y >
Max.
Y && ray.Direction.Y < 0)
594 distance = (
Max.
Y - ray.Origin.Y) / ray.Direction.Y;
597 intersectValue = ray.Origin.X + ray.Direction.X * distance;
598 if (intersectValue >=
Min.
X && intersectValue <=
Max.
X &&
599 (result == -1 || distance < result))
609 this.Min.
X <= rect.Max.X &&
610 this.Max.
X >= rect.Min.X &&
611 this.Max.
Y >= rect.Min.Y &&
612 this.Min.
Y <= rect.Max.Y;
616 circle.Intersects(ref
this, out result);
620 if (polygon ==
null) {
throw new ArgumentNullException(
"polygon"); }
621 polygon.Intersects(ref
this, out result);
625 line.Intersects(ref
this, out result);
630 return string.Format(
"{0} < {1}",
Min,
Max);
639 return Equals(ref
this, ref other);
643 return Equals(ref rect1, ref rect2);
656 return Equals(ref rect1, ref rect2);
660 return !
Equals(ref rect1, ref rect2);
static bool Intersects(Vector2D[] vertexes1, Vector2D[] vertexes2)
static Scalar Sqrt(Scalar d)
Scalar Intersects(Ray ray)
Scalar Intersects(Ray ray)
static void FromCircle(ref Matrix2x3 matrix, ref Scalar radius, out BoundingRectangle result)
ContainmentType Contains(BoundingRectangle rect)
bool Intersects(BoundingRectangle rect)
void GetDistance(ref Vector2D point, out Scalar result)
ContainmentType Contains(BoundingCircle circle)
static void FromUnion(ref BoundingRectangle first, ref BoundingRectangle second, out BoundingRectangle result)
void Intersects(ref BoundingRectangle rect, out bool result)
BoundingRectangle(Scalar minX, Scalar minY, Scalar maxX, Scalar maxY)
Creates a new BoundingRectangle Instance.
void Intersects(ref Ray ray, out Scalar result)
static BoundingRectangle FromCircle(BoundingCircle circle)
override bool Equals(object obj)
static bool operator==(BoundingRectangle rect1, BoundingRectangle rect2)
static bool operator!=(BoundingRectangle rect1, BoundingRectangle rect2)
void Intersects(ref Line line, out bool result)
bool Intersects(Line line)
void Contains(ref BoundingPolygon polygon, out ContainmentType result)
bool Intersects(BoundingPolygon polygon)
bool Equals(BoundingRectangle other)
static void FromVectors(ref Vector2D first, ref Vector2D second, out BoundingRectangle result)
void Contains(ref BoundingRectangle rect, out ContainmentType result)
static void FromIntersection(ref BoundingRectangle first, ref BoundingRectangle second, out BoundingRectangle result)
void Contains(ref BoundingCircle circle, out ContainmentType result)
static BoundingRectangle FromIntersection(BoundingRectangle first, BoundingRectangle second)
Makes a BoundingRectangle that contains the area where the BoundingRectangles Intersect.
static void Transform(ref Matrix2x3 matrix, ref BoundingRectangle rect, out BoundingRectangle result)
ContainmentType Contains(BoundingPolygon polygon)
static BoundingRectangle FromUnion(BoundingRectangle first, BoundingRectangle second)
Makes a BoundingRectangle that can contain the 2 BoundingRectangles passed.
static void FromVectors(ref Matrix3x3 matrix, Vector2D[] vectors, out BoundingRectangle result)
static void FromVectors(Vector2D[] vectors, out BoundingRectangle result)
static BoundingRectangle FromVectors(Vector2D first, Vector2D second)
Creates a new BoundingRectangle Instance from 2 Vector2Ds.
void Contains(ref Vector2D point, out ContainmentType result)
static bool Equals(BoundingRectangle rect1, BoundingRectangle rect2)
bool Intersects(BoundingCircle circle)
override string ToString()
override int GetHashCode()
static bool Equals(ref BoundingRectangle rect1, ref BoundingRectangle rect2)
void Intersects(ref BoundingCircle circle, out bool result)
void Intersects(ref BoundingPolygon polygon, out bool result)
ContainmentType Contains(Vector2D point)
static void FromVectors(ref Matrix2x3 matrix, Vector2D[] vectors, out BoundingRectangle result)
Scalar GetDistance(Vector2D point)
static BoundingRectangle FromVectors(Vector2D[] vectors)
Creates a new BoundingRectangle Instance from multiple Vector2Ds.
BoundingRectangle(Vector2D min, Vector2D max)
Creates a new BoundingRectangle Instance from 2 Vector2Ds.
static void FromCircle(ref BoundingCircle circle, out BoundingRectangle result)
static BoundingRectangle FromCircle(Matrix2x3 matrix, Scalar radius)
Scalar Intersects(Ray ray)
A 2x3 matrix which can represent rotations around axes.
A 3x3 matrix which can represent rotations around axes.
This is the Vector Class.
const int Size
The Size of the class in bytes;
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
static Vector2D Transform(Matrix3x3 matrix, Vector2D source)
Uses a matrix multiplication to Transform the vector.
static Vector2D TransformNormal(Matrix3x3 matrix, Vector2D source)
override int GetHashCode()
Provides a unique hash code based on the member variables of this class. This should be done because ...
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
override bool Equals(object obj)
Compares this Vector to another object. This should be done because the equality operators (==,...
static Vector2D Max(Vector2D value1, Vector2D value2)
static Vector2D Min(Vector2D value1, Vector2D value2)