Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Matrix.jvm.cs « System.Drawing.Drawing2D « System.Drawing « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b0ef229b01f3fa8382bcb4c8eaf424bb89987b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using geom = java.awt.geom;
using JMath = java.lang.Math;

namespace System.Drawing.Drawing2D
{
	public sealed class Matrix : MarshalByRefObject, IDisposable
	{
		#region fields

		static internal readonly Matrix IdentityTransform = new Matrix();
		readonly geom.AffineTransform _nativeMatrix;				

		#endregion
                
		#region ctors

		internal Matrix (geom.AffineTransform ptr)
		{
			_nativeMatrix = ptr;
		}
                
		public Matrix () : this(new geom.AffineTransform())
		{		
		}
        
		public Matrix (Rectangle rect , Point[] plgpts)
		{
			double x1 = plgpts[1].X - plgpts[0].X;
			double y1 = plgpts[1].Y - plgpts[0].Y;
			
			double x2 = plgpts[2].X - plgpts[0].X;
			double y2 = plgpts[2].Y - plgpts[0].Y;

			_nativeMatrix = new geom.AffineTransform(x1/rect.Width, y1/rect.Width, x2/rect.Height, y2/rect.Height, plgpts[0].X, plgpts[0].Y);
			_nativeMatrix.translate(-rect.X,-rect.Y);
		}
        
		public Matrix (RectangleF rect , PointF[] plgpts)
		{
			double x1 = plgpts[1].X - plgpts[0].X;
			double y1 = plgpts[1].Y - plgpts[0].Y;
			
			double x2 = plgpts[2].X - plgpts[0].X;
			double y2 = plgpts[2].Y - plgpts[0].Y;

			_nativeMatrix = new geom.AffineTransform(x1/rect.Width, y1/rect.Width, x2/rect.Height, y2/rect.Height, plgpts[0].X, plgpts[0].Y);
			_nativeMatrix.translate(-rect.X,-rect.Y);
		}

		public Matrix (float m11, float m12, float m21, float m22, float dx, float dy)
			: this(new geom.AffineTransform(m11,m12,m21,m22,dx,dy))
		{
		}

		#endregion
        
		#region properties

		public float[] Elements 
		{
			get 
			{
				float [] elems = new float[] {
					(float)NativeObject.getScaleX(),
					(float)NativeObject.getShearY(),
					(float)NativeObject.getShearX(),
					(float)NativeObject.getScaleY(),
					(float)NativeObject.getTranslateX(),
					(float)NativeObject.getTranslateY()};
				return elems;
			}
		}
        
		public bool IsIdentity 
		{
			get 
			{
				return NativeObject.isIdentity();
			}
		}
        
		public bool IsInvertible 
		{
			get 
			{
				try
				{
					return NativeObject.getDeterminant() != 0.0;
				}
				catch(geom.NoninvertibleTransformException)
				{
					return false;
				}
			}
		}
        
		public float OffsetX 
		{
			get 
			{
				return (float)NativeObject.getTranslateX();
			}
		}
        
		public float OffsetY 
		{
			get 
			{
				return (float)NativeObject.getTranslateY();
			}
		}

		#endregion

		#region methods

		public Matrix Clone()
		{
			return new Matrix ((geom.AffineTransform)NativeObject.clone());
		}
                
        
		public void Dispose ()
		{
		}                       
        
		internal void CopyTo(Matrix matrix) {
			matrix.NativeObject.setTransform(NativeObject);
		}

		public override bool Equals (object obj)
		{
			Matrix m = obj as Matrix;
						

			if (m == null) 
				return false;

			return NativeObject.equals(m.NativeObject);
		}
                
		public override int GetHashCode ()
		{
			return NativeObject.hashCode();
		}
        
		public void Invert ()
		{
			try {
				_nativeMatrix.setTransform( _nativeMatrix.createInverse() );
			}
			catch(geom.NoninvertibleTransformException e) {
				throw new ArgumentException(e.Message, e);
			}
		}
        
		public void Multiply (Matrix matrix)
		{
			Multiply (matrix, MatrixOrder.Prepend);
		}
        
		public void Multiply (Matrix matrix, MatrixOrder order)
		{
			Multiply(matrix.NativeObject, order);
		}
        
		public void Reset()
		{
			NativeObject.setToIdentity();
		}
        
		public void Rotate (float angle)
		{
			NativeObject.rotate (JMath.toRadians(angle));
		}
        
		public void Rotate (float angle, MatrixOrder order)
		{
			Multiply(geom.AffineTransform.getRotateInstance(JMath.toRadians(angle)), order);					
		}
        
		public void RotateAt (float angle, PointF point)
		{
			NativeObject.rotate (JMath.toRadians(angle), point.X, point.Y);
		}
        
		public void RotateAt (float angle, PointF point, MatrixOrder order)
		{
			Multiply(geom.AffineTransform.getRotateInstance(JMath.toRadians(angle),point.X, point.Y), order);
		}
        
		public void Scale (float scaleX, float scaleY)
		{
			NativeObject.scale (scaleX, scaleY);
		}
        
		public void Scale (float scaleX, float scaleY, MatrixOrder order)
		{
			Multiply(geom.AffineTransform.getScaleInstance(scaleX, scaleY), order);
		}
        
		public void Shear (float shearX, float shearY)
		{
			NativeObject.shear(shearX, shearY);
		}
        
		public void Shear (float shearX, float shearY, MatrixOrder order)
		{
			Multiply(geom.AffineTransform.getShearInstance (shearX, shearY), order);
		}
        
		public void TransformPoints (Point[] pts)
		{
			geom.Point2D.Float pt = new geom.Point2D.Float();
			for(int i =0;i < pts.Length;i++) {
				pt.setLocation(pts[i].X,pts[i].Y);
				NativeObject.transform(pt,pt);
				pts[i].X=(int)pt.getX();
				pts[i].Y=(int)pt.getY();
			}
		}
        
		public void TransformPoints (PointF[] pts)
		{
			geom.Point2D.Float pt = new geom.Point2D.Float();
			for(int i =0;i < pts.Length;i++) {
				pt.setLocation(pts[i].X,pts[i].Y);
				NativeObject.transform(pt,pt);
				pts[i].X=(float)pt.getX();
				pts[i].Y=(float)pt.getY();
			}
		}
        
		public void TransformVectors (Point[] pts)
		{
			geom.Point2D.Float pt = new geom.Point2D.Float();
			for(int i =0;i < pts.Length;i++) {
				pt.setLocation(pts[i].X,pts[i].Y);
				NativeObject.deltaTransform(pt,pt);
				pts[i].X=(int)pt.getX();
				pts[i].Y=(int)pt.getY();
			}
		}
        
		public void TransformVectors (PointF[] pts)
		{
			geom.Point2D.Float pt = new geom.Point2D.Float();
			for(int i =0;i < pts.Length;i++) {
				pt.setLocation(pts[i].X,pts[i].Y);
				NativeObject.deltaTransform(pt,pt);
				pts[i].X=(float)pt.getX();
				pts[i].Y=(float)pt.getY();
			}
		}
        
		public void Translate (float offsetX, float offsetY)
		{
			NativeObject.translate (offsetX, offsetY);
		}
        
		public void Translate (float offsetX, float offsetY, MatrixOrder order)
		{
			Multiply(geom.AffineTransform.getTranslateInstance(offsetX, offsetY), order);
		}
        
		public void VectorTransformPoints (Point[] pts)
		{
			TransformVectors (pts);
		}
                
		internal geom.AffineTransform NativeObject
		{
			get
			{
				return _nativeMatrix;
			}
		}

		void Multiply(geom.AffineTransform at, MatrixOrder order) {
			Multiply(NativeObject, at, order);
		}

		internal static void Multiply(geom.AffineTransform to, geom.AffineTransform add, MatrixOrder order) {
			if(order == MatrixOrder.Prepend)
				to.concatenate(add);
			else
				to.preConcatenate(add);
		}

		#endregion
	}
}