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