svn-gvsig-desktop / trunk / libraries / libTopology / src / org / geotools / referencefork / referencing / operation / matrix / Matrix1.java @ 22778
History | View | Annotate | Download (5.88 KB)
1 | 22778 | azabala | /*
|
---|---|---|---|
2 | * GeoTools - OpenSource mapping toolkit
|
||
3 | * http://geotools.org
|
||
4 | * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
|
||
5 | * (C) 2005, Institut de Recherche pour le Développement
|
||
6 | *
|
||
7 | * This library is free software; you can redistribute it and/or
|
||
8 | * modify it under the terms of the GNU Lesser General Public
|
||
9 | * License as published by the Free Software Foundation;
|
||
10 | * version 2.1 of the License.
|
||
11 | *
|
||
12 | * This library is distributed in the hope that it will be useful,
|
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
15 | * Lesser General Public License for more details.
|
||
16 | */
|
||
17 | package org.geotools.referencefork.referencing.operation.matrix; |
||
18 | |||
19 | import java.io.Serializable; |
||
20 | import javax.vecmath.SingularMatrixException; |
||
21 | import org.opengis.referencing.operation.Matrix; |
||
22 | |||
23 | |||
24 | |||
25 | /**
|
||
26 | * A matrix of fixed {@value #SIZE}×{@value #SIZE} size. This trivial matrix is returned as a
|
||
27 | * result of {@linkplain org.opengis.referencing.operation.MathTransform1D} derivative computation.
|
||
28 | *
|
||
29 | * @since 2.2
|
||
30 | * @source $URL: http://svn.geotools.org/geotools/trunk/gt/modules/library/referencing/src/main/java/org/geotools/referencing/operation/matrix/Matrix1.java $
|
||
31 | * @version $Id: Matrix1.java 29769 2008-04-02 17:10:40Z desruisseaux $
|
||
32 | * @author Martin Desruisseaux
|
||
33 | */
|
||
34 | public class Matrix1 implements XMatrix, Serializable { |
||
35 | /** Serial number for interoperability with different versions. */
|
||
36 | private static final long serialVersionUID = -4829171016106097031L; |
||
37 | |||
38 | /** The only element in this matrix. */
|
||
39 | public double m00; |
||
40 | |||
41 | /** The matrix size, which is {@value}. */
|
||
42 | public static final int SIZE = 1; |
||
43 | |||
44 | /**
|
||
45 | * Creates a new identity matrix.
|
||
46 | */
|
||
47 | public Matrix1() {
|
||
48 | m00 = 1;
|
||
49 | } |
||
50 | |||
51 | /**
|
||
52 | * Creates a new matrix initialized to the specified value.
|
||
53 | */
|
||
54 | public Matrix1(final double m00) { |
||
55 | this.m00 = m00;
|
||
56 | } |
||
57 | |||
58 | /**
|
||
59 | * Creates a new matrix initialized to the same value than the specified one.
|
||
60 | * The specified matrix size must be {@value #SIZE}×{@value #SIZE}.
|
||
61 | */
|
||
62 | public Matrix1(final Matrix matrix) { |
||
63 | if (matrix.getNumRow()!=SIZE || matrix.getNumCol()!=SIZE) {
|
||
64 | throw new IllegalArgumentException(); |
||
65 | } |
||
66 | m00 = matrix.getElement(0,0); |
||
67 | } |
||
68 | |||
69 | /**
|
||
70 | * Returns the number of rows in this matrix, which is always {@value #SIZE}
|
||
71 | * in this implementation.
|
||
72 | */
|
||
73 | public final int getNumRow() { |
||
74 | return SIZE;
|
||
75 | } |
||
76 | |||
77 | /**
|
||
78 | * Returns the number of colmuns in this matrix, which is always {@value #SIZE}
|
||
79 | * in this implementation.
|
||
80 | */
|
||
81 | public final int getNumCol() { |
||
82 | return SIZE;
|
||
83 | } |
||
84 | |||
85 | /**
|
||
86 | * {@inheritDoc}
|
||
87 | */
|
||
88 | public final double getElement(final int row, final int col) { |
||
89 | if (row==0 && col==0) { |
||
90 | return m00;
|
||
91 | } else {
|
||
92 | throw new IndexOutOfBoundsException(); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * {@inheritDoc}
|
||
98 | */
|
||
99 | public final void setElement(final int row, final int col, final double value) { |
||
100 | if (row==0 && col==0) { |
||
101 | m00 = value; |
||
102 | } else {
|
||
103 | throw new IndexOutOfBoundsException(); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /**
|
||
108 | * {@inheritDoc}
|
||
109 | */
|
||
110 | public final void setZero() { |
||
111 | m00 = 0;
|
||
112 | } |
||
113 | |||
114 | /**
|
||
115 | * {@inheritDoc}
|
||
116 | */
|
||
117 | public final void setIdentity() { |
||
118 | m00 = 1;
|
||
119 | } |
||
120 | |||
121 | /**
|
||
122 | * {@inheritDoc}
|
||
123 | */
|
||
124 | public final boolean isIdentity() { |
||
125 | return m00 == 1; |
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * {@inheritDoc}
|
||
130 | */
|
||
131 | public final boolean isIdentity(double tolerance) { |
||
132 | return Math.abs(m00 - 1) <= Math.abs(tolerance); |
||
133 | } |
||
134 | |||
135 | /**
|
||
136 | * {@inheritDoc}
|
||
137 | */
|
||
138 | public final boolean isAffine() { |
||
139 | return m00==1; |
||
140 | } |
||
141 | |||
142 | /**
|
||
143 | * {@inheritDoc}
|
||
144 | */
|
||
145 | public final void negate() { |
||
146 | m00 = -m00; |
||
147 | } |
||
148 | |||
149 | /**
|
||
150 | * {@inheritDoc}
|
||
151 | */
|
||
152 | public final void transpose() { |
||
153 | // Nothing to do for a 1x1 matrix.
|
||
154 | } |
||
155 | |||
156 | /**
|
||
157 | * Inverts this matrix in place.
|
||
158 | */
|
||
159 | public final void invert() { |
||
160 | if (m00 == 0) { |
||
161 | throw new SingularMatrixException(); |
||
162 | } |
||
163 | m00 = 1/m00;
|
||
164 | } |
||
165 | |||
166 | /**
|
||
167 | * {@inheritDoc}
|
||
168 | */
|
||
169 | public final void multiply(final Matrix matrix) { |
||
170 | if (matrix.getNumRow()!=SIZE || matrix.getNumCol()!=SIZE) {
|
||
171 | throw new IllegalArgumentException(); |
||
172 | } |
||
173 | m00 *= matrix.getElement(0,0); |
||
174 | } |
||
175 | |||
176 | /**
|
||
177 | * {@inheritDoc}
|
||
178 | */
|
||
179 | public boolean equals(final Matrix matrix, final double tolerance) { |
||
180 | return GeneralMatrix.epsilonEquals(this, matrix, tolerance); |
||
181 | } |
||
182 | |||
183 | /**
|
||
184 | * Returns {@code true} if the specified object is of type {@code Matrix1} and
|
||
185 | * all of the data members are equal to the corresponding data members in this matrix.
|
||
186 | */
|
||
187 | @Override
|
||
188 | public boolean equals(final Object object) { |
||
189 | if (object!=null && object.getClass().equals(getClass())) { |
||
190 | final Matrix1 that = (Matrix1) object;
|
||
191 | return Double.doubleToLongBits(this.m00) == Double.doubleToLongBits(that.m00); |
||
192 | } |
||
193 | return false; |
||
194 | } |
||
195 | |||
196 | /**
|
||
197 | * Returns a hash code value based on the data values in this object.
|
||
198 | */
|
||
199 | @Override
|
||
200 | public int hashCode() { |
||
201 | return (int)(Double.doubleToLongBits(m00) ^ serialVersionUID); |
||
202 | } |
||
203 | |||
204 | /**
|
||
205 | * Returns a string representation of this matrix. The returned string is implementation
|
||
206 | * dependent. It is usually provided for debugging purposes only.
|
||
207 | */
|
||
208 | // @Override
|
||
209 | // public String toString() {
|
||
210 | // return GeneralMatrix.toString(this);
|
||
211 | // }
|
||
212 | |||
213 | /**
|
||
214 | * Returns a clone of this matrix.
|
||
215 | */
|
||
216 | @Override
|
||
217 | public Matrix1 clone() {
|
||
218 | try {
|
||
219 | return (Matrix1) super.clone(); |
||
220 | } catch (CloneNotSupportedException e) { |
||
221 | // Should not happen, since we are cloneable.
|
||
222 | throw new AssertionError(e); |
||
223 | } |
||
224 | } |
||
225 | } |