src/main/java/org/mstepan/advanced/ds/geometry/KDTree.java
public boolean add(T value) {

        checkNotNull(value, "Can't add 'null' value to KDTree");

        initDimensionsCount(value);

        if (isEmpty()) {
            root = new KDEntry<>(value, 0);
        }
        else {
            SearchResult<T> searchRes = find(value);

            // value already found in a tree
            if (isEquals(searchRes.entry.value, value)) {
                return false;
            }

            // insert LEFT
            if (searchRes.lastDirection == Direction.LEFT) {
                searchRes.entry.left = new KDEntry<>(value, searchRes.lastDimension);
            }
            // insert RIGHT
            else {
                searchRes.entry.right = new KDEntry<>(value, searchRes.lastDimension);
            }
        }

        ++size;
        return true;
    }
/**
     * Insert new value into K-D tree.
     *
     * @param value to insert into K-D tree.
     * @return true if value was successfully inserted otherwise false.
     */
Insert new value into K-D tree.
@param value to insert into K-D tree.
@return true if value was successfully inserted otherwise false.
Insert new value into K - D tree . @param value to insert into K - D tree . @return true if value was successfully inserted otherwise false .
public boolean add(T value) {
        checkNotNull(value, "Can't add 'null' value to KDTree");
        initDimensionsCount(value);
        if (isEmpty()) {
            root = new KDEntry<>(value, 0);
        }
        else {
            SearchResult<T> searchRes = find(value);
            if (isEquals(searchRes.entry.value, value)) {
                return false;
            }
            if (searchRes.lastDirection == Direction.LEFT) {
                searchRes.entry.left = new KDEntry<>(value, searchRes.lastDimension);
            }
            else {
                searchRes.entry.right = new KDEntry<>(value, searchRes.lastDimension);
            }
        }
        ++size;
        return true;
    }
public boolean add ( T value ) { checkNotNull ( value , "Can't add 'null' value to KDTree" ) ; initDimensionsCount ( value ) ; if ( isEmpty ( ) ) { root = new KDEntry < > ( value , 0 ) ; } else { SearchResult < T > searchRes = find ( value ) ; if ( isEquals ( searchRes . entry . value , value ) ) { return false ; } if ( searchRes . lastDirection == Direction . LEFT ) { searchRes . entry . left = new KDEntry < > ( value , searchRes . lastDimension ) ; } else { searchRes . entry . right = new KDEntry < > ( value , searchRes . lastDimension ) ; } } ++ size ; return true ; }
Insert new value into K-D tree.
Insert new value into K - D tree .
// value already found in a tree // insert LEFT // insert RIGHT