org.apache.commons.geometry.core.partitioning.Split Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-geometry-core Show documentation
Show all versions of commons-geometry-core Show documentation
Core interfaces and classes for Apache Commons Geometry.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.geometry.core.partitioning;
/** Class containing the result of splitting an object with a hyperplane.
* @param Split type
*/
public final class Split {
/** Part of the object lying on the minus side of the splitting hyperplane.
*/
private final T minus;
/** Part of the object lying on the plus side of the splitting hyperplane.
*/
private final T plus;
/** Build a new instance from its parts.
* @param minus part of the object lying on the minus side of the
* splitting hyperplane or null if no such part exists
* @param plus part of the object lying on the plus side of the
* splitting hyperplane or null if no such part exists.
*/
public Split(final T minus, final T plus) {
this.minus = minus;
this.plus = plus;
}
/** Get the part of the object lying on the minus side of the splitting
* hyperplane or null if no such part exists.
* @return part of the object lying on the minus side of the splitting
* hyperplane
*/
public T getMinus() {
return minus;
}
/** Get the part of the object lying on the plus side of the splitting
* hyperplane or null if no such part exists.
* @return part of the object lying on the plus side of the splitting
* hyperplane
*/
public T getPlus() {
return plus;
}
/** Get the location of the object with respect to its splitting
* hyperplane.
* @return
*
* - {@link SplitLocation#PLUS} - if only {@link #getPlus()} is not null
* - {@link SplitLocation#MINUS} - if only {@link #getMinus()} is not null
* - {@link SplitLocation#BOTH} - if both {@link #getPlus()} and {@link #getMinus()}
* are not null
* - {@link SplitLocation#NEITHER} - if both {@link #getPlus()} and {@link #getMinus()}
* are null
*
*/
public SplitLocation getLocation() {
if (minus != null) {
return plus != null ? SplitLocation.BOTH : SplitLocation.MINUS;
} else if (plus != null) {
return SplitLocation.PLUS;
}
return SplitLocation.NEITHER;
}
/** {@inheritDoc} */
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getSimpleName())
.append("[location= ")
.append(getLocation())
.append(", minus= ")
.append(minus)
.append(", plus= ")
.append(plus)
.append(']');
return sb.toString();
}
}