# Source: bemap-model/bemap-color.js

    /**
     * BeNomad BeMap JavaScript API - Color
     */

    /**
     * @classdesc
     * Base class for Color.
     * @public
     * @constructor
     * @param {int} red a number beetween 0 and 255 to define the red component of color.
     * @param {int} green a number beetween 0 and 255 to define the green component of color.
     * @param {int} blue a number beetween 0 and 255 to define the blue component of color.
     * @param {float} alpha a number between 0 and 1 to define the opacity (alpha) channel of color. 1 to full opacity and 0 to full transparency.
     */
    bemap.Color = function(red, green, blue, alpha) {

      /**
       * @type {int}
       * @protected
       */
      this.r = red ? bemap.Color.prototype._check(red) : 0;

      /**
       * @type {int}
       * @protected
       */
      this.g = green ? bemap.Color.prototype._check(green) : 0;

      /**
       * @type {int}
       * @protected
       */
      this.b = blue ? bemap.Color.prototype._check(blue) : 0;

      /**
       * @type {int}
       * @protected
       */
      this.a = alpha ? alpha : 1;
    };

    bemap.Color.prototype._check = function(n) {
      return Math.min(Math.round(n), 255);
    };

    bemap.Color.prototype._toHexString = function(n) {
      var hex = Number(n).toString(16);
      if (hex.length < 2) {
        hex = "0" + hex;
      }
      return hex;
    };

    /**
     * Return an hex string composed by red, green and blue components of color.
     * @public
     * @return {array} Return an hex string composed by red, green and blue components of color.
     */
    bemap.Color.prototype.getHex = function() {
      return '#' + this._toHexString(this.r) + this._toHexString(this.g) + this._toHexString(this.b);
    };

    /**
     * Return an array composed by red, green and blue components of color.
     * @public
     * @return {array} Return an array composed by red, green and blue components of color.
     */
    bemap.Color.prototype.getRgbArray = function() {
      return [this.r, this.g, this.b];
    };

    /**
     * Return an array composed by red, green, blue and alpha components of color.
     * @public
     * @return {array} Return an array composed by red, green, blue and alpha components of color.
     */
    bemap.Color.prototype.getRgbaArray = function() {
      return [this.r, this.g, this.b, this.a];
    };

    /**
     * Return the red component of color.
     * @public
     * @return {int} Return the red component of color.
     */
    bemap.Color.prototype.getRed = function() {
      return this.r;
    };

    /**
     * Set the red component of color, a number beetween 0 and 255.
     * @public
     * @param {int} red a number beetween 0 and 255 to define the red component of color.
     * @return {bemap.Color} Return this.
     */
    bemap.Color.prototype.setRed = function(red) {
      this.r = bemap.Color.prototype._check(red);
      return this;
    };

    /**
     * Return the green component of color.
     * @public
     * @return {int} Return the green component of color.
     */
    bemap.Color.prototype.getGreen = function() {
      return this.g;
    };

    /**
     * Set the green component of color, a number beetween 0 and 255.
     * @public
     * @param {int} green a number beetween 0 and 255 to define the green component of color.
     * @return {bemap.Color} Return this.
     */
    bemap.Color.prototype.setGreen = function(green) {
      this.g = bemap.Color.prototype._check(green);
      return this;
    };

    /**
     * Return the blue component of color.
     * @public
     * @return {int} Return the blue component of color.
     */
    bemap.Color.prototype.getBlue = function() {
      return this.b;
    };

    /**
     * Set the blue component of color, a number beetween 0 and 255.
     * @public
     * @param {int} blue a number beetween 0 and 255 to define the blue component of color.
     * @return {bemap.Color} Return this.
     */
    bemap.Color.prototype.setBlue = function(blue) {
      this.b = bemap.Color.prototype._check(blue);
      return this;
    };

    /**
     * Return the opaticy (alpha) channel of color.
     * @public
     * @return {int} Return the alpha channel of color.
     */
    bemap.Color.prototype.getAlpha = function() {
      return this.a;
    };

    /**
     * Set the opacity (alpha) channel of color, a number beetween 0 and 255.
     * @public
     * @param {int} alpha a number beetween 0 and 1 to define the opacity (alpha) channel of color.
     * @return {bemap.Color} Return this.
     */
    bemap.Color.prototype.setAlpha = function(alpha) {
      this.a = alpha;
      return this;
    };