Program Listing for File line2d.hpp

Return to documentation for file (include/tuw_geometry/line2d.hpp)

#ifndef TUW_GEOMETRY__LINE2D_HPP
#define TUW_GEOMETRY__LINE2D_HPP

#include <cstdio>

#include "tuw_geometry/polar2d.hpp"

namespace tuw
{
class Line2D;
using Line2DPtr = std::shared_ptr<Line2D>;
using Line2DConstPtr = std::shared_ptr<Line2D const>;

class Line2D : public cv::Vec<double, 3>
{
public:
  friend std::ostream & operator<<(std::ostream & os, const Line2D & o)
  {
    os << "[" << o.a() << ", " << o.b() << ", " << o.c() << "]";
    return os;
  }
  Line2D();
  Line2D(const Line2D & l);
  Line2D(cv::Vec<double, 3> & l, bool normalize = true);
  Line2D(
    const double & x0, const double & y0, const double & x1, const double & y1,
    bool normalize = true);
  Line2D(const Point2D & pt1, const Point2D & pt2, bool normalize = true);
  double & a();
  const double & a() const;
  double & b();
  const double & b() const;
  double & c();
  const double & c() const;
  void normalize();
  double distanceTo(const double & x, const double & y) const;
  double distanceTo(const Point2D & p) const;
  Point2D pointOnLine(const double & x, const double & y) const;
  Point2D pointOnLine(const Point2D & p) const;
  Point2D intersection(const Line2D & l) const;
  cv::Vec<double, 2> normal() const;
  Line2D & set(
    const double & x0, const double & y0, const double & x1, const double & y1,
    bool normalize = true);
  Line2D & set(const Point2D & p0, const Point2D & p1, bool normalize = true);
  cv::Vec<double, 3> & cv();
  const cv::Vec<double, 3> & cv() const;
  Polar2D toPolar() const;
};
using Lines2D = std::vector<Line2D>;
using Lines2DPtr = std::shared_ptr<Lines2D>;
using Lines2DConstPtr = std::shared_ptr<Lines2D const>;
}  // namespace tuw
#endif  // TUW_GEOMETRY__LINE2D_HPP