Barotrauma Client Doc
PointExtensions.cs
1 using Microsoft.Xna.Framework;
2 
3 namespace Barotrauma.Extensions
4 {
5  public static class PointExtensions
6  {
7  public static Point Multiply(this Point p, float f)
8  {
9  return new Point((int)(p.X * f), (int)(p.Y * f));
10  }
11 
12  public static Point Multiply(this Point p, int i)
13  {
14  return new Point(p.X * i, p.Y * i);
15  }
16 
17  public static Point Multiply(this Point p, Vector2 v)
18  {
19  return new Point((int)(p.X * v.X), (int)(p.Y * v.Y));
20  }
21 
22  public static Point Divide(this Point p, int i)
23  {
24  if (i == 0) { return Point.Zero; }
25  return new Point(p.X / i, p.Y / i);
26  }
27 
28  public static Point Divide(this Point p, float f)
29  {
30  if (f == 0) { return Point.Zero; }
31  return new Point((int)(p.X / f), (int)(p.Y / f));
32  }
33 
34  public static Point Divide(this Point p, Vector2 v)
35  {
36  if (v.X == 0 || v.Y == 0) { return Point.Zero; }
37  return new Point((int)(p.X / v.X), (int)(p.Y / v.Y));
38  }
39 
43  public static Point Inverse(this Point p)
44  {
45  return new Point(-p.X, -p.Y);
46  }
47 
51  public static Point Flip(this Point p)
52  {
53  return new Point(p.Y, p.X);
54  }
55 
56  public static Point Clamp(this Point p, Point min, Point max)
57  {
58  return new Point(MathHelper.Clamp(p.X, min.X, max.X), MathHelper.Clamp(p.Y, min.Y, max.Y));
59  }
60  }
61 }