OrientedPoint.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) 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 ASF 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.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */
  21. package org.hipparchus.geometry.euclidean.oned;

  22. import org.hipparchus.geometry.partitioning.Hyperplane;

  23. /** This class represents a 1D oriented hyperplane.
  24.  * <p>An hyperplane in 1D is a simple point, its orientation being a
  25.  * boolean.</p>
  26.  * <p>Instances of this class are guaranteed to be immutable.</p>
  27.  */
  28. public class OrientedPoint implements Hyperplane<Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint> {

  29.     /** Vector location. */
  30.     private final Vector1D location;

  31.     /** Orientation. */
  32.     private boolean direct;

  33.     /** Tolerance below which points are considered to belong to the hyperplane. */
  34.     private final double tolerance;

  35.     /** Simple constructor.
  36.      * @param location location of the hyperplane
  37.      * @param direct if true, the plus side of the hyperplane is towards
  38.      * abscissas greater than {@code location}
  39.      * @param tolerance tolerance below which points are considered to belong to the hyperplane
  40.      */
  41.     public OrientedPoint(final Vector1D location, final boolean direct, final double tolerance) {
  42.         this.location  = location;
  43.         this.direct    = direct;
  44.         this.tolerance = tolerance;
  45.     }

  46.     /** Copy the instance.
  47.      * <p>Since instances are immutable, this method directly returns
  48.      * the instance.</p>
  49.      * @return the instance itself
  50.      */
  51.     @Override
  52.     public OrientedPoint copySelf() {
  53.         return this;
  54.     }

  55.     /** {@inheritDoc} */
  56.     @Override
  57.     public double getOffset(final Vector1D point) {
  58.         final double delta = point.getX() - location.getX();
  59.         return direct ? delta : -delta;
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public Vector1D moveToOffset(final Vector1D point, final double offset) {
  64.         return new Vector1D(location.getX() + (direct ? offset : -offset));
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public Vector1D arbitraryPoint() {
  69.         return location;
  70.     }

  71.     /** Build a region covering the whole hyperplane.
  72.      * <p>Since this class represent zero dimension spaces which does
  73.      * not have lower dimension sub-spaces, this method returns a dummy
  74.      * implementation of a {@link
  75.      * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}.
  76.      * This implementation is only used to allow the {@link
  77.      * org.hipparchus.geometry.partitioning.SubHyperplane
  78.      * SubHyperplane} class implementation to work properly, it should
  79.      * <em>not</em> be used otherwise.</p>
  80.      * @return a dummy sub hyperplane
  81.      */
  82.     @Override
  83.     public SubOrientedPoint wholeHyperplane() {
  84.         return new SubOrientedPoint(this, null);
  85.     }

  86.     /** {@inheritDoc}.
  87.      * <p>Since this class represent zero dimension spaces which does
  88.      * not have lower dimension sub-spaces, this method returns a dummy
  89.      * implementation of a {@link
  90.      * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}.
  91.      * This implementation is only used to allow the {@link
  92.      * org.hipparchus.geometry.partitioning.SubHyperplane
  93.      * SubHyperplane} class implementation to work properly, it should
  94.      * <em>not</em> be used otherwise.</p>
  95.      * @return a dummy sub hyperplane
  96.      */
  97.     @Override
  98.     public SubOrientedPoint emptyHyperplane() {
  99.         return new SubOrientedPoint(this, null);
  100.     }

  101.     /** Build a region covering the whole space.
  102.      * @return a region containing the instance (really an {@link
  103.      * IntervalsSet IntervalsSet} instance)
  104.      */
  105.     @Override
  106.     public IntervalsSet wholeSpace() {
  107.         return new IntervalsSet(tolerance);
  108.     }

  109.     /** {@inheritDoc} */
  110.     @Override
  111.     public boolean sameOrientationAs(final OrientedPoint other) {
  112.         return direct == other.direct;
  113.     }

  114.     /** {@inheritDoc}
  115.      */
  116.     @Override
  117.     public Vector1D project(Vector1D point) {
  118.         return location;
  119.     }

  120.     /** {@inheritDoc}
  121.      */
  122.     @Override
  123.     public double getTolerance() {
  124.         return tolerance;
  125.     }

  126.     /** Get the hyperplane location on the real line.
  127.      * @return the hyperplane location
  128.      */
  129.     public Vector1D getLocation() {
  130.         return location;
  131.     }

  132.     /** Check if the hyperplane orientation is direct.
  133.      * @return true if the plus side of the hyperplane is towards
  134.      * abscissae greater than hyperplane location
  135.      */
  136.     public boolean isDirect() {
  137.         return direct;
  138.     }

  139.     /** Revert the instance.
  140.      */
  141.     public void revertSelf() {
  142.         direct = !direct;
  143.     }

  144. }