View Javadoc
1   /*
2    * Licensed to the Hipparchus project under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The Hipparchus project licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.hipparchus.geometry.euclidean.threed;
19  
20  import org.hipparchus.CalculusFieldElement;
21  import org.hipparchus.Field;
22  import org.hipparchus.util.Binary64Field;
23  import org.junit.Assert;
24  import org.junit.Test;
25  
26  public class RotationStageTest {
27  
28      @Test
29      public void testAxis() {
30          Assert.assertEquals(0.0,
31                              Vector3D.distance(Vector3D.PLUS_I, RotationStage.X.getAxis()),
32                              1.0e-15);
33          Assert.assertEquals(0.0,
34                              Vector3D.distance(Vector3D.PLUS_J, RotationStage.Y.getAxis()),
35                              1.0e-15);
36          Assert.assertEquals(0.0,
37                              Vector3D.distance(Vector3D.PLUS_K, RotationStage.Z.getAxis()),
38                              1.0e-15);
39      }
40  
41      @Test
42      public void testComponent() {
43          final Vector3D v = new Vector3D(1.0, 2.0, 3.0);
44          Assert.assertEquals( 1.0, RotationStage.X.getComponent(v), 1.0e-15);
45          Assert.assertEquals( 2.0, RotationStage.Y.getComponent(v), 1.0e-15);
46          Assert.assertEquals( 3.0, RotationStage.Z.getComponent(v), 1.0e-15);
47      }
48  
49      @Test
50      public void testFieldComponent() {
51          doTestFieldComponent(Binary64Field.getInstance());
52      }
53  
54      private <T extends CalculusFieldElement<T>> void doTestFieldComponent(final Field<T> field) {
55          final FieldVector3D<T> v = new FieldVector3D<>(field.getZero().newInstance(1.0),
56                                                         field.getZero().newInstance(2.0),
57                                                         field.getZero().newInstance(3.0));
58          Assert.assertEquals( 1.0, RotationStage.X.getComponent(v).getReal(), 1.0e-15);
59          Assert.assertEquals( 2.0, RotationStage.Y.getComponent(v).getReal(), 1.0e-15);
60          Assert.assertEquals( 3.0, RotationStage.Z.getComponent(v).getReal(), 1.0e-15);
61      }
62  
63  }