    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     */
    017    package org.apache.commons.math3.geometry.euclidean.oned;
    018
    019    import org.apache.commons.math3.geometry.partitioning.AbstractSubHyperplane;
    020    import org.apache.commons.math3.geometry.partitioning.Hyperplane;
    021    import org.apache.commons.math3.geometry.partitioning.Region;
    022    import 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     * @version $Id: SubOrientedPoint.java 1416643 2012-12-03 19:37:14Z tn $
    029     * @since 3.0
    030     */
    031    public class SubOrientedPoint extends AbstractSubHyperplane<Euclidean1D, Euclidean1D> {
    032
    033        /** Simple constructor.
    034         * @param hyperplane underlying hyperplane
    035         * @param remainingRegion remaining region of the hyperplane
    036         */
    037        public SubOrientedPoint(final Hyperplane<Euclidean1D> hyperplane,
    038                                final Region<Euclidean1D> remainingRegion) {
    039            super(hyperplane, remainingRegion);
    040        }
    041
    042        /** {@inheritDoc} */
    043        @Override
    044        public double getSize() {
    045            return 0;
    046        }
    047
    048        /** {@inheritDoc} */
    049        @Override
    050        protected AbstractSubHyperplane<Euclidean1D, Euclidean1D> buildNew(final Hyperplane<Euclidean1D> hyperplane,
    051                                                                           final Region<Euclidean1D> remainingRegion) {
    052            return new SubOrientedPoint(hyperplane, remainingRegion);
    053        }
    054
    055        /** {@inheritDoc} */
    056        @Override
    057        public Side side(final Hyperplane<Euclidean1D> hyperplane) {
    058            final double global = hyperplane.getOffset(((OrientedPoint) getHyperplane()).getLocation());
    059            return (global < -1.0e-10) ? Side.MINUS : ((global > 1.0e-10) ? Side.PLUS : Side.HYPER);
    060        }
    061
    062        /** {@inheritDoc} */
    063        @Override
    064        public SplitSubHyperplane<Euclidean1D> split(final Hyperplane<Euclidean1D> hyperplane) {
    065            final double global = hyperplane.getOffset(((OrientedPoint) getHyperplane()).getLocation());
    066            return (global < -1.0e-10) ?
    067                                        new SplitSubHyperplane<Euclidean1D>(null, this) :
    068                                            new SplitSubHyperplane<Euclidean1D>(this, null);
    069        }
    070
    071    }