View Javadoc
1   /*
2    * Copyright 2018-2022 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.geojson.model;
18  
19  import io.swagger.v3.oas.annotations.media.Schema;
20  import java.io.Serial;
21  import java.io.Serializable;
22  import java.math.BigDecimal;
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import lombok.EqualsAndHashCode;
26  import lombok.NoArgsConstructor;
27  import lombok.ToString;
28  
29  /**
30   * The bounding box of a geometry, feature or feature collection.
31   *
32   * @author Christian Bremer
33   */
34  @Schema(description = "The bounding box of a geometry, feature or feature collection.")
35  @EqualsAndHashCode(callSuper = true)
36  @ToString(callSuper = true)
37  @NoArgsConstructor
38  public class BoundingBox extends ArrayList<BigDecimal> implements Serializable {
39  
40    @Serial
41    private static final long serialVersionUID = 1L;
42  
43    /**
44     * Instantiates a new bounding box.
45     *
46     * @param coordinates the coordinates
47     */
48    public BoundingBox(Collection<? extends BigDecimal> coordinates) {
49      super(coordinates);
50    }
51  
52    @Schema(hidden = true)
53    @Override
54    public boolean isEmpty() {
55      return super.isEmpty();
56    }
57  
58    /**
59     * The bounding box as double array.
60     *
61     * @return the bounding box as double array
62     */
63    public double[] toDoubleArray() {
64      if (size() == 4 || size() == 6) {
65        double[] bbox = new double[size()];
66        int i = 0;
67        for (BigDecimal value : this) {
68          bbox[i] = value.doubleValue();
69          i++;
70        }
71        return bbox;
72      }
73      return null;
74    }
75  
76  }
77