// Translate path to origin (0, 0)
 public static void CenterToOrigin(this List<Vector2> positions)
 {
     Vector2 center = positions.Center();
     for (int i = 0; i < positions.Count; i++)
     {
         positions[i] -= center;
     }
 }
Ejemplo n.º 2
0
        // Rotate path by given angle
        public static List<Vector2> Rotate(this List<Vector2> positions, float angle)
        {
            List<Vector2> result = new List<Vector2>(positions.Count);
            Vector2 c = positions.Center();

            float cos = (float)Math.Cos(angle);
            float sin = (float)Math.Sin(angle);

            foreach (Vector2 p in positions)
            {
                float dx = p.X - c.X;
                float dy = p.Y - c.Y;

                Vector2 rotatePoint = Vector2.Zero;
                rotatePoint.X = dx * cos - dy * sin + c.X;
                rotatePoint.Y = dx * sin + dy * cos + c.Y;

                result.Add(rotatePoint);
            }
            return result;
        }
Ejemplo n.º 3
0
 public static Point ImmediateInteriorSouth(this Rect rectangle)
 {
     return new Point(rectangle.Center().X, rectangle.Bottom - 1);
 }
Ejemplo n.º 4
0
 public static Point ImmediateInteriorNorth(this Rect rectangle)
 {
     return new Point(rectangle.Center().X, rectangle.Top + 1);
 }
Ejemplo n.º 5
0
 public static Point ImmediateInteriorEast(this Rect rectangle)
 {
     return new Point((int) (rectangle.Right - 1), rectangle.Center().Y);
 }
Ejemplo n.º 6
0
 public static Point ImmediateExteriorWest(this Rect rectangle)
 {
     return new Point((int) (rectangle.Left - 1), rectangle.Center().Y);
 }
Ejemplo n.º 7
0
 public static Point East(this Rect rectangle, int by)
 {
     return new Point((int)(rectangle.Right + by), rectangle.Center().Y);
 }
Ejemplo n.º 8
0
 public static Vector2 Center(this Texture2D texture, Vector2 scale)
 {
     return texture.Center() * scale;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Changes the envelope extent by the specified amount relative
 /// to it's current extent in that dimension (preserving the aspect ratio).
 /// So Zoom(10) on a 100 unit wide envelope creates a 110 unit wide envlope,
 /// while Zoom(-10) on a 100 unit wide envelope creates a 90 unit wide envelope.
 /// Zoom(-100) on an envelope makes it 100% smaller, or effectively a point.
 /// Tragically, a point cannot be "zoomed" back in, so a check should be used
 /// to ensure that the envelope is not currently a point before attempting
 /// to zoom in.
 /// </summary>
 /// <param name="self">The IEnvelope that this zoom method modifies</param>
 /// <param name="percent"> 
 /// Positive 50 makes the envelope 50% larger
 /// Negative 50 makes the envelope 50% smaller
 /// </param>
 /// <example> 
 ///  perCent = -50 compact the envelope a 50% (make it smaller).
 ///  perCent = 200 enlarge envelope by 2.
 /// </example>
 public static void Zoom(this IEnvelope self, double percent)
 {
     if (self == null) return;
     if (self.IsNull) return;
     double ratio = percent / 100;
     Coordinate size = new Coordinate();
     for (int i = 0; i < self.NumOrdinates; i++)
     {
         double oldSize = self.Maximum[i] - self.Minimum[i];
         size[i] = oldSize + ratio * oldSize;
     }
     SetCenter(self, self.Center(), size);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Returns Box.Max in Box coordinates
 /// </summary>
 public static Vector3 Extents(this BoundingBox box)
 {
     return (box.Max - box.Center());
 }
Ejemplo n.º 11
0
 public static Point West(this Rect rectangle, int by = 0)
 {
     return new Point((int)(rectangle.Left + by), rectangle.Center().Y);
 }
Ejemplo n.º 12
0
 public static Point South(this Rect rectangle, int by = 0)
 {
     return new Point(rectangle.Center().X, rectangle.Bottom + by);
 }
Ejemplo n.º 13
0
 public static Point North(this Rect rectangle, int by = 0)
 {
     return new Point(rectangle.Center().X, rectangle.Top + by);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Zooms out for factor > 1, zooms in for factor < 1
 /// </summary>
 public static IRealInterval ZoomBy(this IRealInterval interval, double factor)
 {
     factor = Math.Abs(factor);
     return RealInterval.Make
         (
             interval.Center() - interval.Span() * factor / 2,
             interval.Center() + interval.Span() * factor / 2
        );
 }