Skip to content

File Point.h

File List > src > Point.h

Go to the documentation of this file

// Copyright (c) 2012-2013, IGN France.
// Copyright (c) 2012-2022, Oslandia.
// SPDX-License-Identifier: LGPL-2.0-or-later

#ifndef _SFCGAL_POINT_H_
#define _SFCGAL_POINT_H_

#include "SFCGAL/Coordinate.h"

#include "SFCGAL/Geometry.h"
#include "SFCGAL/detail/TypeForDimension.h"

#include <boost/serialization/base_object.hpp>

namespace SFCGAL {

class SFCGAL_API Point : public Geometry {
public:
  Point();
  Point(const Coordinate &coordinate);
  Point(const Kernel::FT &x, const Kernel::FT &y);
  Point(const Kernel::FT &x, const Kernel::FT &y, const Kernel::FT &z,
        const double &m = NaN());
  Point(const double &x, const double &y);

  Point(const double &x, const double &y, const double &z);

  Point(const double &x, const double &y, const double &z, const double &m);

  Point(const Kernel::Point_2 &other);
  Point(const Kernel::Point_3 &other);

  Point(const Point &other);
  Point &
  operator=(const Point &other);
  ~Point();

  //-- SFCGAL::Geometry
  virtual Point *
  clone() const;

  //-- SFCGAL::Geometry
  virtual std::string
  geometryType() const;
  //-- SFCGAL::Geometry
  virtual GeometryType
  geometryTypeId() const;
  //-- SFCGAL::Geometry
  virtual int
  dimension() const;
  //-- SFCGAL::Geometry
  virtual int
  coordinateDimension() const;
  //-- SFCGAL::Geometry
  virtual bool
  isEmpty() const;
  //-- SFCGAL::Geometry
  virtual bool
  is3D() const;
  //-- SFCGAL::Geometry
  virtual bool
  isMeasured() const;
  //--- accessors

  inline Kernel::RT
  x() const
  {
    return _coordinate.x();
  }
  inline Kernel::RT
  y() const
  {
    return _coordinate.y();
  }
  inline Kernel::RT
  z() const
  {
    return _coordinate.z();
  }

  inline double
  m() const
  {
    return _m;
  }
  inline void
  setM(const double &m)
  {
    _m = m;
  }

  bool
  operator<(const Point &other) const;

  bool
  operator==(const Point &other) const;
  bool
  operator!=(const Point &other) const;

  bool
  almostEqual(const Point &other, const double tolerance) const;

  //-- visitors

  //-- SFCGAL::Geometry
  virtual void
  accept(GeometryVisitor &visitor);
  //-- SFCGAL::Geometry
  virtual void
  accept(ConstGeometryVisitor &visitor) const;

  inline Kernel::Vector_2
  toVector_2() const
  {
    return _coordinate.toVector_2();
  }

  inline Kernel::Vector_3
  toVector_3() const
  {
    return _coordinate.toVector_3();
  }

  inline Kernel::Point_2
  toPoint_2() const
  {
    return _coordinate.toPoint_2();
  }

  inline Kernel::Point_3
  toPoint_3() const
  {
    return _coordinate.toPoint_3();
  }

  template <int D>
  typename detail::TypeForDimension<D>::Point
  toPoint_d() const;

  inline Coordinate &
  coordinate()
  {
    return _coordinate;
  }
  inline const Coordinate &
  coordinate() const
  {
    return _coordinate;
  }

  template <class Archive>
  void
  serialize(Archive &ar, const unsigned int /*version*/)
  {
    ar &boost::serialization::base_object<Geometry>(*this);
    ar &_coordinate;
  }

private:
  Coordinate _coordinate;
  double _m;
};

} // namespace SFCGAL

#endif