// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#ifndef _GeomEval_CircularHelicoidSurface_HeaderFile
#define _GeomEval_CircularHelicoidSurface_HeaderFile

#include <Geom_ElementarySurface.hxx>

//! Describes a circular helicoid surface.
//! A ruled surface generated by a line segment rotating uniformly about an axis
//! while translating along it. Named "circular" because the generating line
//! sweeps circular helices at constant radius.
//!
//! The parametric equation is:
//! @code
//!   S(u,v) = O + v*cos(u)*XDir + v*sin(u)*YDir + (P*u/(2*Pi))*ZDir
//! @endcode
//! where:
//! - O, XDir, YDir, ZDir are from the local coordinate system (gp_Ax3),
//! - P is the pitch (axial advance per 2*Pi turn, must be != 0).
//!
//! The parametric range is (-inf, +inf) for both u and v.
//! The surface is neither periodic nor closed. Continuity is GeomAbs_CN.
class GeomEval_CircularHelicoidSurface : public Geom_ElementarySurface
{
public:
  //! Creates a circular helicoid surface.
  //! @param[in] thePosition the local coordinate system
  //! @param[in] thePitch the axial advance per 2*Pi turn (must be != 0)
  //! @throw Standard_ConstructionError if thePitch == 0
  Standard_EXPORT GeomEval_CircularHelicoidSurface(const gp_Ax3& thePosition, double thePitch);

  //! Returns the pitch.
  Standard_EXPORT double Pitch() const;

  //! Sets a new pitch value.
  //! @param[in] thePitch the new pitch (must be != 0)
  //! @throw Standard_ConstructionError if thePitch == 0
  Standard_EXPORT void SetPitch(double thePitch);

  //! Reversal is not supported for this eval surface.
  //! @throw Standard_NotImplemented
  Standard_EXPORT void UReverse() final;

  //! Reversal is not supported for this eval surface.
  //! @throw Standard_NotImplemented
  Standard_EXPORT void VReverse() final;

  //! Reversal is not supported for this eval surface.
  //! @throw Standard_NotImplemented
  Standard_EXPORT double UReversedParameter(const double U) const final;

  //! Reversal is not supported for this eval surface.
  //! @throw Standard_NotImplemented
  Standard_EXPORT double VReversedParameter(const double V) const final;

  //! Returns infinite bounds for both parameters.
  Standard_EXPORT void Bounds(double& U1, double& U2, double& V1, double& V2) const final;

  //! Returns false.
  Standard_EXPORT bool IsUClosed() const final;

  //! Returns false.
  Standard_EXPORT bool IsVClosed() const final;

  //! Returns false.
  Standard_EXPORT bool IsUPeriodic() const final;

  //! Returns false.
  Standard_EXPORT bool IsVPeriodic() const final;

  //! Isoparametric curve extraction is not supported for this eval surface.
  //! @throw Standard_NotImplemented
  Standard_EXPORT occ::handle<Geom_Curve> UIso(const double U) const final;

  //! Isoparametric curve extraction is not supported for this eval surface.
  //! @throw Standard_NotImplemented
  Standard_EXPORT occ::handle<Geom_Curve> VIso(const double V) const final;

  //! Computes the point S(U, V) on the surface.
  Standard_EXPORT gp_Pnt EvalD0(const double U, const double V) const final;

  //! Computes the point and first partial derivatives at (U, V).
  Standard_EXPORT Geom_Surface::ResD1 EvalD1(const double U, const double V) const final;

  //! Computes the point and partial derivatives up to 2nd order at (U, V).
  Standard_EXPORT Geom_Surface::ResD2 EvalD2(const double U, const double V) const final;

  //! Computes the point and partial derivatives up to 3rd order at (U, V).
  Standard_EXPORT Geom_Surface::ResD3 EvalD3(const double U, const double V) const final;

  //! Computes the derivative of order Nu in u and Nv in v.
  //! @throw Geom_UndefinedDerivative if Nu + Nv < 1 or Nu < 0 or Nv < 0
  Standard_EXPORT gp_Vec EvalDN(const double U,
                                const double V,
                                const int    Nu,
                                const int    Nv) const final;

  //! Transformation is not supported for this eval geometry.
  //! @throw Standard_NotImplemented
  Standard_EXPORT void Transform(const gp_Trsf& T) final;

  //! Creates a new object which is a copy of this surface.
  Standard_EXPORT occ::handle<Geom_Geometry> Copy() const final;

  //! Dumps the content of me into the stream.
  Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const final;

  DEFINE_STANDARD_RTTIEXT(GeomEval_CircularHelicoidSurface, Geom_ElementarySurface)

private:
  double myPitch; //!< Axial advance per 2*Pi turn
};

#endif // _GeomEval_CircularHelicoidSurface_HeaderFile
