All files / scripts Rectangle.js

77.78% Statements 14/18
90% Branches 9/10
100% Functions 4/4
73.33% Lines 11/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                  1x 1x                           96x 48x 48x 48x 48x               1x               1x                 1x                 1x
/**
 * @author Antonio Raúl Guijarro Contreras <alu0101100494@ull.edu.es>
 * @file Declaración de la clase Rectangle. hereda de Shape y simboliza la forma de un rectángulo
 * @copyright Antonio Raúl Guijarro Contreras 2020
 * @since 14.03.2020
 */
 
'use stric'
 
import Shape from "./Shape.js";
import Point from "./Point.js";
 
/** 
 * @extends Shape
 * hereda de de Shape y simboliza la forma de un rectángulo dentro
 * de un canvas.
*/
class Rectangle extends Shape {
  /**
   * Constructor de Rectangle
   * @param {Point} start Punto del triángulo.  Por defecto está asignado a (0, 0)
   * @param {number} width Punto del triángulo Por defecto está asignado a 0
   * @param {number} height Punto del triángulo Por defecto está asignado a 0
   */
  constructor(start = new Point(0, 0), width = 0, height = 0) {
    super();
    this.start = start;
    this.width = width;
    this.height = height;
  }
 
  /**
   * Retorna el área del rectángulo
   * @return {Number} Área del rectángulo
   */
  area() {
    return this.width * this.height;
  }
 
  /**
   * Retorna el perímetro del rectángulo
   * @return {Number} Perímetro del rectángulo
   */
  perimeter() {
    return this.width + this.height
  }
 
  /* istanbul ignore next   */
  /**
   * Se encarga de dibujar la figura que representa la clase
   * @param {Context} ctx Contexto del canvas, preferiblemente '2d'
   */
  draw(ctx) {
    Iif (ctx != null) {
      this.baseDraw(ctx);
      ctx.rect(this.start.x, this.start.y, this.width, this.height);
      ctx.stroke();
      ctx.fill();
    }
  }
}
 
export default Rectangle;