<commit_before>#include "connections/LineConnector.h"

#include <QBrush>
#include <QGraphicsWidget>
#include <QPainter>
#include <QPen>

namespace i6engine {
namespace particleEditor {
namespace connections {

	LineConnector::LineConnector(QGraphicsWidget * first, QGraphicsWidget * second, QColor colour, Qt::PenStyle lineStyle) : _first(first), _second(second), _colour(colour), _lineStyle(lineStyle), _path() {
	}

	void LineConnector::paint(QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *) {
		static int xOffsetMin = 24;

		QPen pen(QBrush(_colour), _lineStyle);
		pen.setWidth(2);
		painter->setPen(pen);

		QPoint points[4];
		int x1 = _first->pos().x();
		int y1 = _first->pos().y();
		int x2 = _second->pos().x();
		int y2 = _second->pos().y();
		int width1 = _first->size().width();
		int height1 = _first->size().height();
		int width2 = _second->size().width();
		int height2 = _second->size().height();
		int x3, y3;
		int x4, y4;

		y1 = y1 + 0.5 * height1;
		y2 = y2 + 0.5 * height2;
		y3 = y1;
		y4 = y2;

		// Determine widest rectangle
		if (width2 > width1) {
			// Swap
			x1 += x2; // = x1 + x2
			x2 = x1 - x2; // = x1 + x2 - x2 = x1
			x1 -= x2; // = x1 + x2 - x1 = x2

			y1 += y2;
			y2 = y1 - y2;
			y1 -= y2;

			y3 += y4;
			y4 = y3 - y4;
			y3 -= y4;

			width1 += width2;
			width2 = width1 - width2;
			width1 -= width2;

			height1 += height2;
			height2 = height1 - height2;
			height1 -= height2;
		}

		// Calculate the 4 control points
		int xOffset = 0.25 * std::abs(x1 - x2);
		xOffset = std::max(xOffset, xOffsetMin);
		if (x1 + width1 > x2 + width2) {
			x3 = x1 - xOffset;
			x4 = x2 - xOffset;
			if (x1 > x2 + width2) {
				x2 += width2;
				x4 = x2 + xOffset;
			}
		} else {
			x1 += width1;
			x3 = x1 + xOffset;
			x4 = x2 - xOffset;
			if (x1 > x2) {
				x2 += width2;
				x4 = x2 + xOffset;
			}
		}

		_path = QPainterPath(QPoint(x1, y1));
		_path.cubicTo(QPoint(x3, y3), QPoint(x4, y4), QPoint(x2, y2));
		painter->drawPath(_path);
	}

	QRectF LineConnector::boundingRect() const {
		return _path.boundingRect();
	}

} /* namespace connections */
} /* namespace particleEditor */
} /* namespace i6engine */
<commit_msg>ISIXE-1749 reverted part of last commit to fix crash, but now lines are removed sometimes<commit_after>#include "connections/LineConnector.h"

#include <QBrush>
#include <QGraphicsWidget>
#include <QPainter>
#include <QPen>

namespace i6engine {
namespace particleEditor {
namespace connections {

	LineConnector::LineConnector(QGraphicsWidget * first, QGraphicsWidget * second, QColor colour, Qt::PenStyle lineStyle) : _first(first), _second(second), _colour(colour), _lineStyle(lineStyle), _path() {
	}

	void LineConnector::paint(QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *) {
		static int xOffsetMin = 24;

		QPen pen(QBrush(_colour), _lineStyle);
		pen.setWidth(2);
		painter->setPen(pen);

		QPoint points[4];
		int x1 = _first->pos().x();
		int y1 = _first->pos().y();
		int x2 = _second->pos().x();
		int y2 = _second->pos().y();
		int width1 = _first->size().width();
		int height1 = _first->size().height();
		int width2 = _second->size().width();
		int height2 = _second->size().height();
		int x3, y3;
		int x4, y4;

		y1 = y1 + 0.5 * height1;
		y2 = y2 + 0.5 * height2;
		y3 = y1;
		y4 = y2;

		// Determine widest rectangle
		if (width2 > width1) {
			// Swap
			x1 += x2; // = x1 + x2
			x2 = x1 - x2; // = x1 + x2 - x2 = x1
			x1 -= x2; // = x1 + x2 - x1 = x2

			y1 += y2;
			y2 = y1 - y2;
			y1 -= y2;

			y3 += y4;
			y4 = y3 - y4;
			y3 -= y4;

			width1 += width2;
			width2 = width1 - width2;
			width1 -= width2;

			height1 += height2;
			height2 = height1 - height2;
			height1 -= height2;
		}

		// Calculate the 4 control points
		int xOffset = 0.25 * std::abs(x1 - x2);
		xOffset = std::max(xOffset, xOffsetMin);
		if (x1 + width1 > x2 + width2) {
			x3 = x1 - xOffset;
			x4 = x2 - xOffset;
			if (x1 > x2 + width2) {
				x2 += width2;
				x4 = x2 + xOffset;
			}
		} else {
			x1 += width1;
			x3 = x1 + xOffset;
			x4 = x2 - xOffset;
			if (x1 > x2) {
				x2 += width2;
				x4 = x2 + xOffset;
			}
		}

		_path = QPainterPath(QPoint(x1, y1));
		_path.cubicTo(QPoint(x3, y3), QPoint(x4, y4), QPoint(x2, y2));
		painter->drawPath(_path);
		prepareGeometryChange();
	}

	QRectF LineConnector::boundingRect() const {
		return QRectF();
	}

} /* namespace connections */
} /* namespace particleEditor */
} /* namespace i6engine */

{'fraction_non_alphanumeric': 0.1617745910822317, 'fraction_numerical': 0.05467174546269325, 'mean_word_length': 2.9089316987740808, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, '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': '3830263', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1784, 'n_words': 437}