/// <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; }
/// <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; }
/// <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; }
public Point3i[] ToArray() { var result = new Point3i[Count]; for (int i = 0; i < Count; ++i) { result[i] = this[i]; } return(result); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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)); }
/// <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); }
/// <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))); }
public static bool Contains(Spherei sphere, Point3i point) { return(Vector.AbsoluteSquared(sphere.Center - point) <= sphere.Radius * sphere.Radius); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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); }
/// <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)); }
/// <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); }
/// <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))); }
/// <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; }
/// <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))); }
/// <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))); }
/// <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))); }
/// <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)); }
/// <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)); }
/// <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))); }
/// <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); }
/// <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)); }