'use strict';
const Rac = require('../Rac');
const utils = require('../util/utils');
/**
* Container of a sequence of drawable objects that can be drawn together.
*
* Used by `[P5Drawer]{@link Rac.P5Drawer}` to perform specific vertex
* operations with drawables to draw complex shapes.
*
* @class
* @alias Rac.Composite
*/
function Composite(rac, sequence = []) {
utils.assertExists(rac, sequence);
this.rac = rac;
this.sequence = sequence;
};
module.exports = Composite;
Composite.prototype.isNotEmpty = function() {
return this.sequence.length != 0;
};
Composite.prototype.add = function(element) {
if (element instanceof Array) {
element.forEach(item => this.sequence.push(item));
return
}
this.sequence.push(element);
};
Composite.prototype.reverse = function() {
let reversed = this.sequence.map(item => item.reverse())
.reverse();
return new Composite(this.rac, reversed);
};