#include "brick_emits.h"


bool BrickEmitLinear::tick_body(double time) {
	outputs[0] = time * inputs[Slope] + inputs[StartValue];
	return true;
}


bool BrickEmitSin::tick_body(double time) {
	outputs[0] = inputs[Amplitude] * sin(inputs[Frequency] * time * (M_PI + M_PI) + inputs[PhaseShift]);
	//cout << time << "\t: " << outputs[0] << endl;
	return true;
}


bool BrickEmitDelta::tick_body(double time) {
	outputs[0] = (pt < inputs[Time] && time >= inputs[Time]) ? 1. / dt : 0.;
	//cout << time << "\t: " << outputs[0] << endl;
	return true;
}


bool BrickEmitStep::tick_body(double time) {
	if (time == inputs[Time]) outputs[0] = (inputs[StartValue] + inputs[FinishValue]) / 2.;
	else outputs[0] = (time > inputs[Time]) ? inputs[FinishValue] : inputs[StartValue];
	//cout << time << "\t: " << outputs[0] << endl;
	return true;
}


bool BrickEmitPulse::tick_body(double time) {
	outputs[0] = time < inputs[StartDelay] ? 0. : (residue(time - inputs[StartDelay], inputs[Period]) <= inputs[Duration]) ? inputs[Amplitude] : 0.;
	//cout << time << "\t: " << outputs[0] << endl;
	return true;
}
