/// <summary> /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// A signed integer that indicates the relative values of x and y: /// - If less than 0, x is less than y. /// - If 0, x equals y. /// - If greater than 0, x is greater than y. /// </returns> public int Compare(Cartesian2dCoordinate x, Cartesian2dCoordinate y) { // Check perfect equality first to avoid further calculations. if (x.X.IsEqualTo(y.X) && x.Y.IsEqualTo(y.Y)) { return(0); } // Get Theta value related to the X vector, if one in the starting one we don't need to compare further. double thetaX = x.ThetaToX; if (thetaX.IsZero()) { return(-1); } double thetaY = y.ThetaToX; if (thetaY.IsZero()) { return(1); } thetaX = AlignThetaOnRotationDirection(x, thetaX); thetaY = AlignThetaOnRotationDirection(y, thetaY); return(thetaX > thetaY ? 1 : -1); }
/// <summary> /// Align the theta of calculated value based on their direction, negative value will be accessible trough bigger angle than positive one. /// </summary> /// <param name="cc">Coordinates used to realign the theta angle.</param> /// <param name="theta">Angle in radians to realign.</param> /// <returns>Realigned angles value in radians.</returns> private double AlignThetaOnRotationDirection(Cartesian2dCoordinate cc, double theta) { if (cc.Y > 0.0) { return(theta); } return((Math.PI * 2.0) - theta); }
/// <summary> /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// A signed integer that indicates the relative values of x and y: /// - If less than 0, x is less than y. /// - If 0, x equals y. /// - If greater than 0, x is greater than y. /// </returns> public int Compare(Cartesian3dCoordinate x, Cartesian3dCoordinate y) { // Check perfect equality first to avoid further calculations. if (x.IsSamePoint(y)) { return(0); } Cartesian2dCoordinate x2 = m_Converter.ConvertTo2d(x); Cartesian2dCoordinate y2 = m_Converter.ConvertTo2d(y); return(Compare(x2, y2)); }
/// <summary> /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// A signed integer that indicates the relative values of x and y: /// - If less than 0, x is less than y. /// - If 0, x equals y. /// - If greater than 0, x is greater than y. /// </returns> public int Compare(Cartesian3dCoordinate x, Cartesian3dCoordinate y) { // Calculate intersection with plane to have all point on same plane. Cartesian3dCoordinate intersectX = m_Converter.Plane.GetIntersection(x); Cartesian3dCoordinate intersectY = m_Converter.Plane.GetIntersection(y); // Convert in a 2D referential to facilitate the comparison. Cartesian2dCoordinate x2 = m_Converter.ConvertTo2d(intersectX); Cartesian2dCoordinate y2 = m_Converter.ConvertTo2d(intersectY); if (x2.Y.IsEqualTo(y2.Y)) { // Same line if (x2.X.IsEqualTo(y2.X)) { return(0); } return(x2.X < y2.X ? -1 : 1); } return(x2.Y > y2.Y ? -1 : 1); }