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.math3.geometry.euclidean.oned;
018
019import org.apache.commons.math3.geometry.partitioning.AbstractSubHyperplane;
020import org.apache.commons.math3.geometry.partitioning.Hyperplane;
021import org.apache.commons.math3.geometry.partitioning.Region;
022import org.apache.commons.math3.geometry.partitioning.Side;
023
024/** This class represents sub-hyperplane for {@link OrientedPoint}.
025 * <p>An hyperplane in 1D is a simple point, its orientation being a
026 * boolean.</p>
027 * <p>Instances of this class are guaranteed to be immutable.</p>
028 * @since 3.0
029 */
030public class SubOrientedPoint extends AbstractSubHyperplane<Euclidean1D, Euclidean1D> {
031
032    /** Simple constructor.
033     * @param hyperplane underlying hyperplane
034     * @param remainingRegion remaining region of the hyperplane
035     */
036    public SubOrientedPoint(final Hyperplane<Euclidean1D> hyperplane,
037                            final Region<Euclidean1D> remainingRegion) {
038        super(hyperplane, remainingRegion);
039    }
040
041    /** {@inheritDoc} */
042    @Override
043    public double getSize() {
044        return 0;
045    }
046
047    /** {@inheritDoc} */
048    @Override
049    public boolean isEmpty() {
050        return false;
051    }
052
053    /** {@inheritDoc} */
054    @Override
055    protected AbstractSubHyperplane<Euclidean1D, Euclidean1D> buildNew(final Hyperplane<Euclidean1D> hyperplane,
056                                                                       final Region<Euclidean1D> remainingRegion) {
057        return new SubOrientedPoint(hyperplane, remainingRegion);
058    }
059
060    /** {@inheritDoc} */
061    @Override
062    public Side side(final Hyperplane<Euclidean1D> hyperplane) {
063        final double global = hyperplane.getOffset(((OrientedPoint) getHyperplane()).getLocation());
064        return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
065    }
066
067    /** {@inheritDoc} */
068    @Override
069    public SplitSubHyperplane<Euclidean1D> split(final Hyperplane<Euclidean1D> hyperplane) {
070        final double global = hyperplane.getOffset(((OrientedPoint) getHyperplane()).getLocation());
071        return (global < -1.0e-10) ?
072                                    new SplitSubHyperplane<Euclidean1D>(null, this) :
073                                        new SplitSubHyperplane<Euclidean1D>(this, null);
074    }
075
076}