Direction.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS 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.  *   http://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. package org.orekit.models.earth.tessellation;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;

  19. /** Enumerate for neighboring directions in a {@link Mesh}.
  20.  * @author Luc Maisonobe
  21.  */
  22. enum Direction {

  23.     /** Along tile in the plus direction. */
  24.     PLUS_ALONG() {

  25.         /** {@inheritDoc} */
  26.         @Override
  27.         public Direction next() {
  28.             return PLUS_ACROSS;
  29.         }

  30.         /** {@inheritDoc} */
  31.         @Override
  32.         public int neighborAlongIndex(final Mesh.Node base) {
  33.             return base.getAlongIndex() + 1;
  34.         }

  35.         /** {@inheritDoc} */
  36.         @Override
  37.         public Vector3D motion(final Mesh.Node base,
  38.                                final double alongDistance, final double acrossDistance) {
  39.             return new Vector3D(alongDistance, base.getAlong());
  40.         }

  41.     },

  42.     /** Along tile in the minus direction. */
  43.     MINUS_ALONG() {

  44.         /** {@inheritDoc} */
  45.         @Override
  46.         public Direction next() {
  47.             return MINUS_ACROSS;
  48.         }

  49.         /** {@inheritDoc} */
  50.         @Override
  51.         public int neighborAlongIndex(final Mesh.Node base) {
  52.             return base.getAlongIndex() - 1;
  53.         }

  54.         /** {@inheritDoc} */
  55.         @Override
  56.         public Vector3D motion(final Mesh.Node base,
  57.                                final double alongDistance, final double acrossDistance) {
  58.             return new Vector3D(-alongDistance, base.getAlong());
  59.         }

  60.     },

  61.     /** Across tile in the plus direction. */
  62.     PLUS_ACROSS() {

  63.         /** {@inheritDoc} */
  64.         @Override
  65.         public Direction next() {
  66.             return MINUS_ALONG;
  67.         }

  68.         /** {@inheritDoc} */
  69.         @Override
  70.         public int neighborAcrossIndex(final Mesh.Node base) {
  71.             return base.getAcrossIndex() + 1;
  72.         }

  73.         /** {@inheritDoc} */
  74.         @Override
  75.         public Vector3D motion(final Mesh.Node base,
  76.                                final double alongDistance, final double acrossDistance) {
  77.             return new Vector3D(acrossDistance, base.getAcross());
  78.         }

  79.     },

  80.     /** Across tile in the minus direction. */
  81.     MINUS_ACROSS() {

  82.         /** {@inheritDoc} */
  83.         @Override
  84.         public Direction next() {
  85.             return PLUS_ALONG;
  86.         }

  87.         /** {@inheritDoc} */
  88.         @Override
  89.         public int neighborAcrossIndex(final Mesh.Node base) {
  90.             return base.getAcrossIndex() - 1;
  91.         }

  92.         /** {@inheritDoc} */
  93.         @Override
  94.         public Vector3D motion(final Mesh.Node base,
  95.                                final double alongDistance, final double acrossDistance) {
  96.             return new Vector3D(-acrossDistance, base.getAcross());
  97.         }

  98.     };

  99.     /** Get the next direction in counterclockwise order.
  100.      * @return next direction
  101.      */
  102.     public abstract Direction next();

  103.     /** Get the along index of neighbor.
  104.      * @param base base node
  105.      * @return along index of neighbor node
  106.      */
  107.     public int neighborAlongIndex(final Mesh.Node base) {
  108.         return base.getAlongIndex();
  109.     }

  110.     /** Get the across index of neighbor.
  111.      * @param base base node
  112.      * @return across index of neighbor node
  113.      */
  114.     public int neighborAcrossIndex(final Mesh.Node base) {
  115.         return base.getAcrossIndex();
  116.     }

  117.     /** Get the motion towards neighbor.
  118.      * @param base base node
  119.      * @param alongDistance distance for along tile motions
  120.      * @param acrossDistance distance for across tile motions
  121.      * @return motion towards neighbor
  122.      */
  123.     public abstract Vector3D motion(Mesh.Node base, double alongDistance, double acrossDistance);

  124. }