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.jupiter.api.Test;
24  
25  import static org.junit.jupiter.api.Assertions.assertEquals;
26  
27  class RotationStageTest {
28  
29      @Test
30      void testAxis() {
31          assertEquals(0.0,
32                              Vector3D.distance(Vector3D.PLUS_I, RotationStage.X.getAxis()),
33                              1.0e-15);
34          assertEquals(0.0,
35                              Vector3D.distance(Vector3D.PLUS_J, RotationStage.Y.getAxis()),
36                              1.0e-15);
37          assertEquals(0.0,
38                              Vector3D.distance(Vector3D.PLUS_K, RotationStage.Z.getAxis()),
39                              1.0e-15);
40      }
41  
42      @Test
43      void testComponent() {
44          final Vector3D v = new Vector3D(1.0, 2.0, 3.0);
45          assertEquals( 1.0, RotationStage.X.getComponent(v), 1.0e-15);
46          assertEquals( 2.0, RotationStage.Y.getComponent(v), 1.0e-15);
47          assertEquals( 3.0, RotationStage.Z.getComponent(v), 1.0e-15);
48      }
49  
50      @Test
51      void testFieldComponent() {
52          doTestFieldComponent(Binary64Field.getInstance());
53      }
54  
55      private <T extends CalculusFieldElement<T>> void doTestFieldComponent(final Field<T> field) {
56          final FieldVector3D<T> v = new FieldVector3D<>(field.getZero().newInstance(1.0),
57                                                         field.getZero().newInstance(2.0),
58                                                         field.getZero().newInstance(3.0));
59          assertEquals( 1.0, RotationStage.X.getComponent(v).getReal(), 1.0e-15);
60          assertEquals( 2.0, RotationStage.Y.getComponent(v).getReal(), 1.0e-15);
61          assertEquals( 3.0, RotationStage.Z.getComponent(v).getReal(), 1.0e-15);
62      }
63  
64  }