libspatialindex API Reference  (git-trunk)
Ball.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Project: libspatialindex - A C++ library for spatial indexing
3  * Author: Peter Labadorf - plaba3.1415@gmail.com
4  ******************************************************************************
5  * Copyright (c) 2023, Peter Labadorf
6  *
7  * All rights reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26 ******************************************************************************/
27 
28 #pragma once
29 
30 #ifndef M_PI
31 #define M_PI 3.14159265358979323846
32 #endif
33 
34 namespace SpatialIndex
35 {
36 
37  class SIDX_DLL Ball: public Tools::IObject, public virtual IShape
38  {
39  public:
40  Ball();
41  Ball(double radius, const Point& center);
42  Ball(double radius, const double *pCoords, uint32_t dimension);
43  Ball(const Ball& b);
44  ~Ball() override;
45 
46  virtual Ball& operator=(const Ball& b);
47  virtual bool operator==(const Ball& b) const;
48 
49  //
50  // IObject interface
51  //
52 
53  Ball* clone() override;
54 
55  //
56  // ISerializable interface
57  //
58 
59  uint32_t getByteArraySize() override;
60  void loadFromByteArray(const uint8_t *data) override;
61  void storeToByteArray(uint8_t **data, uint32_t &length) override;
62 
63  //
64  // IShape interface
65  //
66 
67  bool intersectsShape(const IShape &in) const override;
68  bool containsShape(const IShape &in) const override;
69  bool touchesShape(const IShape &in) const override;
70  void getCenter(SpatialIndex::Point &out) const override;
71  uint32_t getDimension() const override;
72  void getMBR(SpatialIndex::Region &out) const override;
73  double getArea() const override;
74  double getMinimumDistance(const IShape &in) const override;
75 
76  virtual bool containsLineSegment(const SpatialIndex::LineSegment *line) const;
77  virtual bool containsRegion(const SpatialIndex::Region *region) const;
78 
79  inline bool containsPoint(const Point *point) const
80  {
81  return getMinimumDistance(*point) <= m_centerPoint.m_dimension;
82  }
83 
84  inline bool containsBall(const Ball *ball) const
85  {
86  return getMinimumDistance(ball->m_centerPoint) + ball->m_radius <= m_radius;
87  }
88 
89  public:
90  double m_radius{0.0};
92 
93  }; // Ball
94 
95  SIDX_DLL std::ostream& operator<<(std::ostream& os, const Ball& ball);
96 
97 }
98 
bool containsPoint(const Point *point) const
Definition: Ball.h:79
Point m_centerPoint
Definition: Ball.h:91
double m_radius
Definition: Ball.h:90
bool containsBall(const Ball *ball) const
Definition: Ball.h:84
SIDX_DLL std::ostream & operator<<(std::ostream &os, const Ball &ball)
Definition: Ball.cc:215
#define SIDX_DLL
Definition: sidx_export.h:41