public PointF(float x, float y, Angle angle, byte quadratic = 0) : this() { this.X = x; this.Y = y; Quadratic = quadratic; if (!float.IsNaN(X) && !float.IsNaN(Y)) { Valid = true; } if (Valid && angle.Valid) { angle.Rotate(x, y, out x, out y); } }
public static IGlyphSlot RotateSlot(this IGlyphSlot slot, Angle angle, int currentX, int currentY, out float newX, out float newY) { newX = currentX; newY = currentY; if (slot.Points == null || slot.Points.Count == 0 || !angle.Valid || char.IsWhiteSpace(slot.Character)) { return(slot); } Angle a = new Angle(-angle.Degree, 0, 0); var Points = new PointF[slot.Points.Count]; for (int i = 0; i < Points.Length; i++) { var p = new PointF(slot.Points[i].X + slot.Min.X, slot.Points[i].Y + slot.Min.Y, slot.Points[i].Quadratic); Points[i] = a.Rotate(p); } angle.Rotate(currentX, currentY, out newX, out newY); return(Factory.newGlyphSlot(slot.Character, Points, slot.Contours.ToArray(), slot.XHeight)); }
public EllipseData(float x, float y, float width, float height, Angle angle = default(Angle)) : this() { X = x; Y = y; Width = width; Height = height; Rx = (width / 2f); Ry = (height / 2f); Cx = (x + Rx).Round(); Cy = (y + Ry).Round(); WMajor = Rx > Ry; if (angle.Valid && angle.CenterAssigned) { angle.Rotate(Cx, Cy, out Cx, out Cy); X = Cx - Rx; Y = Cy - Ry; } if (angle.Valid) { Angle = new Angle(angle, Cx, Cy); } RxSqr = MathHelper.Sqr(Rx); RySqr = MathHelper.Sqr(Ry); float cos = 1; float sin = 0; if (Angle.Valid) { cos = Angle.MCos; sin = Angle.MSin; } float b0 = ((1 / RxSqr) - (1 / RySqr)); A = ((cos * cos) / RxSqr) + ((sin * sin) / RySqr); B = 2 * cos * sin * b0; C = ((cos * cos) / RySqr) + ((sin * sin) / RxSqr); var HMajor = Rx <= Ry; if (HMajor) { var newA = (-(Angle.Degree) - 90) * Geometry.Radian; cos = (float)Math.Cos(newA); sin = (float)Math.Sin(newA); } var a = Rx > Ry ? Rx : Ry; var b = Rx > Ry ? Ry : Rx; var MajorSqr = a * a; var Distance = (float)Math.Sqrt(a * a - b * b); var xc = Distance * cos; var yc = Distance * sin; float A2 = (MajorSqr - xc * xc); float B2 = (MajorSqr - yc * yc); float C2 = (-xc * yc); var minus2C = Math.Sqrt(A2 + B2 - (2 * C2)); var plus2C = Math.Sqrt(A2 + B2 + (2 * C2)); var XTopMidPositive = (float)((B2 - C2) / minus2C); var XMidBotPositive = (float)((B2 + C2) / plus2C); var YTopMidPositive = (float)((A2 - C2) / minus2C); var YMidBotPositive = (float)(-(A2 + C2) / plus2C); YMax = (float)Math.Sqrt(A2); XMax = (float)Math.Sqrt(B2); TopXGreater = XTopMidPositive > XMidBotPositive; var yPos1 = TopXGreater ? YTopMidPositive : YMidBotPositive; var yPos2 = TopXGreater ? YMidBotPositive : YTopMidPositive; RightYGreater = YTopMidPositive > -YMidBotPositive; YStart = (RightYGreater ? YTopMidPositive : -YMidBotPositive); YEnd = (RightYGreater ? -YMidBotPositive : YTopMidPositive); float val1, val2, val3, val4; Geometry.GetRotatedEllipseDataAt((int)yPos1, true, A, B, C, out val1, out val2); Geometry.GetRotatedEllipseDataAt((int)yPos2, true, A, B, C, out val3, out val4); MathHelper.Order(ref val1, ref val2); MathHelper.Order(ref val3, ref val4); XStart = val2; XEnd = val4; }