using RhythmBase.Components;
namespace RhythmBase.Utils
{
///
/// Visual utils.
///
public static class VisualUtils
{
///
/// Converts percentage point to pixel point with default screen size (352 * 198).
///
public static RDPointE PercentToPixel(RDPointE point) => PercentToPixel(point, RDSizeNI.Screen);
///
/// Converts percentage point to pixel point with specified size.
///
/// The percentage point.
/// Specified size.
/// The pixel point.
public static RDPointE PercentToPixel(RDPointE point, RDSizeE size)
{
RDPointE PercentToPixel = new(point.X * size.Width / 100f, point.Y * size.Height / 100f);
return PercentToPixel;
}
///
/// Converts pixel point to percentage point with default screen size (352 * 198).
///
/// The pixel point.
/// The percentage point.
public static (float? X, float? Y) PixelToPercent((float X, float Y) point) => PixelToPercent(point, (352f, 198f));
///
/// Converts pixel point to percentage point with specified size.
///
/// The pixel point.
/// Specified size.
/// The percentage point.
public static (float? X, float? Y) PixelToPercent((float? X, float? Y) point, (float? X, float? Y) size)
{
(float? X, float? Y) PixelToPercent = (point.X * 100f / size.X, point.Y * 100f / size.Y);
return PixelToPercent;
}
///
/// Translates a point in room perspective.
///
/// The point to translate.
/// The rectangle defining the room perspective.
/// The translated point.
public static RDPointN RoomPerspectiveTranslate(this RDPointN p, RDRectN rect)
{
RDPointN plb = rect.LeftBottom;
RDPointN prb = rect.RightBottom;
RDPointN plt = rect.LeftTop;
RDPointN prt = rect.RightTop;
p = new(p.X, p.Y);
RDPointN p1p2 = prb - (RDSizeN)plb;
RDPointN p1p4 = plt - (RDSizeN)plb;
RDPointN p1p3 = prt - (RDSizeN)plb;
RDPointN pr = plb + new RDSizeN(p1p2.X * p.X, p1p2.Y * p.X) +
new RDSizeN((p1p3.X - p1p2.X - p1p4.X) * p.X * p.Y, (p1p3.Y - p1p2.Y - p1p4.Y) * p.X * p.Y) +
new RDSizeN(p1p4.X * p.Y, p1p4.Y * p.Y);
return pr;
}
///
/// Converts degrees to radians.
///
/// The angle in degrees.
/// The angle in radians.
public static float DegreeToRadius(float degree) => float.Pi * degree / 180f;
///
/// Converts radians to degrees.
///
/// The angle in radians.
/// The angle in degrees.
public static float RadiusToDegree(float radius) => radius * 180f / float.Pi;
}
}