### IGCurve2D

  IGCurve2D is a non-uniform rational B-spline (NURB) of arbitrary degree. The IGCurve2D class provides a non-uniform rational B-spline (NURB) of arbitrary degree. This representation gives exact conic curves, direct control over the continuity of the curve, and no limitations on the number control points. A number of tools are provided for defining and manipulating curves. Constructors are available to make exact arcs, simple beziers(like in MacDraw or Illustrator) or curves. Other methods refine, evaluate and modify the curve. In the current implementation, IGCurve2D should not be subclassed, except for trivial subclasses to add constructor methods(it doesn't use virtual methods).

  Note that currently curves of order 7 or higher are not supported. Also consider that IRawArray does not check whether allocation is successful. Before construction, one should check if there is enough memory and use a reasonable size.

### IGCurve2D - Member Functions and Data by Group

### Constructors & Destructor

Use the constructors and destructor in this group to create and destroy objects of class IGCurve2D.

~IGCurve2D

      public:
      virtual ~IGCurve2D()

  Destroys the IGCurve2D object.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

IGCurve2D

  Overload 1

      public:
      IGCurve2D( const IGPoint2D& p0,
                 const IGPoint2D& p1,
                 const IGPoint2D& p2 )

  Constructor for a three point quadratic Bezier.

  p0
    The first control point.
  p1
    The second control point.
  p2
    The third control point.

Exception

  | A parameter assertion fails if the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 2

      public:
      IGCurve2D(const IGLine2D& line)

  Constructor for a curve from the specified IGLine2D.

  line
    The line to be converted into a curve.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 3

      public:
      IGCurve2D(const IGCurve2D& curve)

  Copying constructor.

  curve
    The curve to be copied.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 4

      public:
      IGCurve2D( unsigned long order,
                 const IGRPoint2DArray& points )

  Constructor for a general NURB (Non-Uniform Rational B-Spline) with the control polygon set to the second argument.

  order
    The order of the new curve.
  points
    The specified control points.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 5

      public:
      IGCurve2D( unsigned long order,
                 const IGRPoint2DArray& points,
                 const IRawArray < GParametric >& knots )

  Constructor for a general NURB (Non-Uniform Rational B-Spline).

  order
    The order of the new curve.
  points
    The specified control points.
  knots
    The specified knot vector.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 6

      public:
      IGCurve2D(unsigned long order, unsigned long numberPoints)

  Constructor for general NURB curve. If knots is not specified a "pinned" knot vector is created. If controlPoints (and knots) are specified, they are copied in. Assertions fail if number of points is less than the order, or if the order is less than two. If the points are not given, the number specified in numberPoints are created, and all are set to the origin (w=1).

  order
    The order of the new curve.
  numberPoints
    The number of control points.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 7

      public:
      IGCurve2D( unsigned long order,
                 unsigned long numberPoints,
                 const IRawArray < GParametric >& knots )

  Constructor for a general NURB (Non-Uniform Rational B-Spline).

  order
    The order of the new curve.
  numberPoints
    The number of control points.
  knots
    The specified knot vector.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 8

      public:
      IGCurve2D( const IGPoint2D& p0,
                 const IGPoint2D& p1,
                 const IGPoint2D& p2,
                 const IGPoint2D& p3 )

  Constructor for a simple four point cubic Bezier.

  p0
    The first control point.
  p1
    The second control point.
  p2
    The third control point.
  p3
    The forth control point.

Exception

  | A parameter assertion fails if the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 9

      public:
      IGCurve2D(const IGPolyline2D& polyline)

  Constructor for a curve from the specified IGPolyline2D.

  polyline
    The polyline to be converted into a curve.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 10

      public:
      IGCurve2D( const IGEllipse2D& e,
                 GDegrees angle1,
                 GDegrees angle2 )

  Constructor for an elliptical arc inscribed within the specified ellipse. Sets the curve to an elliptical arc from angle1 to angle2. Now, the Arc always goes "counterclockwise" (because that's how sin's and cos's go), BUT, because the coordinate system used is by default "upsidedown" from the mathematical one, the arcs go clockwise.

  e
    The ellipse that the arc is to be inscribed within.
  angle1
    The first angle.
  angle2
    The first angle.

Exception

  | A parameter assertion fails if number of points is less than the order, or the order is less than 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 11

      public:
      IGCurve2D()

  Default constructor. Creates an empty curve (0 points and order 0). Will not render. The only operators allowed on empty curves are assignment and stream in.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Assignment Operator

Use this operator to assign the given IGCurve2D object to the target one.

operator =

      public:
      IGCurve2D& operator =(const IGCurve2D& Src)

  Assignment operator.

  Src
    The curve to be copied.

Return
  A reference to the lef-hand side object.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Getting and Setting the Curve's Points

Use the functions in this group to set the curve's points, set its control points as a polyline, transform its control points by the specified matrix, get the point on the IGCurve2D at the specified parametric value, and reverse the order of a curve's points so the parameterization runs the opposite direction.

controlPolyline

      public:
      void controlPolyline(IGPolyline2D& polyline) const

  Returns, in its argument, the set of control points as a polyline.

  polyline
    The curve's control points, returned by reference.

Exception

  | An assertion fails if the curve is empty (uninitialized).

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

evaluate

  Overload 1
  Returns the point on the IGCurve2D at the specified parametric value. Computes the tangent and second derivative at this point.

      public:
      IGPoint2D
        evaluate( GParametric u,
                  IGPoint2D& tangent,
                  IGPoint2D& deriv2 ) const

  u
    The parametric value at which to evaluate the curve. GetMinParameter<= u <=GetMaxParameter.
  tangent
    A vector representing the tangent of the curve at this point; computed by this function.
  derive2
    The second derivative of the curve at this point; computed by this function.

Return
  The point on the curve that corresponds to the specified parametric value.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 2
  Returns the point on the IGCurve2D at the specified parametric value. Computes the tangent, second derivative, and curvature at this point.

      public:
      IGPoint2D
        evaluate( GParametric u,
                  IGPoint2D& tangent,
                  IGPoint2D& deriv2,
                  GCoordinate& curvature ) const

  u
    The parametric value at which to evaluate the curve. GetMinParameter<= u <=GetMaxParameter.
  tangent
    A vector representing the tangent of the curve at this point; computed by this function.
  derive2
    The second derivative of the curve at this point; computed by this function.
  curvature
    The curvature at this point; computed by this function.

Return
  The point on the curve that corresponds to the specified parametric value.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 3
  Returns the point on the IGCurve2D at the specified parametric value.

      public:
      IGPoint2D evaluate(GParametric u) const

  u
    The parametric value at which to evaluate the curve. GetMinParameter<= u <=GetMaxParameter.

Return
  The point on the curve that corresponds to the specified parametric value.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

  Overload 4
  Returns the point on the IGCurve2D at the specified parametric value, and computes the tangent at this point.

      public:
      IGPoint2D evaluate(GParametric u, IGPoint2D& tangent) const

  u
    The parametric value at which to evaluate the curve. GetMinParameter<= u <=GetMaxParameter.
  tangent
    A vector representing the tangent of the curve at this point; computed by this function.

Return
  The point on the curve that corresponds to the specified parametric value.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

evaluateW

      public:
      IGRPoint2D evaluateW(GParametric u) const

  Returns the point (as a IGRPoint2D) on the IGCurve2D at the specified parametric value.

  u
    The parametric value at which to evaluate the curve. GetMinParameter<= u <=GetMaxParameter.

Return
  The IGRPoint2D on the curve at the parametric location.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

reverseDirection

      public:
      void reverseDirection()

  Reverses the order of a curve's points so the parameterization runs the opposite direction. The geometric shape is unchanged.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

setOrder

      public:
      void setOrder(unsigned long order)

  Change order of curve. This function changes the shape, but leaves the number of points intact.

  order
    The new order of the curve.

Exception

  | An assertion fails if the curve is empty (uninitialized).

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

setPoint

      public:
      void setPoint(unsigned long i, const IGRPoint2D& p)

  Replaces this curve's control point at the specified index with the specified point.

  i
    The index (into the array of control points) of the point to be replaced.
  p
    The new control point.

Exception

  | An assertion fails if the curve is empty (uninitialized).

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

setPoints

      public:
      void
        setPoints( const IRawArray < IGRPoint2D >& controlPoints )

  Copies points in from your heap block. (The heap block must have same number of points).

  controlPoints
    The new set of control points. There must be at least two points in the array.

Exception

  | An assertion fails if the number of points passed in is less than or equal to 2.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

transformBy

      public:
      void transformBy(const IGrafMatrix& mat)

  Transform all of the curve's control points by the specified matrix.

  mat
    The transformation matrix by which the curve's points are multiplied.

Exception

  | An assertion fails if the curve is empty (uninitialized).

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Inserting, Setting, and Moving Knots

Use the functions in this group to insert, set, and move the curve's knots.

insertKnot

      public:
      void insertKnot(GParametric u)

  Inserts a single new knot (and the corresponding control point) at the specified parametric location.

  u
    The parametric value of the point at which the knot is inserted. It must be greater than the parametric value of the curve's start point and less than the parametric value of the end point.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

moveKnot

      public:
      void moveKnot(unsigned long index, GParametric u)

  Moves the knot at index i to u. May re-sort knots to ensure knot(i+1)>=knot(i) for all i.

  index
    The index (into the knot vector) of the knot to be moved.
  u
    The parametric location to which the knot is moved.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

setKnots

      public:
      void setKnots(const IRawArray < GParametric >& knots)

  Resets this curve's knot vector to the specified array. The data is copied into the curve, and must have the same number of knots as the curve's existing knot vector. No refinement or consistency checking is performed on this knot vector.

  knots
    The array to be copied into the knot vector.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

setKnotScheme

      public:
      void setKnotScheme(EndConditions theType = kPinned)

  Sets the knot vector to one of three standard schemes (pinned, floating, or Bezier), without any refinement.

  theType = kPinned
    The knot scheme.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Modifying the Curve

Use the functions in this group to change the shape or position of the curve, or extend it.

dragPosition

      public:
      void
        dragPosition( GParametric u,
                      const IGPoint2D& toPoint,
                      GParametric segmentMinimum = 0.2,
                      GParametric segmentMaximum = 0.8 )

  Changes the curve shape so that at parameter u, it goes through ToPoint.

  u
    The parametric position to be dragged to the new location.
  toPoint
    The new location.
  segmentMinimum
    The parametric value below which a point on the curve will not be moved. The default value is 0.2.
  segmentMaximum
    The parametric value above which a point on the curve will not be moved. The default value is 0.2.

Exception

  | An assertion fails if the curve is empty (uninitialized).

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

dragTangent

      public:
      void
        dragTangent( GParametric u,
                     const IGPoint2D& toTangent,
                     GParametric segmentMinimum = 0.2,
                     GParametric segmentMaximum = 0.8 )

  Change curve shape so that at parameter u, it has the specified tangent. Like dragCurve, but instead modifies the -tangent- at the u parameter given. i.e., Adobe rocker arms you can put anyplace on the curve.

  u
    The parametric position to be dragged to the new location.
  toTangent
    The new tangent.
  segmentMinimum
    The parametric value below which a point on the curve will not be moved. The default value is 0.2.
  segmentMaximum
    The parametric value above which a point on the curve will not be moved. The default value is 0.2.

Exception

  | An assertion fails if the curve is empty (uninitialized).

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

makeCompatible

      public:
      static void
        makeCompatible( IGCurve2D& curve1,
                        IGCurve2D& curve2 )

  Modifies both curves to have the same order, the same number of points, and the same knot vector, without changing the shape of either curve. This is accomplished by raising the order and refining the knot vector as necessary.

  curve1
    The first curve to be made compatible.
  curve2
    The second curve to be made compatible.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

prAppendCurve

      protected:
      void
        prAppendCurve( IBaseCurve < IGRPoint2D,
                       IGPoint2D >& crv,
                       bool glue )

  Prepends the given curve at the beginning of the current curve. Glue parameter determines whether joining beginning and end points should be merged(glue==true) or left as double control points.

  crv
    The curve to be joined to this one.
  glue
    Determines whether joining beginning and endpoints should be merged (glue==true) or left as double control points. The default value is TRUE.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Obtaining Information About the Curve

Use the functions in this group to determine if the curve intersects the given rectangle and to get the bounds of its control points.

bounds

      public:
      virtual IGRect2D bounds() const

  Returns the bounds of the curve's control points. Due to the convex hull property, the curve is always contained within its control points. Note this bounds is not cached, but recomputed with every call.

Return
  The rectangle that bounds the curve.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

intersects

      public:
      bool intersects(const IGRect2D& g) const

  Returns true if the curve intersects the rectangle. NOTE: This is currently implemented by discretizing the curve in something resembling screen space. In the future, the implementation will be changed to a truly device independant one.

  g
    The rectangle.

Return
  True if the curve intersects the rectangle.

Exception

  | An assertion fails if the curve is empty (uninitialized).

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### Streaming the IGCurve2D Object In and Out

Use the functions in this group to read the IGCurve2D object in from the specified stream or write it out to it.

operator <<=

      public:
      IDataStream& operator <<=(IDataStream&)

  This operator reads in the IGCurve object.

  IDataStream
    A reference to the stream to be used to read in the object.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

operator >>=

      public:
      IDataStream& operator >>=(IDataStream&) const

  This operator writes the object out to the stream.

  IDataStream
    The stream that the object is written out to.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

readFromStream

      public:
      void readFromStream(IDataStream& toWhere)

  Reading the IGCurve2D object in from the specified stream.

  fromWhere
    The stream used to read in the object.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

writeToStream

      public:
      void writeToStream(IDataStream& toWhere) const

  Writes the IGCurve2D object out to the specified stream.

  toWhere
    The stream the object is written out to.

Supported Platforms

  Windows | OS/2 | AIX
  Yes | Yes | Yes

### IGCurve2D - Inherited Member Functions and Data

#### Inherited Public Functions

  IBaseCurve

  -     virtual ~IBaseCurve()

  -     void
          approximateArcLengthReparameterizationCurve( IGCurve2D& reparamCurve,
                                                       unsigned long maxPts = 0,
                                                       GCoordinate tolerance = 0.01 )

  -     void
          approximateLowerOrder( unsigned long newOrder,
                                 GCoordinate tolerance = 0.2 )

  -     GParametric
          approximateParameterFromArcLength( GCoordinate length,
                                             GCoordinate tolerance = 1.0e - 5 ) const

  -     GCoordinate arcLength() const

  -     GCoordinate
          arcLength( GParametric uFrom,
                     GParametric uTo ) const

  -     void
          concatenate( const IBaseCurve < RPointType,
                       PointType >& p,
                       bool glue = true )

  -     void
          dragPosition( GParametric u,
                        const PointType& toPoint,
                        GParametric segmentMinimum = 0.2,
                        GParametric segmentMaximum = 0.8 )

  -     void
          dragTangent( GParametric u,
                       const PointType& toTangent,
                       GParametric segmentMinimum = 0.2,
                       GParametric segmentMaximum = 0.8 )

  -     PointType evaluate(GParametric u) const

  -     PointType evaluate(GParametric u, PointType& tangent) const

  -     PointType
          evaluate( GParametric u,
                    PointType& tangent,
                    PointType& deriv2 ) const

  -     RPointType evaluateW(GParametric u) const

  -     IBaseCurve(unsigned long order, unsigned long numberPoints)

  -     IBaseCurve( unsigned long order,
                    unsigned long numberPoints,
                    const IRawArray < GParametric >& knots )

  -     IBaseCurve( const PointType& p0,
                    const PointType& p1,
                    const PointType& p2 )

  -     IBaseCurve( const PointType& p0,
                    const PointType& p1,
                    const PointType& p2,
                    const PointType& p3 )

  -     IBaseCurve( unsigned long order,
                    const IRawArray < RPointType >& points )

  -     IBaseCurve()

  -     IBaseCurve( unsigned long order,
                    const IRawArray < RPointType >& points,
                    const IRawArray < GParametric >& knots )

  -     IBaseCurve( const IBaseCurve < RPointType,
                    PointType >& curve )

  -     bool isBezier() const

  -     bool isConsistent()

  -     bool isEmpty() const

  -     bool isPinned() const

  -     GParametric knot(unsigned long i) const

  -     void knots(IRawArray < GParametric >& knots) const

  -     static void
          makeCompatible( IBaseCurve < RPointType,
                          PointType >& curve1,
                          IBaseCurve < RPointType,
                          PointType >& curve2 )

  -     void makeDiscontinuity(GParametric u, EDiscontinuity cont)

  -     GParametric maxParameter() const

  -     GParametric minParameter() const

  -     GParametric nearestParametric(const PointType& test) const

  -     unsigned long
          nextDiscontinuity( unsigned long startIndex,
                             unsigned long discontinuity = 0 ) const

  -     unsigned long numberOfKnots() const

  -     unsigned long numberOfPoints() const

  -     bool
          operator !=( const IBaseCurve < RPointType,
                       PointType >& ) const

  -     IBaseCurve < RPointType , PointType >&
          operator =( const IBaseCurve < RPointType,
                      PointType >& Crv )

  -     bool
          operator ==( const IBaseCurve < RPointType,
                       PointType >& ) const

  -     unsigned long order() const

  -     RPointType point(unsigned long i) const

  -     void points(IRawArray < RPointType >& pts) const

  -     void raiseOrder(unsigned long newOrder)

  -     void refine(const IRawArray < GParametric >& newKnots)

  -     void refineToBeziers()

  -     void refineToPinned()

  -     void refineUniform()

  -     void
          sectionOfCurve( GParametric from,
                          GParametric to,
                          IBaseCurve < RPointType,
                          PointType >& section ) const

  -     void setPoint(unsigned long i, const RPointType& p)

  -     void
          setPoints( const IRawArray < RPointType >& controlPoints )

#### Inherited Public Data

  - None

#### Inherited Protected Functions

  IBaseCurve

  -     PointType
          evaluate( GParametric u,
                    unsigned long delta ) const

  -     void incrementOrder()

  -     void
          prAppendCurve( IBaseCurve < RPointType,
                         PointType >& crv,
                         bool glue )

  -     static void
          reduceOneDegree( IRawArray < RPointType >& pts,
                           unsigned long order,
                           unsigned long numPts,
                           GCoordinate tolerance,
                           long* discons,
                           unsigned long numDiscons,
                           unsigned long* newPts )

#### Inherited Protected Data

  - None