Program Listing for File line.hxx

Return to documentation for file (src/acme/line.hxx)

/*
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                     *
 * The ACME project                                                    *
 *                                                                     *
 * Copyright (c) 2020, Davide Stocco and Enrico Bertolazzi.            *
 *                                                                     *
 * The ACME project and its components are supplied under the terms of *
 * the open source BSD 2-Clause License. The contents of the ACME      *
 * project and its components may not be copied or disclosed except in *
 * accordance with the terms of the BSD 2-Clause License.              *
 *                                                                     *
 * URL: https://opensource.org/licenses/BSD-2-Clause                   *
 *                                                                     *
 *    Davide Stocco                                                    *
 *    Department of Industrial Engineering                             *
 *    University of Trento                                             *
 *    e-mail: davide.stocco@unitn.it                                   *
 *                                                                     *
 *    Enrico Bertolazzi                                                *
 *    Department of Industrial Engineering                             *
 *    University of Trento                                             *
 *    e-mail: enrico.bertolazzi@unitn.it                               *
 *                                                                     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/


#pragma once
#ifndef INCLUDE_ACME_LINE_HXX
#define INCLUDE_ACME_LINE_HXX

#include "point.hxx"

namespace acme
{

  /*\
   |   _ _
   |  | (_)_ __   ___
   |  | | | '_ \ / _ \
   |  | | | | | |  __/
   |  |_|_|_| |_|\___|
   |
  \*/


  class line : public entity
  {
  private:
    point m_origin    = NAN_POINT;
    vec3  m_direction = NAN_VEC3;

  public:
    line(line const &) = default;

    line(line &&) = default;

    line & operator=(const line &) = default;

    line & operator=(line &&) = default;

    ~line(void) override = default;

    line(void);

    line(
      real ox,
      real oy,
      real oz,
      real dx,
      real dy,
      real dz
    );

    line(
      point const & origin,
      vec3  const & direction
    );

    bool
    isApprox(
      line const & line_in,
      real         tolerance = EPSILON
    ) const;

    point const &
    origin(void)
    const;

    point &
    origin(void);

    vec3 const &
    direction(void)
    const;

    vec3 &
    direction(void);

    void
    normalize(void);

    vec3
    toVector(void)
    const;

    vec3
    toUnitVector(void)
    const;

    void
    reverse(void);

    void
    translate(
      vec3 const & vector_in
    ) override;

    void
    transform(
      affine const & affine_in
    ) override;

    bool
    isInside(
      point const & point_in,
      real          tolerance = EPSILON
    ) const;

    bool
    isDegenerated(
      real tolerance = EPSILON
    ) const override;

    inline
    integer
    level(void)
      const override
    {
      return integer(3);
    }

    inline
    std::string
    type(void)
      const override
    {
      return "line";
    }

    inline
    bool
    isNone(void)
      const override
    {
      return false;
    }

    inline
    bool
    isPoint(void)
      const override
    {
      return false;
    }

    inline
    bool
    isLine(void)
      const override
    {
      return true;
    }

    inline
    bool
    isRay(void)
      const override
    {
      return false;
    }

    inline
    bool
    isPlane(void)
      const override
    {
      return false;
    }

    inline
    bool
    isSegment(void)
      const override
    {
      return false;
    }

    inline
    bool
    isTriangle(void)
      const override
    {
      return false;
    }

    inline
    bool
    isDisk(void)
      const override
    {
      return false;
    }

    inline
    bool
    isBall(void)
      const override
    {
      return false;
    }

    inline
    bool
    isClampable(void)
      const override
    {
      return false;
    }

    inline
    bool
    isNonClampable(void)
      const override
    {
      return true;
    }

    bool
    clamp(
      vec3 & min,
      vec3 & max
    ) const override;

    bool
    clamp(
      real & min_x,
      real & min_y,
      real & min_z,
      real & max_x,
      real & max_y,
      real & max_z
    ) const override;

  }; // class line

  static line const & NAN_LINE   = * new line(NAN_POINT, NAN_VEC3);
  static line       & DUMMY_LINE = * new line(NAN_POINT, NAN_VEC3);

} // namespace acme

#endif