Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Spherei"/> using the specified location and radius.
 /// </summary>
 /// <param name="center">The center of the sphere.</param>
 /// <param name="radius">The radius of the sphere.</param>
 public Spherei(Point3i center, int radius)
 {
     Contract.Requires(0 <= radius);
     X      = center.X;
     Y      = center.Y;
     Z      = center.Z;
     Radius = radius;
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Boxi"/> using the specified location and size.
 /// </summary>
 /// <param name="location">The front-lower-left corner of the box.</param>
 /// <param name="width">Value for the Width component of the box.</param>
 /// <param name="height">Value for the Height component of the box.</param>
 /// <param name="depth">Value for the Depth component of the box.</param>
 public Boxi(Point3i location, int width, int height, int depth)
 {
     X      = location.X;
     Y      = location.Y;
     Z      = location.Z;
     Width  = width;
     Height = height;
     Depth  = depth;
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Boxi"/> using the specified location and size.
 /// </summary>
 /// <param name="location">The front-lower-left corner of the box.</param>
 /// <param name="size">The size of the box.</param>
 public Boxi(Point3i location, Size3i size)
 {
     X      = location.X;
     Y      = location.Y;
     Z      = location.Z;
     Width  = size.Width;
     Height = size.Height;
     Depth  = size.Depth;
 }
Example #4
0
        public                     Point3i[] ToArray()
        {
            var result = new Point3i[Count];

            for (int i = 0; i < Count; ++i)
            {
                result[i] = this[i];
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// Reads a <see cref="Polygon3i"/> from an <see cref="Ibasa.IO.BinaryReader">.
        /// </summary>
        public static Polygon3i ReadPolygon3i(this Ibasa.IO.BinaryReader reader)
        {
            var length = reader.ReadInt32();
            var array  = new Point3i[length];

            for (int i = 0; i < length; ++i)
            {
                array[i] = reader.ReadPoint3i();
            }
            return(new Polygon3i(array));
        }
Example #6
0
        /// <summary>
        /// Transforms a point in cartesian coordinates to spherical coordinates.
        /// </summary>
        /// <param name="value">The point to transform.</param>
        /// <returns>The spherical coordinates of value.</returns>
        public static SphericalCoordinate CartesianToSpherical(Point3i value)
        {
            double r     = Functions.Sqrt(value.X * value.X + value.Y * value.Y + value.Z * value.Z);
            double theta = Functions.Atan2(value.Y, value.X);

            if (theta < 0)
            {
                theta += 2 * Constants.Pi;
            }
            return(new SphericalCoordinate(
                       r,
                       (double)Functions.Acos(value.Z / r),
                       theta));
        }
Example #7
0
 /// <summary>
 /// Determines whether any component of a point is non-zero.
 /// </summary>
 /// <param name="value">A point.</param>
 /// <returns>true if any components are non-zero; false otherwise.</returns>
 public static bool Any(Point3i value)
 {
     return(value.X != 0 || value.Y != 0 || value.Z != 0);
 }
Example #8
0
 /// <summary>
 /// Determines whether all components of a point satisfy a condition.
 /// </summary>
 /// <param name="value">A point.</param>
 /// <param name="predicate">A function to test each component for a condition.</param>
 /// <returns>true if every component of the point passes the test in the specified
 /// predicate; otherwise, false.</returns>
 public static bool All(Point3i value, Predicate <int> predicate)
 {
     return(predicate(value.X) && predicate(value.Y) && predicate(value.Z));
 }
Example #9
0
 /// <summary>
 /// Determines whether all components of a point are non-zero.
 /// </summary>
 /// <param name="value">A point.</param>
 /// <returns>true if all components are non-zero; false otherwise.</returns>
 public static bool All(Point3i value)
 {
     return(value.X != 0 && value.Y != 0 && value.Z != 0);
 }
Example #10
0
 /// <summary>
 /// Maps the components of a point and returns the result.
 /// </summary>
 /// <param name="value">The point to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Point3f Map(Point3i value, Func <int, float> mapping)
 {
     return(new Point3f(mapping(value.X), mapping(value.Y), mapping(value.Z)));
 }
Example #11
0
 public static bool Contains(Spherei sphere, Point3i point)
 {
     return(Vector.AbsoluteSquared(sphere.Center - point) <= sphere.Radius * sphere.Radius);
 }
Example #12
0
 /// <summary>
 /// Returns the product of a point and scalar.
 /// </summary>
 /// <param name="point">The point to multiply.</param>
 /// <param name="scalar">The scalar to multiply.</param>
 /// <returns>The product of the left and right parameters.</returns>
 public static Point3i Multiply(Point3i point, int scalar)
 {
     return(new Point3i(point.X * scalar, point.Y * scalar, point.Z * scalar));
 }
Example #13
0
 /// <summary>
 /// Divides a point by a scalar and returns the result.
 /// </summary>
 /// <param name="point">The point to be divided (the dividend).</param>
 /// <param name="scalar">The scalar to divide by (the divisor).</param>
 /// <returns>The result of dividing left by right (the quotient).</returns>
 public static Point3i Divide(Point3i point, int scalar)
 {
     return(new Point3i(point.X / scalar, point.Y / scalar, point.Z / scalar));
 }
Example #14
0
 /// <summary>
 /// Subtracts one points from another and returns the result.
 /// </summary>
 /// <param name="left">The value to subtract from (the minuend).</param>
 /// <param name="right">The value to subtract (the subtrahend).</param>
 /// <returns>The result of subtracting right from left (the difference).</returns>
 public static Vector3i Subtract(Point3i left, Point3i right)
 {
     return(new Vector3i(left.X - right.X, left.Y - right.Y, left.Z - right.Z));
 }
Example #15
0
 /// <summary>
 /// Subtracts a vector from a point and returns the result.
 /// </summary>
 /// <param name="point">The point value to subtract from (the minuend).</param>
 /// <param name="vector">The vector value to subtract (the subtrahend).</param>
 /// <returns>The result of subtracting vector from point (the difference).</returns>
 public static Point3i Subtract(Point3i point, Vector3i vector)
 {
     return(new Point3i(point.X - vector.X, point.Y - vector.Y, point.Z - vector.Z));
 }
Example #16
0
 /// <summary>
 /// Adds a point and a vector and returns the result.
 /// </summary>
 /// <param name="point">The point value to add.</param>
 /// <param name="vector">The vector value to add.</param>
 /// <returns>The sum of left and right.</returns>
 public static Point3i Add(Point3i point, Vector3i vector)
 {
     return(new Point3i(point.X + vector.X, point.Y + vector.Y, point.Z + vector.Z));
 }
Example #17
0
 /// <summary>
 /// Writes the given <see cref="Point3i"/> to an <see cref="Ibasa.IO.BinaryWriter">.
 /// </summary>
 public static void Write(this Ibasa.IO.BinaryWriter writer, Point3i point)
 {
     writer.Write(point.X);
     writer.Write(point.Y);
     writer.Write(point.Z);
 }
Example #18
0
 /// <summary>
 /// Projects a point onto a vector, returns the distance of the projection from the origin.
 /// </summary>
 /// <param name="vector">The vector to project onto.</param>
 /// <param name="point">The point to project.</param>
 /// <returns>The distance from the origin of the projection.</returns>
 public static int Project(Point3i point, Vector3i vector)
 {
     return(vector.X * point.X + vector.Y * point.Y + vector.Z * point.Z);
 }
Example #19
0
 /// <summary>
 /// Determines whether any components of a point satisfy a condition.
 /// </summary>
 /// <param name="value">A point.</param>
 /// <param name="predicate">A function to test each component for a condition.</param>
 /// <returns>true if any component of the point passes the test in the specified
 /// predicate; otherwise, false.</returns>
 public static bool Any(Point3i value, Predicate <int> predicate)
 {
     return(predicate(value.X) || predicate(value.Y) || predicate(value.Z));
 }
Example #20
0
 /// <summary>
 /// Returns a value that indicates whether two points are equal.
 /// </summary>
 /// <param name="left">The first point to compare.</param>
 /// <param name="right">The second point to compare.</param>
 /// <returns>true if the left and right are equal; otherwise, false.</returns>
 public static bool Equals(Point3i left, Point3i right)
 {
     return(left == right);
 }
Example #21
0
 /// <summary>
 /// Maps the components of a point and returns the result.
 /// </summary>
 /// <param name="value">The point to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Point3d Map(Point3i value, Func <int, double> mapping)
 {
     return(new Point3d(mapping(value.X), mapping(value.Y), mapping(value.Z)));
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Line3i"/> using the specified values.
 /// </summary>
 /// <param name="start">Start point of the line.</param>
 /// <param name="end">End point of the line.</param>
 public Line3i(Point3i start, Point3i end)
 {
     Start = start;
     End   = end;
 }
Example #23
0
 /// <summary>
 /// Maps the components of a point and returns the result.
 /// </summary>
 /// <param name="value">The point to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Point3l Map(Point3i value, Func <int, long> mapping)
 {
     return(new Point3l(mapping(value.X), mapping(value.Y), mapping(value.Z)));
 }
Example #24
0
 /// <summary>
 /// Returns a point that contains the highest value from each pair of components.
 /// </summary>
 /// <param name="value1">The first point.</param>
 /// <param name="value2">The second point.</param>
 /// <returns>The highest of each component in left and the matching component in right.</returns>
 public static Point3i Max(Point3i value1, Point3i value2)
 {
     return(new Point3i(Functions.Max(value1.X, value2.X), Functions.Max(value1.Y, value2.Y), Functions.Max(value1.Z, value2.Z)));
 }
Example #25
0
 /// <summary>
 /// Returns the absolute value (per component).
 /// </summary>
 /// <param name="value">A point.</param>
 /// <returns>The absolute value (per component) of value.</returns>
 public static Point3i Abs(Point3i value)
 {
     return(new Point3i(Functions.Abs(value.X), Functions.Abs(value.Y), Functions.Abs(value.Z)));
 }
Example #26
0
 /// <summary>
 /// Returns the manhatten distance between two points.
 /// </summary>
 /// <param name="value1">The first point.</param>
 /// <param name="value2">The second point.</param>
 /// <returns>The manhatten distance between value1 and value2.</returns>
 public static int ManhattenDistance(Point3i value1, Point3i value2)
 {
     return(Functions.Abs(value2.X - value1.X) + Functions.Abs(value2.Y - value1.Y) + Functions.Abs(value2.Z - value1.Z));
 }
Example #27
0
 /// <summary>
 /// Returns the distance between two points.
 /// </summary>
 /// <param name="value1">The first point.</param>
 /// <param name="value2">The second point.</param>
 /// <returns>The distance between value1 and value2.</returns>
 public static double Distance(Point3i value1, Point3i value2)
 {
     return(Vector.Absolute(value2 - value1));
 }
Example #28
0
 /// <summary>
 /// Constrains each component to a given range.
 /// </summary>
 /// <param name="value">A point to constrain.</param>
 /// <param name="min">The minimum values for each component.</param>
 /// <param name="max">The maximum values for each component.</param>
 /// <returns>A point with each component constrained to the given range.</returns>
 public static Point3i Clamp(Point3i value, Point3i min, Point3i max)
 {
     return(new Point3i(Functions.Clamp(value.X, min.X, max.X), Functions.Clamp(value.Y, min.Y, max.Y), Functions.Clamp(value.Z, min.Z, max.Z)));
 }
Example #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Line3i"/> using the specified values.
 /// </summary>
 /// <param name="startX">X coordinate of the start point of the line.</param>
 /// <param name="startY">Y coordinate of the start point of the line.</param>
 /// <param name="startZ">Z coordinate of the start point of the line.</param>
 /// <param name="endX">X coordinate of the end point of the line.</param>
 /// <param name="endY">Y coordinate of the end point of the line.</param>
 /// <param name="endZ">Z coordinate of the end point of the line.</param>
 public Line3i(int startX, int startY, int startZ, int endX, int endY, int endZ)
 {
     Start = new Point3i(startX, startY, startZ);
     End   = new Point3i(endX, endY, endZ);
 }
Example #30
0
 /// <summary>
 /// Returns the squared distance between two points.
 /// </summary>
 /// <param name="value1">The first point.</param>
 /// <param name="value2">The second point.</param>
 /// <returns>The squared distance between value1 and value2.</returns>
 public static int DistanceSquared(Point3i value1, Point3i value2)
 {
     return(Vector.AbsoluteSquared(value2 - value1));
 }