// file: $USFS/class/image_analysis/v6.0/imaga_seg_2.cc
//

// isip include files
//
#include "image_analysis.h"
#include <link_list.h>
#include <polygon.h>

#include "image_analysis_constants.h"

// method: is_inside_cc
//
// arguments:
//  int_4 x_val: (input) x coordinate for the pixel
//  int_4 y_val: (input) y coordinate for the pixel
//
// return:
//  a logical_1 value indicating if the given pixel is inside the prescribed
// region or not
//
// this method traverses the linked list of polygon_list_d to check if the
// given pixel falls into the prescribed region or not
//
logical_1 Image_analysis::is_inside_cc(int_4 x_val_a, int_4 y_val_a) {

  // declare local variables
  //
  logical_1 inside = ISIP_FALSE;
  Link_node* curr_node = (Link_node*)NULL;
  Link_node* next_node = (Link_node*)NULL;
  Polygon* polygon = (Polygon*)NULL;

  // loop over the linked list
  //
  for (curr_node = polygon_list_d->get_head_cc();
       curr_node != (Link_node*)NULL; curr_node = next_node) {
    next_node = curr_node->get_next_cc();
    polygon = (Polygon*)(curr_node->get_item_cc());
    if (polygon->is_inside_cc(x_val_a, y_val_a) == ISIP_TRUE) {
      inside = ISIP_TRUE;
      return inside;
    }
  }
    
  // exit gracefully
  //
  return inside;
}
