Utils
Global utilities and functions.
Definition
Namespace:Telerik.Windows.Diagrams.Core
Assembly:Telerik.Windows.Diagrams.Core.dll
Syntax:
public static class Utils
Inheritance: objectUtils
Fields
Methods
Approximates the arc.
public static IEnumerable<Point> ApproximateArc(Point topLeft, Point bottomRight, double startAngle, double endAngle)
The topLeft.
bottomRightPointThe bottomRight.
startAngledoubleThe angle in degrees at which the arc starts.
endAngledoubleThe angle in degrees at which the arc ends.
Returns:IEnumerable<Point>
Approximates the Bezier curve as segments represented by a series of points.
public static IEnumerable<Point> ApproximateBezierCurve(Point[] bezierPoints, int quality)
The Bezier points.
qualityintThe quality of the approximation. The greater the value, the more accurate approximation (more approximated points).
Returns:IEnumerable<Point>
Approximates the ellipse defined by the given bounds.
Approximates the rounded rectangle.
Approximates the rounded rectangle.
public static IEnumerable<Point> ApproximateRoundedRectangle(Rect rectangle, double radius)
IEnumerable<Point>
Arcs the convert.
public static void ArcConvert(Rect rect, double startAngle, double sweep, out Point startPoint, out Point outsidePoint, out bool largeArc, out SweepDirection dir)
The rec.
startAngledoubleThe start angle.
sweepdoubleThe sweep.
startPointPointThe start point.
outsidePointPointThe outside point.
largeArcboolIf set to true [large arc].
The direction.
Returns whether the line (line segments) intersect and returns in the crossingPoint the actual crossing point if they do.
public static bool AreLinesIntersecting(Point line1Start, Point line1End, Point line2Start, Point line2End, ref Point crossingPoint)
The first point of the first line.
line1EndPointThe second point of the first line.
line2StartPointThe first point of the second line.
line2EndPointThe second point of the second line.
crossingPointPointThe crossing point.
Returns:Returns the barycentric coordinates as percentages with respect to the given rectangle.
public static Point BarycentricPercentageFromPoint(Point realPoint, Rect rectangle)
The real point.
rectangleRectThe rectangle which acts as a barycentric coordinate system.
Returns:Point
The percentages wrapped in a Point.
Given an interval and a value this will output the value which is closer to the given value.
Returns the point of the interval which sits the closest to the given point.
public static Point Closer(Point point, Point point1, Point point2)
The point seeking the closes neighbor.
point1PointThe first point in the interval.
point2PointThe second point in the interval.
Returns:Point
Returns the vector between the two points.
public static Vector Delta(this Point point1, Point point2)
The point where the vector starts.
point2PointThe points where the vector ends.
Returns:Vector
Determinants the specified point1.
public static double Determinant(Point point1, Point point2)
The point1.
point2PointThe point2.
Returns:Calculates the point of the specified line segment which determines the distance from the specified point to the line segment. That is, the perpendicular projection onto the segment.
public static Point DistancePoint(Point point, Point lineStart, Point lineEnd)
The point outside the segment.
lineStartPointThe first point defining the segment.
lineEndPointThe second point defining the segment.
Returns:Point
Returns the squared distance between the given points.
public static double DistanceSquared(Point point1, Point point2)
Returns the dot product of the specified points.
public static double Dot(Point point1, Point point2)
Returns the dot product of the specified vectors.
public static double Dot(Vector vector1, Vector vector2)
Finds the angle between three points.
public static double FindAngle(Point firstPoint, Point centralPoint, Point secondPoint)
Finds the angle between two points.
public static double FindAngle(Point start, Point end)
Finds the intersection point of a shape and the line segment defined by the point
segmentStart and segmentEnd.
public static Point FindIntersectionPoint(this Rect rec, double angle, Point segmentStart, Point segmentEnd, GlidingStyle style)
The bounding rectangle of the shape.
angledoubleThe rotation angle.
segmentStartPointThe line point which is supposedly inside the shape defined by rec.
The other line point which supposedly sits outside the bounds define by rec.
The gliding style.
Returns:Point
Finds the intersection point of the lines defined by the point pairs.
public static Point FindLinesIntersection(Point line1Start, Point line1End, Point line2Start, Point line2End, bool acceptNaN = false)
Point
The intersection point. If acceptNaN is
Finds the radian between three points.
public static double FindRadian(Point firstPoint, Point centralPoint, Point secondPoint)
Finds the radian between two points.
public static double FindRadian(Point start, Point end)
Gets the Bezier point at the specified value.
public static Point GetBezierPoint(Collection<Point> points, int segment, double value)
The points.
segmentintThe segment.
valuedoubleA value in the interval [0,1].
Returns:Point
Gets a point from the maximum X and Y values from the specified points.
public static Point GetBottomRightPoint(IEnumerable<Point> points)
The points.
Returns:Point
Gets the enclosing bounds of the points collection.
public static Rect GetBounds(this IList<Point> points)
The points collection.
Returns:Rect
Gets the only the child elements.
public static IEnumerable<XElement> GetChildElements(this XElement element)
The parent element.
Returns:IEnumerable<XElement>
Returns the point at an angle on the ellipse defined by the specified rectangle.
public static Point GetEllipsePointAtAngle(this Rect rect, double angle)
The rect.
angledoubleThe angle in degrees.
Returns:Point
Gets the enumeration values.
public static T[] GetEnumValues<T>()
T[]
Gets the normalization point.
public static Point GetNormalizationPoint(this IEnumerable<Point> points)
The points.
Returns:Point
Gets the normalized points.
public static IEnumerable<Point> GetNormalizedPoints(this IEnumerable<Point> points)
The points.
Returns:IEnumerable<Point>
Gets the projected points of the specified point on the given rectangle.
public static void GetProjections(Point point, Rect rectangle, Point[] projections)
Gets a point from the minimum X and Y values from the specified points.
public static Point GetTopLeftPoint(IEnumerable<Point> points)
The points.
Returns:Point
Determines whether [has valid area] [the specified size].
public static bool HasValidArea(this Size size)
The size.
Returns:true if [has valid area] [the specified size]; otherwise, false.
Determines whether the specified line segments intersect.
public static bool Intersect(Point[] points)
True if the segments intersect, false if not.
Calculate the intersection point between a polyline and a line segment.
public static bool IntersectionPointOnEllipse(Collection<Point> points, Point org, Point end, ref Point result)
Calculate the intersection point between an ellipse and a line segment.
public static void IntersectionPointOnEllipse(Rect rect, Point lineStart, Point lineEnd, ref Point result)
Calculates the intersection point between the specified rectangle and the line segment defined by the specified points.
public static void IntersectionPointOnRectangle(Rect rectangle, Point lineStart, Point lineEnd, ref Point intersectionPoint)
Inverts the point.
public static Point InvertPoint(this Point point)
The point.
Returns:Point
Determines, given three points, if when travelling from the first to the second to the third, we travel in a counterclockwise direction.
public static int IsCounterClockWise(Point point1, Point point2, Point point3)
1 if the movement is in a counterclockwise direction, -1 if not.
Determines whether the specified values are equal with Epsilon approximation.
Gets whether the value is NaN or infinite point.
Determines whether the specified values are not equal with Epsilon approximation.
Returns whether the specified point is inside the ellipse defined by the specified rectangle.
public static bool IsPointInEllipse(Point point, Rect rectangle)
Determines whether [is point in rectangle] [the specified point].
public static bool IsPointInRectangle(Point point, Size size)
The point.
sizeSizeThe size.
Returns:true if [is point in rectangle] [the specified point]; otherwise, false.
Returns the length of the given point considered as a vector.
Linear interpolation between the two given values.
public static double Lerp(double x, double y, double alpha)
The value to be returned when alpha is zero.
The value to be returned when alpha is equal to one.
The linear interpolation parameter which usually takes a value in the interval [0,1] but which works outside this range nevertheless.
Linear interpolation between the two given points.
public static Point Lerp(Point pointA, Point pointB, double alpha)
The value to be returned when alpha is zero.
The value to be returned when alpha is equal to one.
The linear interpolation parameter which usually takes a value in the interval [0,1] but which works outside this range nevertheless.
Point
Linear interpolation between the two given vectors.
public static Vector Lerp(Vector vectorA, Vector vectorB, double alpha)
The value to be returned when alpha is zero.
The value to be returned when alpha is equal to one.
The linear interpolation parameter which usually takes a value in the interval [0,1] but which works outside this range nevertheless.
Vector
Moves the given point into the rectangle by taking the rectangle's intervals as limiting values for the point's coordinates.
public static Point Limit(this Point point, Rect rectangle)
Any point.
rectangleRectA rectangle which acts as limiting container.
Returns:Point
Returns the middle point between the given points.
public static Point MiddlePoint(Point point1, Point point2)
A point.
point2PointAnother point.
Returns:Point
Halfway between the two given points.
Returns the mirrored vector with respect to the X-coordinate.
public static Vector MirrorHorizontally(this Vector vector)
The vector to mirror.
Returns:Vector
The mirrored vector.
Returns the opposite of point point with respect to specified line.
public static Point MirrorPoint(Point point, Point lineStart, Point lineEnd)
Point
Mirrors the point with respect to the given center.
public static Point MirrorPoint(Point point, Point center)
Point
Returns the mirrored vector with respect to the Y-coordinate.
public static Vector MirrorVertically(this Vector vector)
The vector to mirror.
Returns:Vector
The mirrored vector.
Calculates the intersection points with each of the given segments and determines the one nearest to the first point.
Gets the nearest point.
public static Point NearestPoint(this Point point, IEnumerable<Point> points)
The point.
pointsIEnumerable<Point>The points.
Returns:Point
Normalize the specified point1.
public static Vector Normal(Point point1, Point point2)
The point1.
point2PointThe point2.
Returns:Vector
Normalize the specified vector.
public static Vector Normalized(this Vector vector)
The vector.
Returns:Vector
Offsets the specified points.
public static IList<Point> Offset(this IEnumerable<Point> points, Vector offsetVector)
The points.
offsetVectorVectorThe offset vector.
Returns:IList<Point>
Returns the perpendicular of the specified vector.
public static Vector Perpendicular(this Vector vector)
A vector.
Returns:Vector
Given a percentage and a rectangle this will return the coordinates corresponding to the percentages given.
public static Point PointFromBarycentricPercentage(Point percentage, Rect rectangle)
A couple of values in percentage, e.g. a value of (50,50) will return the center of the rectangle.
rectangleRectThe rectangle which acts as the barycentric system.
Returns:Point
The point corresponding to the barycentric coordinates.
Given rect1 percentage and a rectangle this will return the coordinates corresponding to the percentages given.
public static Point PointFromBarycentricPercentage(Point percentage, Size size)
A couple of values in percentage, e.g. a value of (50,50) will return the center of the rectangle.
sizeSizeThe size from which the point will be extracted.
Returns:Point
The point corresponding to the barycentric coordinates.
Gets a point extending the line by a specified distance.
public static Point PointOnLine(Point startPoint, Point endPoint, double distance)
The start point.
endPointPointThe end point.
distancedoubleThe distance.
Returns:Point
The opposite of the approximation method, this attempts to smoothen out the polyline to a Bezier curve.
public static IEnumerable<Point> PolylineToBezier(Collection<Point> points)
The polyline.
Returns:IEnumerable<Point>
Finds the projection (point) of the given point on the line.
public static Point ProjectPointOnLine(Point point, Point lineStart, Point lineEnd)
Point
Pushes the specified start point onwards in the direction specified by the vector and a length given.
public static Point Push(Point start, Vector unitVector, double distance)
The start.
unitVectorVectorThe unit vector.
distancedoubleThe distance to push.
Returns:Point
Rotates the transform.
public static RotateTransform RotateTransform(Point center, double angle)
The center.
angledoubleThe angle.
Returns:RotateTransform
Determine whether point1 and point2 are on the same side of a line.
public static bool SameSide(Point lineStart, Point lineEnd, Point point1, Point point2)
Checks whether the segments defined by the specified point pairs intersect and returns the intersection point.
public static bool SegmentIntersect(Point segmentStart, Point segmentEnd, Point lineStart, Point lineEnd, ref Point result)
Returns zero within the given interval and +/-1 whether the value is above or below the interval.
Returns the StairValue(double, double, double) of the x,y values of the given point with respect to the boundaries of the specified rectangle.
public static Vector StairValue(Point point, Rect rectangle)
The point to test.
rectangleRectThe rectangle which acts as the domain of the stair function.
Returns:Vector
Zero, -1 or +1 whether the coordinate is below, inside, or above the boundary of the rectangle.
Swaps the values of the two points.
public static void Swap(ref Point point1, ref Point point2)
A point.
point2PointAnother point.
DoubleCollection from a string representation.
public static DoubleCollection ToDoubleCollection(string value)
DoubleCollection
Returns value of the enumeration.
Converts the double collection to a string representation.
public static string ToInvariant(this DoubleCollection collection)
The collection.
Returns:Converts the point to a string representation.
public static string ToInvariant(this Point point)
The point.
Returns:Converts the point to a string representation.
Attempts to convert the given string to a points.
public static Point? ToPoint(string point)
The string representation of the point.
Returns:Point?
The Point corresponding to the serialized form.
Return a rectangle located a (0.0) with the specified size.
public static Rect ToRect(this Size size)
The s.
Returns:Rect
A rectangle located at the (0.0).
Sizes from string.
Returns a unit point in the direction defined by the given point.
public static Point ToUnit(this Point point)
Point
Unions two rectangles.
public static Rect Union(Rect rect1, Rect rect2)
The first rectangle.
rect2RectThe second rectangle.
Returns:Rect
Union of the two rectangles.
Returns a unit vector in the direction specified by the angle.
public static Vector UnitVector(double degrees)
The angle in degrees.
Returns:Vector
A unit vector.