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 /* 19 * This is not the original file distributed by the Apache Software Foundation 20 * It has been modified by the Hipparchus project 21 */ 22 package org.hipparchus.geometry.euclidean.oned; 23 24 import org.hipparchus.geometry.partitioning.Hyperplane; 25 26 /** This class represents a 1D oriented hyperplane. 27 * <p>An hyperplane in 1D is a simple point, its orientation being a 28 * boolean.</p> 29 * <p>Instances of this class are guaranteed to be immutable.</p> 30 */ 31 public class OrientedPoint implements Hyperplane<Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint> { 32 33 /** Vector location. */ 34 private final Vector1D location; 35 36 /** Orientation. */ 37 private boolean direct; 38 39 /** Tolerance below which points are considered to belong to the hyperplane. */ 40 private final double tolerance; 41 42 /** Simple constructor. 43 * @param location location of the hyperplane 44 * @param direct if true, the plus side of the hyperplane is towards 45 * abscissas greater than {@code location} 46 * @param tolerance tolerance below which points are considered to belong to the hyperplane 47 */ 48 public OrientedPoint(final Vector1D location, final boolean direct, final double tolerance) { 49 this.location = location; 50 this.direct = direct; 51 this.tolerance = tolerance; 52 } 53 54 /** Copy the instance. 55 * <p>Since instances are immutable, this method directly returns 56 * the instance.</p> 57 * @return the instance itself 58 */ 59 @Override 60 public OrientedPoint copySelf() { 61 return this; 62 } 63 64 /** {@inheritDoc} */ 65 @Override 66 public double getOffset(final Vector1D point) { 67 final double delta = point.getX() - location.getX(); 68 return direct ? delta : -delta; 69 } 70 71 /** {@inheritDoc} */ 72 @Override 73 public Vector1D moveToOffset(final Vector1D point, final double offset) { 74 return new Vector1D(location.getX() + (direct ? offset : -offset)); 75 } 76 77 /** {@inheritDoc} */ 78 @Override 79 public Vector1D arbitraryPoint() { 80 return location; 81 } 82 83 /** Build a region covering the whole hyperplane. 84 * <p>Since this class represent zero dimension spaces which does 85 * not have lower dimension sub-spaces, this method returns a dummy 86 * implementation of a {@link 87 * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}. 88 * This implementation is only used to allow the {@link 89 * org.hipparchus.geometry.partitioning.SubHyperplane 90 * SubHyperplane} class implementation to work properly, it should 91 * <em>not</em> be used otherwise.</p> 92 * @return a dummy sub hyperplane 93 */ 94 @Override 95 public SubOrientedPoint wholeHyperplane() { 96 return new SubOrientedPoint(this, null); 97 } 98 99 /** {@inheritDoc}. 100 * <p>Since this class represent zero dimension spaces which does 101 * not have lower dimension sub-spaces, this method returns a dummy 102 * implementation of a {@link 103 * org.hipparchus.geometry.partitioning.SubHyperplane SubHyperplane}. 104 * This implementation is only used to allow the {@link 105 * org.hipparchus.geometry.partitioning.SubHyperplane 106 * SubHyperplane} class implementation to work properly, it should 107 * <em>not</em> be used otherwise.</p> 108 * @return a dummy sub hyperplane 109 */ 110 @Override 111 public SubOrientedPoint emptyHyperplane() { 112 return new SubOrientedPoint(this, null); 113 } 114 115 /** Build a region covering the whole space. 116 * @return a region containing the instance (really an {@link 117 * IntervalsSet IntervalsSet} instance) 118 */ 119 @Override 120 public IntervalsSet wholeSpace() { 121 return new IntervalsSet(tolerance); 122 } 123 124 /** {@inheritDoc} */ 125 @Override 126 public boolean sameOrientationAs(final OrientedPoint other) { 127 return direct == other.direct; 128 } 129 130 /** {@inheritDoc} 131 */ 132 @Override 133 public Vector1D project(Vector1D point) { 134 return location; 135 } 136 137 /** {@inheritDoc} 138 */ 139 @Override 140 public double getTolerance() { 141 return tolerance; 142 } 143 144 /** Get the hyperplane location on the real line. 145 * @return the hyperplane location 146 */ 147 public Vector1D getLocation() { 148 return location; 149 } 150 151 /** Check if the hyperplane orientation is direct. 152 * @return true if the plus side of the hyperplane is towards 153 * abscissae greater than hyperplane location 154 */ 155 public boolean isDirect() { 156 return direct; 157 } 158 159 /** Revert the instance. 160 */ 161 public void revertSelf() { 162 direct = !direct; 163 } 164 165 }