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.geometry.spherical.twod;
018
019import java.util.Arrays;
020import java.util.Collection;
021import java.util.List;
022import java.util.stream.Collectors;
023
024import org.apache.commons.geometry.core.partitioning.BoundarySource;
025
026/** Extension of the {@link BoundarySource} interface for spherical 2D
027 * space.
028 */
029public interface BoundarySource2S extends BoundarySource<GreatArc> {
030
031    /** Return a {@link BoundaryList2S} containing the boundaries in this instance.
032     * @return a {@link BoundaryList2S} containing the boundaries in this instance
033     */
034    default BoundaryList2S toList() {
035        final List<GreatArc> boundaries = boundaryStream()
036                .collect(Collectors.toList());
037
038        return new BoundaryList2S(boundaries);
039    }
040
041    /** Return a BSP tree constructed from the boundaries contained in this
042     * instance. The default implementation creates a new, empty tree
043     * and inserts the boundaries from this instance.
044     * @return a BSP tree constructed from the boundaries in this instance
045     */
046    default RegionBSPTree2S toTree() {
047        final RegionBSPTree2S tree = RegionBSPTree2S.empty();
048        tree.insert(this);
049
050        return tree;
051    }
052
053    /** Return a {@link BoundarySource2S} instance containing the given boundaries.
054     * @param boundaries boundaries to include in the boundary source
055     * @return a boundary source containing the given boundaries
056     */
057    static BoundarySource2S of(final GreatArc... boundaries) {
058        return of(Arrays.asList(boundaries));
059    }
060
061    /** Return a {@link BoundarySource2S} instance containing the given boundaries. The given
062     * collection is used directly as the source of the line subsets; no copy is made.
063     * @param boundaries boundaries to include in the boundary source
064     * @return a boundary source containing the given boundaries
065     */
066    static BoundarySource2S of(final Collection<GreatArc> boundaries) {
067        return boundaries::stream;
068    }
069}