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