public void CanFindAdjoint() { Matrix2D actual = Matrix2D.Adjoint(new Matrix2D { M11 = -3, M12 = 2, M13 = -5, M21 = -1, M22 = 0, M23 = -2, M31 = 3, M32 = -4, M33 = 1 }); Matrix2D expected = new Matrix2D { M11 = -8, M12 = 18, M13 = -4, M21 = -5, M22 = 12, M23 = -1, M31 = 4, M32 = -6, M33 = 2 }; AssertMatricesAreEqual(expected, actual); }
public TypeToolObject(BinaryPSDReader reader) : base(reader) { BinaryPSDReader r = this.GetDataReader(); ushort Version = r.ReadUInt16(); //1= Photoshop 5.0 this.Transform = new Matrix2D(r); ushort TextDescriptorVersion = r.ReadUInt16(); //=50. For Photoshop 6.0. if (true) this.TxtDescriptor = new DynVal(r, true); else { uint XTextDescriptorVersion = r.ReadUInt32(); //=16. For Photoshop 6.0. this.TextDescriptor = new Descriptor(r); } this.Data = r.ReadBytes((int)r.BytesToEnd); ////ushort WarpDescriptorVersion = r.ReadUInt16(); //=50. For Photoshop 6.0. ////uint XWarpDescriptorVersion = r.ReadUInt32(); //=16. For Photoshop 6.0. ////Descriptor warpDescriptor = new Descriptor(r); //this.WarpDescriptor = new DynVal(r, true); //this.WarpRect = ERectangleF.FromLTRB((float)r.ReadPSDDouble(), (float)r.ReadPSDDouble(), (float)r.ReadPSDDouble(), (float)r.ReadPSDDouble()); ////this.WarpRect.Left = r.ReadPSDDouble(); ////double warpRectTop = r.ReadPSDDouble(); ////double warpRectRight = r.ReadPSDDouble(); ////double warpRectBottom = r.ReadPSDDouble(); //this.Data = null; }
public override void TransformBy(Matrix2D transformation) { Point2D p1 = P1; Point2D p2 = P2; p1.TransformBy(transformation); p2.TransformBy(transformation); P1 = p1; P2 = p2; }
public virtual void Begin(Matrix2D? transformMatrix = null) { if (_isBeginCalled) throw new InvalidOperationException( "Begin cannot be called again until End has been successfully called."); _transformMatrix = transformMatrix.HasValue ? transformMatrix.Value.ToMatrix3D() : Matrix.Identity; _isBeginCalled = true; }
public override void TransformBy(Matrix2D transformation) { for (int i = 0; i < Points.Length; i++) { Point2D p = Points[i]; p.TransformBy(transformation); Points[i] = p; } }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="a11">x-component of the pixel width</param> /// <param name="a21">y-component of the pixel width</param> /// <param name="a12">x-component of the pixel height</param> /// <param name="a22">y-component of the pixel height</param> /// <param name="b1">x-ordinate of the center of the top left pixel</param> /// <param name="b2">y-ordinate of the center of the top left pixel</param> public WorldFile(double a11 = 1d, double a21 = 0d, double a12 = 0d, double a22 = -1, double b1 = 0d, double b2 = 0d) { _matrix.A11 = a11; _matrix.A21 = a21; _matrix.A12 = a12; _matrix.A22 = a22; _inverse = _matrix.Inverse(); B1 = b1; B2 = b2; }
public SvgMatrix( List<float> points ) { _points = points; matrix = new Matrix2D( _points[0], _points[1], _points[2], _points[3], _points[4], _points[5] ); }
public static Matrix2D Adjoint(Matrix2D matrix) { Matrix2D adjoint; adjoint.M11 = matrix.M33 * matrix.M22 - matrix.M32 * matrix.M23; adjoint.M12 = -(matrix.M33 * matrix.M12 - matrix.M32 * matrix.M13); adjoint.M13 = matrix.M23 * matrix.M12 - matrix.M22 * matrix.M13; adjoint.M21 = -(matrix.M33 * matrix.M21 - matrix.M31 * matrix.M23); adjoint.M22 = matrix.M33 * matrix.M11 - matrix.M31 * matrix.M13; adjoint.M23 = -(matrix.M23 * matrix.M11 - matrix.M21 * matrix.M13); adjoint.M31 = matrix.M32 * matrix.M21 - matrix.M31 * matrix.M22; adjoint.M32 = -(matrix.M32 * matrix.M11 - matrix.M31 * matrix.M12); adjoint.M33 = matrix.M22 * matrix.M11 - matrix.M21 * matrix.M12; return adjoint; }
/// <summary> /// Loads a world file /// </summary> /// <param name="file">The filename</param> /// <exception cref="ArgumentNullException"/> /// <exception cref="ArgumentException"/> public void Load(string file) { if (string.IsNullOrEmpty(file)) throw new ArgumentNullException("file"); if (File.Exists(file)) throw new ArgumentException(string.Format("File '{0}' not found", file), "file"); using (var sr = new StreamReader(file)) { _matrix.A11 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); _matrix.A21 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); _matrix.A12 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); _matrix.A22 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); B1 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); B2 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); } _inverse = _matrix.Inverse(); }
public void Matrix2D_Clear() { var m = new Matrix2D <string>(); Assert.AreEqual(0, m.RowCount); Assert.AreEqual(0, m.ColumnCount); m.Clear(); Assert.AreEqual(0, m.RowCount); Assert.AreEqual(0, m.ColumnCount); m[0, 0] = "Hello World!"; Assert.AreEqual(1, m.RowCount); Assert.AreEqual(1, m.ColumnCount); m.Clear(); Assert.AreEqual(0, m.RowCount); Assert.AreEqual(0, m.ColumnCount); Assert.IsNull(m[0, 0]); m[100, 100] = "100,100"; m.Clear(); Assert.AreEqual(0, m.RowCount); Assert.AreEqual(0, m.ColumnCount); }
protected override GeneralPath GetOutline(INode node) { double width = Math.Min(node.Layout.Width, node.Layout.Height / BpmnConstants.ConversationWidthHeightRatio); double height = width * BpmnConstants.ConversationWidthHeightRatio; RectD bounds = new RectD(node.Layout.GetCenter().X - width / 2, node.Layout.GetCenter().Y - height / 2, width, height); var path = new GeneralPath(); path.MoveTo(0, 0.5); path.LineTo(0.25, 0); path.LineTo(0.75, 0); path.LineTo(1, 0.5); path.LineTo(0.75, 1); path.LineTo(0.25, 1); path.Close(); var transform = new Matrix2D(); transform.Translate(bounds.GetTopLeft()); transform.Scale(bounds.Width, bounds.Height); path.Transform(transform); return(path); }
public void TestMatrixF2DRotate() { double delta = 0.00001; var sqrt2 = System.Math.Sqrt(2); // rotate by 45°. var rotate = Matrix2D.Rotate(System.Math.PI / 4); double x, y; rotate.Apply(sqrt2, sqrt2, out x, out y); Assert.AreEqual(2, x, delta); Assert.AreEqual(0, y, delta); // rotate by 90° rotate = Matrix2D.Rotate(System.Math.PI / 2); rotate.Apply(sqrt2, sqrt2, out x, out y); Assert.AreEqual(sqrt2, x, delta); Assert.AreEqual(-sqrt2, y, delta); }
public void TestMatrix2DScaleRotateAndTranslate() { double delta = 0.00001; var scale = Matrix2D.Scale(2); var translate = Matrix2D.Translate(1, 0); var rotate = Matrix2D.Rotate(System.Math.PI / 2); double x, y; scale.Apply(1, 1, out x, out y); translate.Apply(x, y, out x, out y); rotate.Apply(x, y, out x, out y); Assert.AreEqual(2, x, delta); Assert.AreEqual(-3, y, delta); var transformation = scale * translate * rotate; transformation.Apply(1, 1, out x, out y); Assert.AreEqual(2, x, delta); Assert.AreEqual(-3, y, delta); }
public Tile(int tileNo, List <string> lines, bool calculateEdges = true) { TileNo = tileNo; matrix = CharMatrix.Build(lines); Width = matrix.Width; Height = matrix.Height; if (calculateEdges) { //cache edges for all orientations: for (int i = 0; i < 8; i++) { bool rotate, hflip, vflip; (rotate, hflip, vflip) = DecodeTransform(i); int[] edges = new int[4]; for (int e = 0; e < 4; e++) { Edge edge = (Edge)e; edges[e] = ToInt(GetTransformedEdge(edge, rotate, hflip, vflip)); } orientedEdges[i] = edges; } } }
public void WorldTransformedSceneNodes_ReturnsTransformedSceneNodes() { var child = new SceneNode(); child.Transform = Matrix2D.identity; var root = new SceneNode(); root.Children = new System.Collections.Generic.List <SceneNode>(2); root.Children.Add(child); var transform = Matrix2D.Translate(new Vector2(1, 2)); root.Transform = transform; var nodes = VectorUtils.WorldTransformedSceneNodes(root, null); foreach (var nodeWithTransform in nodes) { Assert.AreEqual(1.0f, nodeWithTransform.WorldTransform.m02); Assert.AreEqual(2.0f, nodeWithTransform.WorldTransform.m12); } }
/// <summary> /// New PolyShape from Unity shape data. /// </summary> /// <param name="unityShape">Shape data</param> /// <param name="shapeTransform">Transform matrix</param> public static PolyShape Create(Shape unityShape, Matrix2D shapeTransform) { PolyShape shape = Create(); int vertexCount = 0; foreach (BezierContour contour in unityShape.Contours) { vertexCount += contour.Segments.Length; } shape.vertices = new Vertex[vertexCount]; for (int i = 0; i < vertexCount; i++) { shape.vertices[i] = new Vertex(); } foreach (BezierContour contour in unityShape.Contours) { for (int i = 0; i < contour.Segments.Length; i++) { BezierPathSegment segment = contour.Segments[i]; shape.vertices[i].position = shapeTransform.MultiplyPoint(segment.P0); shape.vertices[i].exitCP = shapeTransform.MultiplyPoint(segment.P1); shape.vertices[shape.NextIndex(i)].enterCP = shapeTransform.MultiplyPoint(segment.P2); shape.vertices[i].segmentCurves = true; } shape.closed = contour.Closed; } if (unityShape.PathProps.Stroke != null) { shape.colorOutline = unityShape.PathProps.Stroke.Color; } return(shape); }
private void hitMelee() { // perform a melee hit var meleeWeapon = entity.getComponent <MeleeWeapon>(); var dir = lastFacing == Direction.Right ? 1 : -1; var facingFlipScale = new Vector2(dir, 1); var offset = meleeWeapon.offset; offset = Vector2Ext.transform(offset, Matrix2D.createScale(facingFlipScale)); var reach = meleeWeapon.reach; // reflect X based on direction RectangleExt.scale(ref reach, facingFlipScale); // var swordCollider = new BoxCollider(offset.X + reach.X, // offset.Y + reach.Y, reach.Width, reach.Height); var swordCollider = new BoxCollider(0, 0, reach.Width, reach.Height); swordCollider.localOffset = new Vector2(offset.X + reach.X + reach.Width / 2f, offset.Y + reach.Y + reach.Height / 2f); entity.addComponent(swordCollider); collisionResults.Clear(); swordCollider.collidesWithAnyMultiple(Vector2.Zero, collisionResults); for (var i = 0; i < collisionResults.Count; i++) { var result = collisionResults[i]; var character = result.collider?.entity.getComponent <Character>(); if (character != null) { hurtCharacter(character); } } entity.removeComponent(swordCollider); }
/// <summary> /// Loads a world file /// </summary> /// <param name="file">The filename</param> /// <exception cref="ArgumentNullException"/> /// <exception cref="ArgumentException"/> public void Load(string file) { if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException("file"); } if (File.Exists(file)) { throw new ArgumentException(string.Format("File '{0}' not found", file), "file"); } using (var sr = new StreamReader(file)) { // ReSharper disable AssignNullToNotNullAttribute _matrix.A11 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); _matrix.A21 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); _matrix.A12 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); _matrix.A22 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); B1 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); B2 = double.Parse(sr.ReadLine(), NumberStyles.Float, NumberFormatInfo.InvariantInfo); // ReSharper restore AssignNullToNotNullAttribute } _inverse = _matrix.Inverse(); }
public void TestSetTransformationMatrixWithRightAngle() { Sprite sprite = new Sprite(); float[] angles = { (float)(Math.PI / 2.0f), (float)(-Math.PI / 2.0f) }; Matrix2D[] matrices = { Matrix2D.Create(0, 1, -1, 0), Matrix2D.Create(0, -1, 1, 0) }; for (int i = 0; i < 2; ++i) { float angle = angles[i]; Matrix2D matrix = matrices[i]; sprite.TransformationMatrix = matrix; AssertAreEqualWithSmallError(0.0f, sprite.X, "wrong x coord"); AssertAreEqualWithSmallError(0.0f, sprite.Y, "wrong y coord"); AssertAreEqualWithSmallError(1.0f, sprite.ScaleX, "wrong scaleX"); AssertAreEqualWithSmallError(1.0f, sprite.ScaleY, "wrong scaleY"); AssertAreEqualWithSmallError(angle, sprite.Rotation, "wrong rotation"); } }
public static bool StampValue(Matrix2D <char> map, Matrix2D <char> sprite, int spriteX, int spriteY, char value) { for (int y = 0; y < sprite.Height; y++) { var py = spriteY + y; if (py < 0 || py >= map.Height) { continue; } for (int x = 0; x < sprite.Width; x++) { var px = spriteX + x; if (px < 0 || px >= map.Width) { continue; } if ((sprite[x, y] != ' ')) { map[px, py] = value; } } } return(false); }
public void TestSetTransformationMatrix() { const float x = 50; const float y = 100; const float scaleX = 0.5f; const float scaleY = 1.5f; const float rotation = (float)(Math.PI / 4.0f); Matrix2D matrix = Matrix2D.Create(); matrix.Scale(scaleX, scaleY); matrix.Rotate(rotation); matrix.Translate(x, y); Sprite sprite = new Sprite(); sprite.TransformationMatrix = matrix; AssertAreEqualWithSmallError(x, sprite.X); AssertAreEqualWithSmallError(y, sprite.Y); AssertAreEqualWithSmallError(scaleX, sprite.ScaleX); AssertAreEqualWithSmallError(scaleY, sprite.ScaleY); AssertAreEqualWithSmallError(rotation, sprite.Rotation); }
//--------------------- PointToLocalSpace -------------------------------- // //------------------------------------------------------------------------ public static Vector2D PointToLocalSpace(Vector2D point, Vector2D agentHeading, Vector2D agentSide, Vector2D agentPosition) { //make a copy of the point Vector2D transPoint = new Vector2D(point); //create a transformation matrix Matrix2D matTransform = new Matrix2D(); double tx = -agentPosition.DotProduct(agentHeading); double ty = -agentPosition.DotProduct(agentSide); //create the transformation matrix matTransform.P11 = agentHeading.X; matTransform.P12 = agentSide.X; matTransform.P21 = agentHeading.Y; matTransform.P22 = agentSide.Y; matTransform.P31 = tx; matTransform.P32 = ty; //now transform the vertices matTransform.TransformVector2D(transPoint); return(transPoint); }
public static Matrix2D Transpose(Matrix2D matrix) { Matrix2D result = new Matrix2D(); result.M11 = matrix.M11; result.M12 = matrix.M21; result.M13 = matrix.M31; result.M21 = matrix.M12; result.M22 = matrix.M22; result.M23 = matrix.M32; result.M31 = matrix.M13; result.M32 = matrix.M23; result.M33 = matrix.M33; return result; }
public static void transform( Vector2[] sourceArray, int sourceIndex, ref Matrix2D matrix, Vector2[] destinationArray, int destinationIndex, int length ) { for( var i = 0; i < length; i++ ) { var position = sourceArray[sourceIndex + i]; var destination = destinationArray[destinationIndex + i]; destination.X = ( position.X * matrix.M11 ) + ( position.Y * matrix.M21 ) + matrix.M31; destination.Y = ( position.X * matrix.M12 ) + ( position.Y * matrix.M22 ) + matrix.M32; destinationArray[destinationIndex + i] = destination; } }
public GeneralShape2D(ISegment2DIterator iterator, Matrix2D transformation) : this(iterator, transformation, false) { }
static Matrix2D() { Identity = new Matrix2D(1, 0, 0, 0, 1, 0, 0, 0, 1); Zero = new Matrix2D(0, 0, 0, 0, 0, 0, 0, 0, 0); }
public static Matrix2D Multiply(this Matrix2D m, Matrix2D n) { return(new Matrix2D(m.A.Multiply(n.A).Add(m.B.Multiply(n.C)), m.A.Multiply(n.B).Add(m.B.Multiply(n.D)), m.C.Multiply(n.A).Add(m.D.Multiply(n.C)), m.C.Multiply(n.B).Add(m.D.Multiply(n.D)))); }
/// <summary> /// Transform the shape by an arbitrary matrix. /// </summary> /// <param name="matrix">Matrix to transform shape</param> public abstract void TransformBy(Matrix2D matrix);
void RefreshTransform2D() { mTransform2D = Matrix2D.TRS(mTransform.position, 0.0f, sprite.size * mScale); }
private static void AssertMatricesAreEqual(Matrix2D expectedMatrix, Matrix2D actualMatrix) { TestUtility.AssertAreRoughlyEqual(expectedMatrix.M11, actualMatrix.M11); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M12, actualMatrix.M12); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M13, actualMatrix.M13); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M21, actualMatrix.M21); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M22, actualMatrix.M22); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M23, actualMatrix.M23); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M31, actualMatrix.M31); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M32, actualMatrix.M32); TestUtility.AssertAreRoughlyEqual(expectedMatrix.M33, actualMatrix.M33); }
public void CanFindInverse() { Matrix2D actual = Matrix2D.Invert(new Matrix2D { M11 = 3, M12 = 2, M13 = 3, M21 = 4, M22 = 5, M23 = 6, M31 = 7, M32 = 8, M33 = 9 }); Matrix2D expected = new Matrix2D { M11 = 0.5f, M12 = -1, M13 = 0.5f, M21 = -1, M22 = -1, M23 = 1, M31 = 0.5f, M32 = 1.6666666667f, M33 = -1.1666666667f }; AssertMatricesAreEqual(expected, actual); }
public static void transform( ref Vector2 position, ref Matrix2D matrix, out Vector2 result ) { var x = ( position.X * matrix.M11 ) + ( position.Y * matrix.M21 ) + matrix.M31; var y = ( position.X * matrix.M12 ) + ( position.Y * matrix.M22 ) + matrix.M32; result.X = x; result.Y = y; }
public void DimensionsHeight0() { Matrix2D <int> m = new Matrix2D <int>(1, 0); }
/// <summary> /// Process a path /// </summary> /// <param name="path">A path object which is processed.</param> void ProcessPath(Element path) { if (!path.IsFilled() && !path.IsStroked()) { return; } try { pdftron.PDF.PathData pathData = path.GetPathData(); double[] data = pathData.points; ii++; if (ii == 627) { } if (verticalLines.Count > 0 && verticalLines.First().Value.Count == 2) { } Matrix2D matrix2D = path.GetCTM(); //Mark Matrix2D pageMatrix2D = _pdfDoc.GetPage(_pageNum).GetDefaultMatrix(); //Matrix2D exchangeMatrix = new Matrix2D(Math.Abs(pageMatrix2D.m_a), // Math.Abs(pageMatrix2D.m_b), Math.Abs(pageMatrix2D.m_c), Math.Abs(pageMatrix2D.m_d), 0, 0); Matrix2D exchangeMatrix = new Matrix2D(pageMatrix2D.m_a, pageMatrix2D.m_b, pageMatrix2D.m_c, pageMatrix2D.m_d, 0, 0); for (int i = 0; i < data.Length; i += 2) { matrix2D.Mult(ref data[i], ref data[i + 1]); } int data_sz = data.Length; byte[] opr = pathData.operators; int opr_sz = opr.Length; int opr_itr = 0, opr_end = opr_sz; int data_itr = 0, data_end = data_sz; double x1, y1, x2, y2, x3, y3; for (; opr_itr < opr_end; ++opr_itr) { switch ((pdftron.PDF.PathData.PathSegmentType)((int)opr[opr_itr])) { case pdftron.PDF.PathData.PathSegmentType.e_moveto: x1 = data[data_itr]; ++data_itr; y1 = data[data_itr]; ++data_itr; pageMatrix2D.Mult(ref x1, ref y1); curPoint = new Point(x1, y1); break; case pdftron.PDF.PathData.PathSegmentType.e_lineto: x1 = data[data_itr]; ++data_itr; y1 = data[data_itr]; ++data_itr; pageMatrix2D.Mult(ref x1, ref y1); Point point = new Point(x1, y1); DealDrawLine(curPoint, point); curPoint = point; break; case pdftron.PDF.PathData.PathSegmentType.e_cubicto: x1 = data[data_itr++]; y1 = data[data_itr++]; x2 = data[data_itr++]; y2 = data[data_itr++]; x3 = data[data_itr++]; y3 = data[data_itr++]; break; case pdftron.PDF.PathData.PathSegmentType.e_rect: { x1 = data[data_itr++]; y1 = data[data_itr++]; pageMatrix2D.Mult(ref x1, ref y1); double w = data[data_itr++]; double h = data[data_itr++]; exchangeMatrix.Mult(ref w, ref h); x2 = x1 + w; y2 = y1; x3 = x2; y3 = y1 + h; double x4 = x1; double y4 = y3; Point point1 = new Point(x1, y1); Point point2 = new Point(x2, y2); Point point3 = new Point(x3, y3); Point point4 = new Point(x4, y4); if (Math.Abs(w) > lengthError) { DealDrawLine(point1, point2); if (Math.Abs(h) > lengthError) { DealDrawLine(point4, point3); } } if (Math.Abs(h) > lengthError) { DealDrawLine(point3, point2); if (Math.Abs(w) > lengthError) { DealDrawLine(point4, point1); } } if (Math.Abs(w) <= lengthError && Math.Abs(h) <= lengthError) { if (w > h) { DealDrawLine(point1, point2); } else { DealDrawLine(point4, point1); } } break; } } } } catch (Exception) { throw; } }
/// <summary> /// Calculates a screen space scissor rectangle using the given Camera. If the Camera is null than the scissor will /// be calculated only with the batchTransform /// </summary> /// <returns>The scissors.</returns> /// <param name="camera">Camera.</param> /// <param name="batchTransform">Batch transform.</param> /// <param name="scissor">Area.</param> public static Rectangle calculateScissors( Camera camera, Matrix2D batchTransform, Rectangle scissor ) { // convert the top-left point to screen space var tmp = new Vector2( scissor.X, scissor.Y ); tmp = Vector2.Transform( tmp, batchTransform ); if( camera != null ) tmp = camera.worldToScreenPoint( tmp ); var newScissor = new Rectangle(); newScissor.X = (int)tmp.X; newScissor.Y = (int)tmp.Y; // convert the bottom-right point to screen space tmp.X = scissor.X + scissor.Width; tmp.Y = scissor.Y + scissor.Height; tmp = Vector2.Transform( tmp, batchTransform ); if( camera != null ) tmp = camera.worldToScreenPoint( tmp ); newScissor.Width = (int)tmp.X - newScissor.X; newScissor.Height = (int)tmp.Y - newScissor.Y; return newScissor; }
private static VectorShape ParseShape(Shape shape, Matrix2D transform) { VectorShape vectorShape = new PolyShape(shape, transform); return(vectorShape); }
public static Vector2 transform( Vector2 position, Matrix2D matrix ) { return new Vector2( ( position.X * matrix.M11 ) + ( position.Y * matrix.M21 ) + matrix.M31, ( position.X * matrix.M12 ) + ( position.Y * matrix.M22 ) + matrix.M32 ); }
public void Append(IShape2D shape, bool connect, Matrix2D transform) { this.Append(shape.CreateIterator(), connect, transform); }
public abstract void TransformBy(Matrix2D transformation);
public static Matrix2D Invert(Matrix2D matrix) { return(Adjoint(matrix) / matrix.Determinant); }
public static void CreateModelFromFile(IGAModel model, string fileName) { char[] delimeters = { ' ', '=', '\t' }; Attributes?name = null; String[] text = System.IO.File.ReadAllLines(fileName); for (int i = 0; i < text.Length; i++) { String[] line = text[i].Split(delimeters, StringSplitOptions.RemoveEmptyEntries); if (line.Length == 0) { continue; } try { name = (Attributes)Enum.Parse(typeof(Attributes), line[0].ToLower()); }catch (Exception e) { throw new KeyNotFoundException("Variable name is not found " + line[0]); } switch (name) { case Attributes.numberofdimensions: model.NumberOfDimensions = Int32.Parse(line[1]); break; case Attributes.degreeksi: model.DegreeKsi = Int32.Parse(line[1]); break; case Attributes.degreeheta: model.DegreeHeta = Int32.Parse(line[1]); break; case Attributes.degreezeta: model.DegreeZeta = Int32.Parse(line[1]); break; case Attributes.numberofcpksi: model.NumberOfCPKsi = Int32.Parse(line[1]); break; case Attributes.numberofcpheta: model.NumberOfCPHeta = Int32.Parse(line[1]); break; case Attributes.numberofcpzeta: model.NumberOfCPZeta = Int32.Parse(line[1]); break; case Attributes.knotvaluevectorksi: if (model.DegreeKsi == 0 || model.NumberOfCPKsi == 0) { throw new ArgumentOutOfRangeException("Degree Ksi and number of Control Points per axis Ksi must be defined before Knot Value Vector Ksi."); } model.KnotValueVectorKsi = new Vector <double>(model.NumberOfCPKsi + model.DegreeKsi + 1); for (int j = 0; j < model.NumberOfCPKsi + model.DegreeKsi + 1; j++) { model.KnotValueVectorKsi[j] = Double.Parse(line[j + 1], CultureInfo.InvariantCulture); } break; case Attributes.knotvaluevectorheta: if (model.DegreeHeta == 0 || model.NumberOfCPHeta == 0) { throw new ArgumentOutOfRangeException("Degree Heta and number of Control Points per axis Heta must be defined before Knot Value Vector Heta."); } model.KnotValueVectorHeta = new Vector <double>(model.NumberOfCPHeta + model.DegreeHeta + 1); for (int j = 0; j < model.NumberOfCPHeta + model.DegreeHeta + 1; j++) { model.KnotValueVectorHeta[j] = Double.Parse(line[j + 1], CultureInfo.InvariantCulture); } break; case Attributes.knotvaluevectorzeta: if (model.DegreeZeta == 0 || model.NumberOfCPZeta == 0) { throw new ArgumentOutOfRangeException("Degree Zeta and number of Control Points per axis Zeta must be defined before Knot Value Vector Zeta."); } model.KnotValueVectorZeta = new Vector <double>(model.NumberOfCPZeta + model.DegreeZeta + 1); for (int j = 0; j < model.NumberOfCPZeta + model.DegreeZeta + 1; j++) { model.KnotValueVectorZeta[j] = Double.Parse(line[j + 1], CultureInfo.InvariantCulture); } break; case Attributes.cpcoord: if (model.NumberOfDimensions == 2) { Matrix2D <double> cpCoordinates = new Matrix2D <double>(model.NumberOfCPKsi * model.NumberOfCPHeta, 3); cpCoordinates[0, 0] = Double.Parse(line[1], CultureInfo.InvariantCulture); cpCoordinates[0, 1] = Double.Parse(line[2], CultureInfo.InvariantCulture); cpCoordinates[0, 2] = Double.Parse(line[3], CultureInfo.InvariantCulture); for (int j = 1; j < model.NumberOfCPKsi * model.NumberOfCPHeta; j++) { i++; line = text[i].Split(delimeters); cpCoordinates[j, 0] = Double.Parse(line[0], CultureInfo.InvariantCulture); cpCoordinates[j, 1] = Double.Parse(line[1], CultureInfo.InvariantCulture); cpCoordinates[j, 2] = Double.Parse(line[2], CultureInfo.InvariantCulture); } model.CreateModelData(cpCoordinates); } else { Matrix2D <double> cpCoordinates = new Matrix2D <double>(model.NumberOfCPKsi * model.NumberOfCPHeta * model.NumberOfCPZeta, 4); cpCoordinates[0, 0] = Double.Parse(line[1], CultureInfo.InvariantCulture); cpCoordinates[0, 1] = Double.Parse(line[2], CultureInfo.InvariantCulture); cpCoordinates[0, 2] = Double.Parse(line[3], CultureInfo.InvariantCulture); cpCoordinates[0, 3] = Double.Parse(line[4], CultureInfo.InvariantCulture); for (int j = 1; j < model.NumberOfCPKsi * model.NumberOfCPHeta * model.NumberOfCPZeta; j++) { i++; line = text[i].Split(delimeters); cpCoordinates[j, 0] = Double.Parse(line[0], CultureInfo.InvariantCulture); cpCoordinates[j, 1] = Double.Parse(line[1], CultureInfo.InvariantCulture); cpCoordinates[j, 2] = Double.Parse(line[2], CultureInfo.InvariantCulture); cpCoordinates[j, 3] = Double.Parse(line[3], CultureInfo.InvariantCulture); } model.CreateModelData(cpCoordinates); } break; case Attributes.end: return; } } }
/// <summary> /// Copies the vertex data of the style's current target to the target of another style. /// If you pass a matrix, all vertices will be transformed during the process. /// /// Subclasses may override this method if they need to modify the vertex data in that /// process. /// </summary> /// <param name="targetStyle">Points to the style of a MeshBatch</param> /// <param name="targetVertexId">Where to start the copy in the target</param> /// <param name="matrix">If you pass a non-null matrix, the 2D position of each vertex /// will be transformed by that matrix before storing it in the target object.</param> /// <param name="vertexId">position to start copyting from</param> /// <param name="numVertices">Number of vertices to copy</param> public void BatchVertexData(MeshStyle targetStyle, int targetVertexId = 0, Matrix2D matrix = null, int vertexId = 0, int numVertices = -1) { _vertexData.CopyTo(targetStyle._vertexData, vertexId, targetVertexId, numVertices, matrix); }
/// <summary> /// Transforms a point from the local coordinate system to global (stage) coordinates. /// </summary> public Point LocalToGlobal(Point localPoint) { Matrix2D matrix = GetTransformationMatrix(Base); return(matrix.TransformPoint(localPoint)); }
public GeneralShape2D(IShape2D shape, Matrix2D transformation, bool fixate) : this(shape.CreateIterator(), transformation, fixate) { this.method_2(shape); }
public static void transform( Vector2[] sourceArray, ref Matrix2D matrix, Vector2[] destinationArray ) { transform( sourceArray, 0, ref matrix, destinationArray, 0, sourceArray.Length ); }
public void TransformBy(Matrix2D transformation) { this.method_6(transformation, 0, this.int_2); }
protected virtual void updateMatrixes() { if( !_areMatrixesDirty ) return; Matrix2D tempMat; _transformMatrix = Matrix2D.createTranslation( -entity.transform.position.X, -entity.transform.position.Y ); // position if( _zoom != 1f ) { Matrix2D.createScale( _zoom, _zoom, out tempMat ); // scale -> Matrix2D.multiply( ref _transformMatrix, ref tempMat, out _transformMatrix ); } if( entity.transform.rotation != 0f ) { Matrix2D.createRotation( entity.transform.rotation, out tempMat ); // rotation Matrix2D.multiply( ref _transformMatrix, ref tempMat, out _transformMatrix ); } Matrix2D.createTranslation( (int)_origin.X, (int)_origin.Y, out tempMat ); // translate -origin Matrix2D.multiply( ref _transformMatrix, ref tempMat, out _transformMatrix ); // calculate our inverse as well Matrix2D.invert( ref _transformMatrix, out _inverseTransformMatrix ); // whenever the matrix changes the bounds are then invalid _areBoundsDirty = true; _areMatrixesDirty = false; }
void updateTransform() { if( hierarchyDirty != DirtyType.Clean ) { if( parent != null ) parent.updateTransform(); if( _localDirty ) { if( _localPositionDirty ) { Matrix2D.createTranslation( _localPosition.X, _localPosition.Y, out _translationMatrix ); _localPositionDirty = false; } if( _localRotationDirty ) { Matrix2D.createRotation( _localRotation, out _rotationMatrix ); _localRotationDirty = false; } if( _localScaleDirty ) { Matrix2D.createScale( _localScale.X, _localScale.Y, out _scaleMatrix ); _localScaleDirty = false; } Matrix2D.multiply( ref _scaleMatrix, ref _rotationMatrix, out _localTransform ); Matrix2D.multiply( ref _localTransform, ref _translationMatrix, out _localTransform ); if( parent == null ) { _worldTransform = _localTransform; _rotation = _localRotation; _scale = _localScale; _worldInverseDirty = true; } _localDirty = false; } if( parent != null ) { Matrix2D.multiply( ref _localTransform, ref parent._worldTransform, out _worldTransform ); _rotation = _localRotation + parent._rotation; _scale = parent._scale * _localScale; _worldInverseDirty = true; } _worldToLocalDirty = true; _positionDirty = true; hierarchyDirty = DirtyType.Clean; } }
public override void TransformBy(Matrix2D transformation) { Point2D p = P; p.TransformBy(transformation); P = p; Rotation += transformation.RotationAngle * 180 / (float)Math.PI; }
/// <summary> /// Creates a matrix that represents the transformation from the local coordinate system to another. /// </summary> public Matrix2D GetTransformationMatrix(DisplayObject targetSpace) { DisplayObject commonParent = null; DisplayObject currentObject; Matrix2D outMatrix = Matrix2D.Create(); outMatrix.Identity(); if (targetSpace == this) { return(outMatrix); } if (targetSpace == _parent || (targetSpace == null && _parent == null)) { outMatrix.CopyFromMatrix(TransformationMatrix); return(outMatrix); } if (targetSpace == null || targetSpace == Base) { // targetSpace 'null' represents the target coordinate of the base object. // -> move up from this to base currentObject = this; while (currentObject != targetSpace) { outMatrix.AppendMatrix(currentObject.TransformationMatrix); currentObject = currentObject._parent; } return(outMatrix); } if (targetSpace.Parent == this) { outMatrix = targetSpace.GetTransformationMatrix(this); outMatrix.Invert(); return(outMatrix); } // 1.: Find a common parent of this and the target coordinate space. commonParent = FindCommonParent(this, targetSpace); // 2.: Move up from this to common parent currentObject = this; while (currentObject != commonParent) { outMatrix.AppendMatrix(currentObject.TransformationMatrix); currentObject = currentObject._parent; } if (commonParent == targetSpace) { return(outMatrix); } // 3.: Now move up from target until we reach the common parent var sHelperMatrix = Matrix2D.Create(); sHelperMatrix.Identity(); currentObject = targetSpace; while (currentObject != commonParent) { sHelperMatrix.AppendMatrix(currentObject.TransformationMatrix); currentObject = currentObject._parent; } // 4.: Combine the two matrices sHelperMatrix.Invert(); outMatrix.AppendMatrix(sHelperMatrix); return(outMatrix); }
public static Matrix2D Invert(Matrix2D matrix) { return Adjoint(matrix) / matrix.Determinant; }
public void DimensionsWidth0() { Matrix2D <int> m = new Matrix2D <int>(0, 1); }