libspatialindex API Reference  (git-trunk)
LineSegment.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Project: libspatialindex - A C++ library for spatial indexing
3  * Author: Marios Hadjieleftheriou, mhadji@gmail.com
4  ******************************************************************************
5  * Copyright (c) 2004, Marios Hadjieleftheriou
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 namespace SpatialIndex
31 {
32  class SIDX_DLL LineSegment : public Tools::IObject, public virtual IShape
33  {
34  public:
36  LineSegment(const double* startPoint, const double* endPoint, uint32_t dimension);
37  LineSegment(const Point& startPoint, const Point& endPoint);
38  LineSegment(const LineSegment& l);
39  ~LineSegment() override;
40 
41  virtual LineSegment& operator=(const LineSegment& p);
42  virtual bool operator==(const LineSegment& p) const;
43 
44  //
45  // IObject interface
46  //
47  LineSegment* clone() override;
48 
49  //
50  // ISerializable interface
51  //
52  uint32_t getByteArraySize() override;
53  void loadFromByteArray(const uint8_t* data) override;
54  void storeToByteArray(uint8_t** data, uint32_t& length) override;
55 
56  //
57  // IShape interface
58  //
59  bool intersectsShape(const IShape& in) const override;
60  bool containsShape(const IShape& in) const override;
61  bool touchesShape(const IShape& in) const override;
62  void getCenter(Point& out) const override;
63  uint32_t getDimension() const override;
64  void getMBR(Region& out) const override;
65  double getArea() const override;
66  double getMinimumDistance(const IShape& in) const override;
67 
68  virtual bool intersectsLineSegment(const LineSegment& l) const;
69  virtual bool intersectsRegion(const Region& p) const;
70  virtual double getMinimumDistance(const Point& p) const;
71  //virtual double getMinimumDistance(const Region& r) const;
72  virtual double getRelativeMinimumDistance(const Point& p) const;
73  virtual double getRelativeMaximumDistance(const Region& r) const;
74  virtual double getAngleOfPerpendicularRay();
75 
76  virtual void makeInfinite(uint32_t dimension);
77  virtual void makeDimension(uint32_t dimension);
78 
79  public:
80  uint32_t m_dimension{0};
81  double* m_pStartPoint{nullptr};
82  double* m_pEndPoint{nullptr};
83 
84  friend class Region;
85  friend class Point;
86  friend SIDX_DLL std::ostream& operator<<(std::ostream& os, const LineSegment& pt);
87 
88  protected:
89 
90  //some helpers for intersects methods
91  static double doubleAreaTriangle(const Point& a, const Point& b, const Point& c);
92  static bool leftOf(const Point& a, const Point& b, const Point& c);
93  static bool collinear(const Point& a, const Point& b, const Point& c);
94  static bool between(const Point& a, const Point& b, const Point& c);
95  static bool between(double a, double b, double c);
96  static bool intersectsProper(const Point& a, const Point& b, const Point& c, const Point& d);
97  static bool intersects(const Point& a, const Point& b, const Point& c, const Point& d);
98 
99  }; // LineSegment
100 
101  SIDX_DLL std::ostream& operator<<(std::ostream& os, const LineSegment& pt);
102 }
103 
friend SIDX_DLL std::ostream & operator<<(std::ostream &os, const LineSegment &pt)
SIDX_DLL std::ostream & operator<<(std::ostream &os, const Ball &ball)
Definition: Ball.cc:215
#define SIDX_DLL
Definition: sidx_export.h:41