All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.conversantmedia.util.collection.spatial.AxialSplitLeaf Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.conversantmedia.util.collection.spatial;

/*
 * #%L
 * Conversant RTree
 * ~~
 * Conversantmedia.com © 2016, Conversant, Inc. Conversant® is a trademark of Conversant, Inc.
 * ~~
 * Licensed 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.
 * #L%
 */

import java.util.Arrays;
import java.util.Comparator;

/**
 * Fast RTree split suggested by Yufei Tao [email protected]
 *
 * Perform an axial split
 *
 * Created by jcairns on 5/5/15.
 */
final class AxialSplitLeaf extends Leaf {

    protected AxialSplitLeaf(final RectBuilder builder, final int mMin, final int mMax) {
        super(builder, mMin, mMax, RTree.Split.AXIAL);
    }

    @Override
    protected Node split(final T t) {
        final Branch pNode = new Branch<>(builder, mMin, mMax, splitType);
        final Node l1Node = create(builder, mMin, mMax, splitType);
        final Node l2Node = create(builder, mMin, mMax, splitType);
        final int nD = r[0].getNDim();

        // choose axis to split
        int axis = 0;
        double rangeD = mbr.getRange(0);
        for(int d=1; d rangeD) {
                axis = d;
                rangeD = dr;
            }
        }

        final int splitDimension = axis;

        // sort along split dimension
        final HyperRect[] sortedMbr = Arrays.copyOf(r, r.length);

        Arrays.sort(sortedMbr, new Comparator() {
            @Override
            public int compare(final HyperRect o1, final HyperRect o2) {
                final HyperPoint p1 = o1.getCentroid();
                final HyperPoint p2 = o2.getCentroid();

                return p1.getCoord(splitDimension).compareTo(p2.getCoord(splitDimension));
            }
        });

        // divide sorted leafs
        for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy