src/ccstruct/coutln.cpp
int16_t C_OUTLINE::winding_number(ICOORD point) const {
  int16_t stepindex; // index to cstep
  int16_t count;     // winding count
  ICOORD vec;        // to current point
  ICOORD stepvec;    // step vector
  int32_t cross;     // cross product

  vec = start - point; // vector to it
  count = 0;
  for (stepindex = 0; stepindex < stepcount; stepindex++) {
    stepvec = step(stepindex); // get the step
                               // crossing the line
    if (vec.y() <= 0 && vec.y() + stepvec.y() > 0) {
      cross = vec * stepvec; // cross product
      if (cross > 0) {
        count++; // crossing right half
      } else if (cross == 0) {
        return INTERSECTING; // going through point
      }
    } else if (vec.y() > 0 && vec.y() + stepvec.y() <= 0) {
      cross = vec * stepvec;
      if (cross < 0) {
        count--; // crossing back
      } else if (cross == 0) {
        return INTERSECTING; // illegal
      }
    }
    vec += stepvec; // sum vectors
  }
  return count; // winding number
}
/**
 * @name C_OUTLINE::winding_number
 *
 * @return the winding number of the outline around the given point.
 * @param point point to wind around
 */
@name C_OUTLINE::winding_number
@return the winding number of the outline around the given point.
@param point point to wind around
@name C_OUTLINE :: winding_number @return the winding number of the outline around the given point . @param point point to wind around
int16_t C_OUTLINE::winding_number(ICOORD point) const {
  int16_t stepindex; 
  int16_t count;     
  ICOORD vec;        
  ICOORD stepvec;    
  int32_t cross;     
  vec = start - point; 
  count = 0;
  for (stepindex = 0; stepindex < stepcount; stepindex++) {
    stepvec = step(stepindex); 
    if (vec.y() <= 0 && vec.y() + stepvec.y() > 0) {
      cross = vec * stepvec; 
      if (cross > 0) {
        count++; 
      } else if (cross == 0) {
        return INTERSECTING; 
      }
    } else if (vec.y() > 0 && vec.y() + stepvec.y() <= 0) {
      cross = vec * stepvec;
      if (cross < 0) {
        count--; 
      } else if (cross == 0) {
        return INTERSECTING; 
      }
    }
    vec += stepvec; 
  }
  return count; 
}
int16_t C_OUTLINE :: winding_number ( ICOORD point ) const { int16_t stepindex ; int16_t count ; ICOORD vec ; ICOORD stepvec ; int32_t cross ; vec = start - point ; count = 0 ; for ( stepindex = 0 ; stepindex < stepcount ; stepindex ++ ) { stepvec = step ( stepindex ) ; if ( vec . y ( ) <= 0 && vec . y ( ) + stepvec . y ( ) > 0 ) { cross = vec * stepvec ; if ( cross > 0 ) { count ++ ; } else if ( cross == 0 ) { return INTERSECTING ; } } else if ( vec . y ( ) > 0 && vec . y ( ) + stepvec . y ( ) <= 0 ) { cross = vec * stepvec ; if ( cross < 0 ) { count -- ; } else if ( cross == 0 ) { return INTERSECTING ; } } vec += stepvec ; } return count ; }
@name C_OUTLINE::winding_number
 @return the winding number of the outline around the given point.
@name C_OUTLINE :: winding_number @return the winding number of the outline around the given point .
// index to cstep // winding count // to current point // step vector // cross product // vector to it // get the step // crossing the line // cross product // crossing right half // going through point // crossing back // illegal // sum vectors // winding number