text: ﻿/*******************************************************************************
   * This file is part of Tiny3D (Tiny 3D Graphic Rendering Engine)
   * Copyright (C) 2015-2020  Answer Wong
   * For latest info, see https://github.com/answerear/Tiny3D
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   ******************************************************************************/
  
  
  namespace Tiny3D
  {
      template <typename T>
      inline TIntrPointSphere<T>::TIntrPointSphere()
          : mPoint(nullptr)
          , mSphere(nullptr)
      {
  
      }
  
      template <typename T>
      inline TIntrPointSphere<T>::TIntrPointSphere(
          const TVector3<T> &point,
          const TSphere<T> &sphere)
          : mPoint(&point)
          , mSphere(&sphere)
      {
  
      }
  
      template <typename T>
      inline TIntrPointSphere<T>::TIntrPointSphere(
          const TVector3<T> *point,
          const TSphere<T> *sphere)
          : mPoint(point)
          , mSphere(sphere)
      {
  
      }
  
      template <typename T>
      inline bool TIntrPointSphere<T>::test()
      {
          if (mPoint == nullptr || mSphere == nullptr)
              return false;
  
          const TVector3<T> &point = *mPoint;
          const TVector3<T> &center = mSphere->getCenter();
          T radius = mSphere->getRadius();
          if (point.distance2(center) <= radius * radius)
          {
              return false;
          }
  
          return true;
      }
  }
  
  