/// <summary>Constructor with Min and Max values.</summary> /// <param name="min">The min value.</param> /// <param name="max">The max value.</param> public BoundingBox(Point2D min, Point2D max) { _minX = min.X; _minY = min.Y; _maxX = max.X; _maxY = max.Y; }
//============================================================================================================================= /// <summary>Translates the current geometry.</summary> /// <param name="offset">The point describing the translation to perform.</param> /// <returns>The current geometry.</returns> //============================================================================================================================= public Point2D Translate(Point2D offset) { _x += offset._x; _y += offset._y; return this; }
//============================================================================================================================= /// <summary>Subtracts a constant from the current point.</summary> /// <param name="value">The constant to subtract.</param> /// <returns>The current point.</returns> /// <remarks>The current point is changed.</remarks> //============================================================================================================================= public Point2D SelfSubtract(Point2D pt) { _x -= pt._x; _y -= pt._y; return this; }
//============================================================================================================================= /// <summary>Multiply the current point with another point.</summary> /// <param name="point">The point to Multiply with.</param> /// <returns>The result of the Multiplication.</returns> /// <remarks>The current point is changed.</remarks> //============================================================================================================================= public Point2D SelfMultiply(Point2D pt) { _x *= pt._x; _y *= pt._y; return this; }
//============================================================================================================================= /// <summary>Divides the current point by another point.</summary> /// <param name="point">The point to divide by.</param> /// <returns>The result of the division.</returns> /// <remarks>The current point is changed.</remarks> //============================================================================================================================= public Point2D SelfDivide(Point2D pt) { _x /= pt._x; _y /= pt._y; return this; }
//============================================================================================================================= /// <summary>Divides the current point by another point.</summary> /// <param name="point">The point to divide by.</param> /// <returns>The result of the division.</returns> /// <remarks>The current point remains unchanged.</remarks> //============================================================================================================================= public Point2D Divide(Point2D pt) { return new Point2D(_x / pt._x, _y / pt._y); }
/// <summary>Tests if a point lies strictly inside the box (does not touch the border).</summary> /// <param name="pt">The point to test.</param> /// <returns>true if the point is strictly in the box.</returns> public bool IsPointStrictlyInside(Point2D pt) { return pt.X > _minX && pt.Y > _minY && pt.X < _maxX && pt.Y < _maxY; }
//============================================================================================================================= /// <summary>Rotates the current point object around a specific point.</summary> /// <param name="center">The center of the rotation.</param> /// <param name="angle">The angle in radians.</param> //============================================================================================================================= public void RotateRadians(Point2D center, double angle) { Point2D temp = this; temp -= center; temp.RotateRadians(angle); temp += center; _x = temp.X; _y = temp.Y; }
//============================================================================================================================= /// <summary>Subtracts a point from the current point.</summary> /// <param name="point">The point to subtract.</param> /// <returns>The result of the subtraction.</returns> /// <remarks>The current point remains unchanged.</remarks> //============================================================================================================================= public Point2D Subtract(Point2D point) { return new Point2D(_x - point._x, _y - point._y); }
//============================================================================================================================= /// <summary>Return the current point added with a constant. </summary> /// <param name="point">The Constant to add.</param> /// <returns>The result of the addition.</returns> /// <remarks>The current point is modificed.</remarks> //============================================================================================================================= public Point2D SelfAdd(Point2D point) { _x += point._x; _y += point._y; return this; }
//============================================================================================================================= /// <summary>Return a new point with the sum of a point and the current point. </summary> /// <param name="point">The point to add.</param> /// <returns>The result of the addition.</returns> /// <remarks>The current point remains unchanged.</remarks> //============================================================================================================================= public Point2D Add(Point2D point) { return new Point2D(_x + point._x, _y + point._y); }
//============================================================================================================================= /// <summary>Calculate the dot product of 2 points.</summary> /// <param name="point">The 2nd point.</param> /// <returns>The dot product.</returns> //============================================================================================================================= public double Dot(Point2D point) { return (_x * point._x) + (_y * point._y); }
/// <summary>Adjust the box to fit the point.</summary> /// <param name="pt">The point.</param> public void Adjust(Point2D pt) { if (pt.X < _minX) _minX = pt.X; if (pt.X > _maxX) _maxX = pt.X; if (pt.Y < _minY) _minY = pt.Y; if (pt.Y > _maxY) _maxY = pt.Y; }
/// <summary>Sets the min and max points of the box.</summary> /// <param name="min">The min point of the box.</param> /// <param name="max">The max point of the box.</param> public void Set(Point2D min, Point2D max) { _minX = min.X; _minY = min.Y; _maxX = max.X; _maxY = max.Y; }
//============================================================================================================================= /// <summary>Rotates the current point object around a specific point.</summary> /// <param name="center">The center of the rotation.</param> /// <param name="angle">The angle in degrees.</param> //============================================================================================================================= public void Rotate(Point2D center, double angle) { RotateRadians(center, Util.ToRadians(angle)); }
//============================================================================================================================= /// <summary>Copy constructor.</summary> /// <param name="point">The source point.</param> //============================================================================================================================= public Point2D(Point2D point) { _x = point._x; _y = point._y; }
//============================================================================================================================= /// <summary>Rotates the current point object around the origin.</summary> /// <param name="angle">The angle in radians.</param> //============================================================================================================================= public void RotateRadians(double angle) { Point2D temp = new Point2D(this); _x = temp._x * Math.Cos(angle) - temp._y * Math.Sin(angle); _y = temp._x * Math.Sin(angle) + temp._y * Math.Cos(angle); }
//============================================================================================================================= /// <summary>Multiplies the current point by another point.</summary> /// <param name="point">The point to multiply by.</param> /// <returns>The result of the multiplication.</returns> /// <remarks>The current point remains unchanged.</remarks> //============================================================================================================================= public Point2D Multiply(Point2D point) { return new Point2D(_x * point._x, _y * point._y); }
//===================================================================== /// /// <summary> /// Scales the shape primitive to a base point. /// </summary> /// <param name="factor">The scale factor.</param> /// <param name="pt">The base point.</param> /// //===================================================================== public void Scale(double factor, Point2D pt) { Point2D pt2 = this - pt; pt2 *= factor; this._x = pt2._x + pt._x; this._y = pt2._y + pt._y; }
/// <summary>Tests if a point lies inside the box.</summary> /// <param name="pt">The point to test.</param> /// <returns>true if the point is in the box.</returns> public bool Contains(Point2D pt) { return pt.X >= _minX && pt.Y >= _minY && pt.X <= _maxX && pt.Y <= _maxY; }