Last active
May 22, 2019 11:03
-
-
Save ilyaqznetsow/feba846dacf229c1e7cd4993c8b4c5b5 to your computer and use it in GitHub Desktop.
Angle to Points Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//original: https://github.com/ChasakisD/XFShimmerLayout/blob/master/src/XFShimmerLayout/Extensions/SkiaExtensions.cs | |
public static class PointsExtension{ | |
public static IEnumerable<Point> ToPoints(this double angle) | |
{ | |
var d = Math.Pow(2, .5); | |
var eps = Math.Pow(2, -52); | |
var finalAngle = angle % 360; | |
var startPointRadians = (180 - finalAngle).ToRadians(); | |
var startX = d * Math.Cos(startPointRadians); | |
var startY = d * Math.Sin(startPointRadians); | |
var endPointRadians = (360 - finalAngle).ToRadians(); | |
var endX = d * Math.Cos(endPointRadians); | |
var endY = d * Math.Sin(endPointRadians); | |
return new[] | |
{ | |
new Point(startX.CheckForOverflow(eps), startY.CheckForOverflow(eps)), | |
new Point(endX.CheckForOverflow(eps), endY.CheckForOverflow(eps)) | |
}; | |
} | |
public static double ToRadians(this double angle) | |
{ | |
return Math.PI * angle / 180; | |
} | |
private static double CheckForOverflow(this double value, double eps) | |
{ | |
return value <= 0 || Math.Abs(value) <= eps ? 0f : value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment