// Created on: 1991-05-27
// Created by: Isabelle GRIGNON
// Copyright (c) 1991-1999 Matra Datavision
// Copyright (c) 1999-2014 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.

#include <Standard_DomainError.hxx>
#include <IntSurf_LineOn2S.hxx>
#include <IntPatch_Point.hxx>


inline void IntPatch_WLine::AddVertex (const IntPatch_Point& thePnt,
                                       const Standard_Boolean theIsPrepend)
{
  if(theIsPrepend)
    svtx.Prepend(thePnt);
  else
    svtx.Append(thePnt);
}

inline void IntPatch_WLine::Replace (const Standard_Integer Index,
				     const IntPatch_Point& Pnt)
{
  svtx(Index) = Pnt;
}

inline void IntPatch_WLine::SetFirstPoint (const Standard_Integer IndFirst)
{
  fipt = Standard_True;
  indf = IndFirst;
}

inline void IntPatch_WLine::SetLastPoint (const Standard_Integer IndLast)
{
  lapt = Standard_True;
  indl = IndLast;
}

inline Standard_Integer IntPatch_WLine::NbPnts () const
{
  return curv->NbPoints();
}

inline const IntSurf_PntOn2S& IntPatch_WLine::Point (const Standard_Integer Index) const
{
  return curv->Value(Index);
}

inline Standard_Boolean IntPatch_WLine::HasFirstPoint () const
{
  return fipt;
}

inline Standard_Boolean IntPatch_WLine::HasLastPoint () const
{
  return lapt;
}

inline const IntPatch_Point& IntPatch_WLine::FirstPoint () const
{
  if (!fipt) {throw Standard_DomainError();}
  return svtx(indf);
}

inline const IntPatch_Point& IntPatch_WLine::LastPoint () const
{
  if (!lapt) {throw Standard_DomainError();}
  return svtx(indl);
}

inline const IntPatch_Point& IntPatch_WLine::FirstPoint (Standard_Integer& Indfirst) const
{
  if (!fipt) {throw Standard_DomainError();}
  Indfirst = indf;
  return svtx(indf);
}

inline const IntPatch_Point& IntPatch_WLine::LastPoint (Standard_Integer& Indlast) const
{
  if (!lapt) {throw Standard_DomainError();}
  Indlast = indl;
  return svtx(indl);
}

inline Standard_Integer IntPatch_WLine::NbVertex () const
{
  return svtx.Length();
}

inline const IntPatch_Point& IntPatch_WLine::Vertex (const Standard_Integer Index) const
{
  return svtx(Index);
}

inline IntPatch_Point& IntPatch_WLine::ChangeVertex (const Standard_Integer Index)
{
  return svtx(Index);
}

inline void IntPatch_WLine::ClearVertexes()
{
  svtx.Clear();
}

inline void IntPatch_WLine::RemoveVertex(const Standard_Integer theIndex)
{
  if((theIndex < 1) || (theIndex > NbVertex()))
    throw Standard_OutOfRange("Cannot delete not existing vertex");
  svtx.Remove(theIndex);
}

inline void IntPatch_WLine::InsertVertexBefore( const Standard_Integer theIndex,
                                                const IntPatch_Point& thePnt)
{
  const Standard_Integer aNbVertexes = NbVertex();
  Standard_Integer anIndex = Max(theIndex, 1);

  if(anIndex > aNbVertexes)
    svtx.Append(thePnt);
  else
    svtx.InsertBefore(theIndex, thePnt);
}
