001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.geometry.euclidean.oned; 018 019import org.apache.commons.numbers.core.Precision; 020 021/** Class containing factory methods for constructing {@link OrientedPoint} instances. 022 */ 023public final class OrientedPoints { 024 025 /** Utility class; no instantiation. */ 026 private OrientedPoints() { 027 } 028 029 /** Create a new instance from the given location and boolean direction value. 030 * @param location the location of the hyperplane 031 * @param positiveFacing if true, the hyperplane will face toward positive infinity; 032 * otherwise, it will point toward negative infinity. 033 * @param precision precision context used to compare floating point values 034 * @return a new instance 035 */ 036 public static OrientedPoint fromLocationAndDirection(final double location, final boolean positiveFacing, 037 final Precision.DoubleEquivalence precision) { 038 return fromPointAndDirection(Vector1D.of(location), positiveFacing, precision); 039 } 040 041 /** Create a new instance from the given point and boolean direction value. 042 * @param point the location of the hyperplane 043 * @param positiveFacing if true, the hyperplane will face toward positive infinity; 044 * otherwise, it will point toward negative infinity. 045 * @param precision precision context used to compare floating point values 046 * @return a new instance 047 */ 048 public static OrientedPoint fromPointAndDirection(final Vector1D point, final boolean positiveFacing, 049 final Precision.DoubleEquivalence precision) { 050 return new OrientedPoint(point, positiveFacing, precision); 051 } 052 053 /** Create a new instance from the given point and direction. 054 * @param point the location of the hyperplane 055 * @param direction the direction of the plus side of the hyperplane 056 * @param precision precision context used to compare floating point values 057 * @return a new instance oriented in the given direction 058 * @throws IllegalArgumentException if the direction is zero as evaluated by the 059 * given precision context 060 */ 061 public static OrientedPoint fromPointAndDirection(final Vector1D point, final Vector1D direction, 062 final Precision.DoubleEquivalence precision) { 063 if (direction.isZero(precision)) { 064 throw new IllegalArgumentException("Oriented point direction cannot be zero"); 065 } 066 067 final boolean positiveFacing = direction.getX() > 0; 068 069 return new OrientedPoint(point, positiveFacing, precision); 070 } 071 072 /** Create a new instance at the given point, oriented so that it is facing positive infinity. 073 * @param point the location of the hyperplane 074 * @param precision precision context used to compare floating point values 075 * @return a new instance oriented toward positive infinity 076 */ 077 public static OrientedPoint createPositiveFacing(final Vector1D point, 078 final Precision.DoubleEquivalence precision) { 079 return new OrientedPoint(point, true, precision); 080 } 081 082 /** Create a new instance at the given location, oriented so that it is facing positive infinity. 083 * @param location the location of the hyperplane 084 * @param precision precision context used to compare floating point values 085 * @return a new instance oriented toward positive infinity 086 */ 087 public static OrientedPoint createPositiveFacing(final double location, 088 final Precision.DoubleEquivalence precision) { 089 return new OrientedPoint(Vector1D.of(location), true, precision); 090 } 091 092 /** Create a new instance at the given point, oriented so that it is facing negative infinity. 093 * @param point the location of the hyperplane 094 * @param precision precision context used to compare floating point values 095 * @return a new instance oriented toward negative infinity 096 */ 097 public static OrientedPoint createNegativeFacing(final Vector1D point, 098 final Precision.DoubleEquivalence precision) { 099 return new OrientedPoint(point, false, precision); 100 } 101 102 /** Create a new instance at the given location, oriented so that it is facing negative infinity. 103 * @param location the location of the hyperplane 104 * @param precision precision context used to compare floating point values 105 * @return a new instance oriented toward negative infinity 106 */ 107 public static OrientedPoint createNegativeFacing(final double location, 108 final Precision.DoubleEquivalence precision) { 109 return new OrientedPoint(Vector1D.of(location), false, precision); 110 } 111}