2025-01-11 10:47:59 +01:00
|
|
|
|
// WindowsPhoneSpeedyBlupi, Version=1.0.0.5, Culture=neutral, PublicKeyToken=6db12cd62dbec439
|
|
|
|
|
// WindowsPhoneSpeedyBlupi.Misc
|
|
|
|
|
using System;
|
2025-01-11 10:49:51 +01:00
|
|
|
|
using System.Diagnostics;
|
2025-01-11 10:47:59 +01:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using WindowsPhoneSpeedyBlupi;
|
2025-01-11 10:49:51 +01:00
|
|
|
|
using static WindowsPhoneSpeedyBlupi.Def;
|
2025-01-11 10:47:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace WindowsPhoneSpeedyBlupi
|
|
|
|
|
{
|
|
|
|
|
public static class Misc
|
|
|
|
|
{
|
|
|
|
|
public static Rectangle RotateAdjust(Rectangle rect, double angle)
|
|
|
|
|
{
|
|
|
|
|
TinyPoint tinyPoint = default(TinyPoint);
|
|
|
|
|
tinyPoint.X = rect.Width / 2;
|
|
|
|
|
tinyPoint.Y = rect.Height / 2;
|
|
|
|
|
TinyPoint p = tinyPoint;
|
|
|
|
|
TinyPoint tinyPoint2 = RotatePointRad(angle, p);
|
|
|
|
|
int num = tinyPoint2.X - p.X;
|
|
|
|
|
int num2 = tinyPoint2.Y - p.Y;
|
|
|
|
|
return new Rectangle(rect.Left - num, rect.Top - num2, rect.Width, rect.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TinyPoint RotatePointRad(double angle, TinyPoint p)
|
|
|
|
|
{
|
|
|
|
|
return RotatePointRad(default(TinyPoint), angle, p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TinyPoint RotatePointRad(TinyPoint center, double angle, TinyPoint p)
|
|
|
|
|
{
|
|
|
|
|
TinyPoint tinyPoint = default(TinyPoint);
|
|
|
|
|
TinyPoint result = default(TinyPoint);
|
|
|
|
|
tinyPoint.X = p.X - center.X;
|
|
|
|
|
tinyPoint.Y = p.Y - center.Y;
|
|
|
|
|
double num = Math.Sin(angle);
|
|
|
|
|
double num2 = Math.Cos(angle);
|
|
|
|
|
result.X = (int)((double)tinyPoint.X * num2 - (double)tinyPoint.Y * num);
|
|
|
|
|
result.Y = (int)((double)tinyPoint.X * num + (double)tinyPoint.Y * num2);
|
|
|
|
|
result.X += center.X;
|
|
|
|
|
result.Y += center.Y;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double DegToRad(double angle)
|
|
|
|
|
{
|
|
|
|
|
return angle * Math.PI / 180.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int Approch(int actual, int final, int step)
|
|
|
|
|
{
|
|
|
|
|
if (actual < final)
|
|
|
|
|
{
|
|
|
|
|
actual = Math.Min(actual + step, final);
|
|
|
|
|
}
|
|
|
|
|
else if (actual > final)
|
|
|
|
|
{
|
|
|
|
|
actual = Math.Max(actual - step, final);
|
|
|
|
|
}
|
|
|
|
|
return actual;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int Speed(double speed, int max)
|
|
|
|
|
{
|
|
|
|
|
if (speed > 0.0)
|
|
|
|
|
{
|
|
|
|
|
return Math.Max((int)(speed * (double)max), 1);
|
|
|
|
|
}
|
|
|
|
|
if (speed < 0.0)
|
|
|
|
|
{
|
|
|
|
|
return Math.Min((int)(speed * (double)max), -1);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TinyRect Inflate(TinyRect rect, int value)
|
|
|
|
|
{
|
|
|
|
|
TinyRect result = default(TinyRect);
|
2025-01-11 10:49:51 +01:00
|
|
|
|
result.LeftX = rect.LeftX - value;
|
|
|
|
|
result.RightX = rect.RightX + value;
|
|
|
|
|
result.TopY = rect.TopY - value;
|
|
|
|
|
result.BottomY = rect.BottomY + value;
|
2025-01-11 10:47:59 +01:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsInside(TinyRect rect, TinyPoint p)
|
|
|
|
|
{
|
2025-01-11 10:49:51 +01:00
|
|
|
|
return p.X >= rect.LeftX && p.X <= rect.RightX && p.Y >= rect.TopY && p.Y <= rect.BottomY;
|
2025-01-11 10:47:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IntersectRect(out TinyRect dst, TinyRect src1, TinyRect src2)
|
|
|
|
|
{
|
|
|
|
|
dst = default(TinyRect);
|
2025-01-11 10:49:51 +01:00
|
|
|
|
dst.LeftX = Math.Max(src1.LeftX, src2.LeftX);
|
|
|
|
|
dst.RightX = Math.Min(src1.RightX, src2.RightX);
|
|
|
|
|
dst.TopY = Math.Max(src1.TopY, src2.TopY);
|
|
|
|
|
dst.BottomY = Math.Min(src1.BottomY, src2.BottomY);
|
2025-01-11 10:47:59 +01:00
|
|
|
|
return !IsRectEmpty(dst);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool UnionRect(out TinyRect dst, TinyRect src1, TinyRect src2)
|
|
|
|
|
{
|
|
|
|
|
dst = default(TinyRect);
|
2025-01-11 10:49:51 +01:00
|
|
|
|
dst.LeftX = Math.Min(src1.LeftX, src2.LeftX);
|
|
|
|
|
dst.RightX = Math.Max(src1.RightX, src2.RightX);
|
|
|
|
|
dst.TopY = Math.Min(src1.TopY, src2.TopY);
|
|
|
|
|
dst.BottomY = Math.Max(src1.BottomY, src2.BottomY);
|
2025-01-11 10:47:59 +01:00
|
|
|
|
return !IsRectEmpty(dst);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsRectEmpty(TinyRect rect)
|
|
|
|
|
{
|
2025-01-11 10:49:51 +01:00
|
|
|
|
if (rect.LeftX < rect.RightX)
|
2025-01-11 10:47:59 +01:00
|
|
|
|
{
|
2025-01-11 10:49:51 +01:00
|
|
|
|
return rect.TopY >= rect.BottomY;
|
2025-01-11 10:47:59 +01:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-01-11 10:49:51 +01:00
|
|
|
|
|
2025-01-11 10:47:59 +01:00
|
|
|
|
}
|
|
|
|
|
}
|