<commit_before>#include "gui/clipping/ClippingCohenSutherland.h"

ClippingCohenSutherland::ClippingCohenSutherland(const double xvMin,
		const double xvMax, const double yvMin, const double yvMax) :
		Clipping(xvMin, xvMax, yvMin, yvMax) {
}

ClippingCohenSutherland::~ClippingCohenSutherland() {
}

QList<Ponto> ClippingCohenSutherland::clipReta(const Reta* const reta) const {
	QList<Ponto> pontos = reta->getPontos();
	Ponto p1 = pontos.at(0);
	Ponto p2 = pontos.at(1);

	// Region Code = Topo [0] Fundo [1] Direita [2] Esquerda [3]
	short rc1[4] = {0, 0, 0, 0};
	short rc2[4] = {0, 0, 0, 0};
	this->carregarRcPonto(&p1, rc1);
	this->carregarRcPonto(&p2, rc2);

	if ((rc1[0] * rc2[0] + rc1[1] * rc2[1] + rc1[2] * rc2[2] + rc1[3] * rc2[3])
			!= 0)
		return QList<Ponto>();

	if ((rc1[0] + rc2[0] + rc1[1] + rc2[1] + rc1[2] + rc2[2] + rc1[3] + rc2[3])
			== 0)
		return pontos;

	double coefAngular = reta->coeficienteAngular();

	switch (rc1[0] + rc1[1] + rc1[2] + rc1[3]) {
		case 1:
			if (!this->clippingBasico(rc1, &p1, coefAngular))
				return QList<Ponto>();
			break;
		case 2:
			if (!this->clippingComposto(rc1, &p1, coefAngular))
				return QList<Ponto>();
			break;
		default:
			break;
	}

	pontos.clear();
	pontos.append(p1);

	switch (rc2[0] + rc2[1] + rc2[2] + rc2[3]) {
		case 1:
			this->clippingBasico(rc2, &p2, coefAngular);
			pontos.append(p2);
			return pontos;
		case 2:
			this->clippingComposto(rc2, &p2, coefAngular);
			pontos.append(p2);
			return pontos;
		default:
			break;
	}

	return QList<Ponto>();
}

void ClippingCohenSutherland::carregarRcPonto(const Ponto* const p, short rc[4]) const {
	if (p->getY() > yvMax) {
		rc[0] = 1;
	} else if (p->getY() < yvMin) {
		rc[1] = 1;
	}
	if (p->getX() > xvMax) {<commit_msg>Clipping de Cohen-Sutherland corrigido.<commit_after>#include "gui/clipping/ClippingCohenSutherland.h"

ClippingCohenSutherland::ClippingCohenSutherland(const double xvMin,
		const double xvMax, const double yvMin, const double yvMax) :
		Clipping(xvMin, xvMax, yvMin, yvMax) {
}

ClippingCohenSutherland::~ClippingCohenSutherland() {
}

QList<Ponto> ClippingCohenSutherland::clipReta(const Reta* const reta) const {
	QList<Ponto> pontos = reta->getPontos();
	Ponto p1 = pontos.at(0);
	Ponto p2 = pontos.at(1);

	// Region Code = Topo [0] Fundo [1] Direita [2] Esquerda [3]
	short rc1[4] = {0, 0, 0, 0};
	short rc2[4] = {0, 0, 0, 0};
	this->carregarRcPonto(&p1, rc1);
	this->carregarRcPonto(&p2, rc2);

	if ((rc1[0] * rc2[0] + rc1[1] * rc2[1] + rc1[2] * rc2[2] + rc1[3] * rc2[3])
			!= 0)
		return QList<Ponto>();

	if ((rc1[0] + rc2[0] + rc1[1] + rc2[1] + rc1[2] + rc2[2] + rc1[3] + rc2[3])
			== 0)
		return pontos;

	double coefAngular = reta->coeficienteAngular();

	switch (rc1[0] + rc1[1] + rc1[2] + rc1[3]) {
		case 1:
			if (!this->clippingBasico(rc1, &p1, coefAngular))
				return QList<Ponto>();
			break;
		case 2:
			if (!this->clippingComposto(rc1, &p1, coefAngular))
				return QList<Ponto>();
			break;
		default:
			break;
	}

	switch (rc2[0] + rc2[1] + rc2[2] + rc2[3]) {
		case 1:
			this->clippingBasico(rc2, &p2, coefAngular);
			break;
		case 2:
			this->clippingComposto(rc2, &p2, coefAngular);
			break;
		default:
			break;
	}

	pontos.clear();
	pontos.append(p1);
	pontos.append(p2);
	return pontos;
}

void ClippingCohenSutherland::carregarRcPonto(const Ponto* const p, short rc[4]) const {
	if (p->getY() > yvMax) {
		rc[0] = 1;
	} else if (p->getY() < yvMin) {
		rc[1] = 1;
	}
	if (p->getX() > xvMax) {
{'fraction_non_alphanumeric': 0.1837496411139822, 'fraction_numerical': 0.053689348262991675, 'mean_word_length': 4.123529411764705, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654085', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1624, 'n_words': 322}