public static IEnumerable <GsVector> CreateBezier(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { GsVector[] array = new GsVector[] { new GsVector(x1, y1), new GsVector(x2, y2), new GsVector(x3, y3), new GsVector(x4, y4), }; return(CreateBezier(array)); }
/// <summary> /// Calculate the projection of a polygon on an axis and returns it as a [min, max] interval /// </summary> private static void ProjectPolygon(GsVector axis, GsPolygon hull, ref float min, ref float max) { // get the points GsVector[] points = hull.mPoints; // To project a point on an axis use the dot product float d = GsVector.Dot(axis, points[0]); min = d; max = d; for (int i = 0; i < points.Length; i++) { d = GsVector.Dot(points[i], axis); min = Math.Min(min, d); max = Math.Max(max, d); } }
public static GsVector Rotate(this GsVector pointToRotate, GsVector centerPoint, double angleInDegrees) { double angleInRadians = angleInDegrees * (Math.PI / 180); double cosTheta = Math.Cos(angleInRadians); double sinTheta = Math.Sin(angleInRadians); return(new GsVector { X = (float) (cosTheta * (pointToRotate.X - centerPoint.X) - sinTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.X), Y = (float) (sinTheta * (pointToRotate.X - centerPoint.X) + cosTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.Y) }); }
private GsVector[] GetPoints(GsVector[] hull, GsMatrix transform) { mMinX = float.MaxValue; mMaxX = float.MinValue; mMinY = float.MaxValue; mMaxY = float.MinValue; List <GsVector> points = new List <GsVector>(hull.Length); foreach (GsVector pt in hull) { points.Add(GsVector.Transform(pt, transform)); float x = points[points.Count - 1].X; float y = points[points.Count - 1].Y; mMinX = Math.Min(mMinX, x); mMinY = Math.Min(mMinY, y); mMaxX = Math.Max(mMaxX, x); mMaxY = Math.Max(mMaxY, y); } return(points.ToArray()); }
/// <summary> /// tests if a point is Left|On|Right of an infinite line. /// </summary> /// <param name="P0">Point 1.</param> /// <param name="P1">Point 2.</param> /// <param name="P2">Point 3.</param> /// <returns> /// >0 for P2 left of the line through P0 and P1 /// =0 for P2 on the line /// <0 for P2 right of the line /// </returns> private static float isLeft(GsVector P0, GsVector P1, GsVector P2) { return((P1.X - P0.X) * (P2.Y - P0.Y) - (P2.X - P0.X) * (P1.Y - P0.Y)); }
public bool Contains(GsVector pt) { return(Contains(pt.X, pt.Y)); }
public void Offset(GsVector pos) { Offset(pos.X, pos.Y); }
public GsRectangle(GsVector location, GsSize size) : this(location.X, location.Y, size.Width, size.Height) { }
public static GsRectangle Offset(GsRectangle box, GsVector offset) { return(new GsRectangle(box.Location + offset, box.Size)); }
public static IEnumerable <GsVector> CreateRoundRect(GsRectangle rect, float radius, RectangleCorners corners) { float l = rect.Left; float t = rect.Top; float r = rect.Right; float b = rect.Bottom; float lr = rect.Left + radius; float tr = rect.Top + radius; float rr = rect.Right - radius; float br = rect.Bottom - radius; List <GsVector> polygon = new List <GsVector>(); // upper-left if ((corners & RectangleCorners.TopLeft) != 0) { GsVector[] upleft_corner = new GsVector[3] { new GsVector(l, tr), new GsVector(l, t), new GsVector(lr, t), }; polygon.AddRange(CreateBezier(upleft_corner)); } else { polygon.Add(new GsVector(l, t)); } // upper-right if ((corners & RectangleCorners.TopRight) != 0) { GsVector[] upright_corner = new GsVector[3] { new GsVector(rr, t), new GsVector(r, t), new GsVector(r, tr), }; polygon.AddRange(CreateBezier(upright_corner)); } else { polygon.Add(new GsVector(r, t)); } // bottom-right if ((corners & RectangleCorners.BottomRight) != 0) { GsVector[] bottomright_corner = new GsVector[3] { new GsVector(r, br), new GsVector(r, b), new GsVector(rr, b), }; polygon.AddRange(CreateBezier(bottomright_corner)); } else { polygon.Add(new GsVector(r, b)); } // bottom-left if ((corners & RectangleCorners.BottomLeft) != 0) { GsVector[] bottomleft_corner = new GsVector[3] { new GsVector(lr, b), new GsVector(l, b), new GsVector(l, br), }; polygon.AddRange(CreateBezier(bottomleft_corner)); } else { polygon.Add(new GsVector(l, b)); } // close it up polygon.Add(polygon[0]); // return it! return(polygon); }
private static GsVector CalculatePosition(GsSize size, float x, float y, float width, float height, GsAlignment alignment) { GsVector pos = new GsVector(x, y); float top = y; float middle = (y + (height / 2)) - (size.Height / 2); float bottom = (y + height) - size.Height; float left = x; float center = (x + (width / 2)) - (size.Width / 2); float right = (x + width) - size.Width; switch (alignment) { case GsAlignment.BottomCenter: pos.X = center; pos.Y = bottom; break; case GsAlignment.BottomLeft: pos.X = left; pos.Y = bottom; break; case GsAlignment.BottomRight: pos.X = right; pos.Y = bottom; break; case GsAlignment.MiddleCenter: pos.X = center; pos.Y = middle; break; case GsAlignment.MiddleLeft: pos.X = left; pos.Y = middle; break; case GsAlignment.MiddleRight: pos.X = right; pos.Y = middle; break; case GsAlignment.TopCenter: pos.X = center; pos.Y = top; break; case GsAlignment.TopLeft: pos.X = left; pos.Y = top; break; case GsAlignment.TopRight: pos.X = right; pos.Y = top; break; } return(pos); }