/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef RGBTriplet_h
#define RGBTriplet_h

#include <math.h>
#include <stdio.h>

struct RGBTriplet {
  RGBTriplet(void) { red = green = blue = 0; }

  RGBTriplet(unsigned char r,
	     unsigned char g,
	     unsigned char b) {
    red = r;
    green = g;
    blue = b;
  }

  bool operator==(RGBTriplet &other) {
    return red == other.red &&
      green == other.green &&
      blue == other.blue;
  }

  double distance(RGBTriplet &other) {
    return sqrt((red - other.red)*(red - other.red) +
		(green - other.green)*(green - other.green) +
		(blue - other.blue)*(blue - other.blue));
  }

  void write(FILE *outfile) {
    fwrite(&red, 1, 1, outfile);
    fwrite(&green, 1, 1, outfile);
    fwrite(&blue, 1, 1, outfile);
  }

  bool read(FILE *infile) {
    int count = 0;

    count += fread(&red, 1, 1, infile);
    count += fread(&green, 1, 1, infile);
    count += fread(&blue, 1, 1, infile);

    return count==3;
  }


  unsigned char red;
  unsigned char green;
  unsigned char blue;
};

#endif
