<commit_before>/*
 * This file is part of the UnTech Editor Suite.
 * Copyright (c) 2016 - 2017, <NAME> <<EMAIL>>.
 * Distributed under The MIT License: https://opensource.org/licenses/MIT
 */

#include "aabbgraphicsitem.h"

#include <QGraphicsScene>
#include <QPainter>
#include <QtMath>

using namespace UnTech::GuiQt;

AabbGraphicsItem::AabbGraphicsItem(QGraphicsItem* parent)
    : QGraphicsItem(parent)
    , _size(1, 1)
    , _range(0, 0, INT_MAX, INT_MAX)
    , _pen()
    , _brush(Qt::NoBrush)
    , _selectionOutline(nullptr)
{
    setFlag(ItemSendsGeometryChanges);
}

void AabbGraphicsItem::setRange(const QRect& range)
{
    if (_range != range) {
        _range = range;
        if (!_range.isValid()) {
            _range = QRect(0, 0, INT_MAX, INT_MAX);
        }

        QPointF pos = this->pos();
        int x = qFloor(pos.x());
        int y = qFloor(pos.y());

        setSize(_size);
        setPos(x, y);
    }
}

void AabbGraphicsItem::setSize(int width, int height)
{
    QPointF pos = this->pos();
    int x = qFloor(pos.x());
    int y = qFloor(pos.y());

    QSize s(qBound(1, width, _range.right() - x + 1),
            qBound(1, height, _range.bottom() - y + 1));

    if (_size != s) {
        prepareGeometryChange();
        _size = s;
        update();
        updateSelectionOutline();
    }
}

void AabbGraphicsItem::setRect(const QRect& rect)
{
    QGraphicsItem::setPos(rect.x(), rect.y());
    setSize(rect.width(), rect.height());
}

void AabbGraphicsItem::setRect(const urect& rect)
{
    QGraphicsItem::setPos(rect.x, rect.y);
    setSize(rect.width, rect.height);
}

void AabbGraphicsItem::setRect(const ms8rect& rect)
{
    QGraphicsItem::setPos(rect.x, rect.y);
    setSize(rect.width, rect.height);
}

void AabbGraphicsItem::setRect(const upoint& point, unsigned squareSize)
{
    QGraphicsItem::setPos(point.x, point.y);
    setSize(squareSize);
}

void AabbGraphicsItem::setRect(const ms8point& point, unsigned squareSize)
{
    QGraphicsItem::setPos(point.x, point.y);
    setSize(squareSize);
}

void AabbGraphicsItem::setPen(const QPen& pen)
{
    if (_pen != pen) {
        prepareGeometryChange();<commit_msg>fix: prevent corruption on AabbGraphicsItem::setRect<commit_after>/*
 * This file is part of the UnTech Editor Suite.
 * Copyright (c) 2016 - 2017, <NAME> <<EMAIL>>.
 * Distributed under The MIT License: https://opensource.org/licenses/MIT
 */

#include "aabbgraphicsitem.h"

#include <QGraphicsScene>
#include <QPainter>
#include <QtMath>

using namespace UnTech::GuiQt;

AabbGraphicsItem::AabbGraphicsItem(QGraphicsItem* parent)
    : QGraphicsItem(parent)
    , _size(1, 1)
    , _range(0, 0, INT_MAX, INT_MAX)
    , _pen()
    , _brush(Qt::NoBrush)
    , _selectionOutline(nullptr)
{
    setFlag(ItemSendsGeometryChanges);
}

void AabbGraphicsItem::setRange(const QRect& range)
{
    if (_range != range) {
        _range = range;
        if (!_range.isValid()) {
            _range = QRect(0, 0, INT_MAX, INT_MAX);
        }

        QPointF pos = this->pos();
        int x = qFloor(pos.x());
        int y = qFloor(pos.y());

        setSize(_size);
        setPos(x, y);
    }
}

void AabbGraphicsItem::setSize(int width, int height)
{
    QPointF pos = this->pos();
    int x = qFloor(pos.x());
    int y = qFloor(pos.y());

    QSize s(qBound(1, width, _range.right() - x + 1),
            qBound(1, height, _range.bottom() - y + 1));

    if (_size != s) {
        prepareGeometryChange();
        _size = s;
        update();
        updateSelectionOutline();
    }
}

void AabbGraphicsItem::setRect(const QRect& rect)
{
    _size = QSize(0, 0);
    QGraphicsItem::setPos(rect.x(), rect.y());
    setSize(rect.width(), rect.height());
}

void AabbGraphicsItem::setRect(const urect& rect)
{
    _size = QSize(0, 0);
    QGraphicsItem::setPos(rect.x, rect.y);
    setSize(rect.width, rect.height);
}

void AabbGraphicsItem::setRect(const ms8rect& rect)
{
    _size = QSize(0, 0);
    QGraphicsItem::setPos(rect.x, rect.y);
    setSize(rect.width, rect.height);
}

void AabbGraphicsItem::setRect(const upoint& point, unsigned squareSize)
{
    _size = QSize(0, 0);
    QGraphicsItem::setPos(point.x, point.y);
    setSize(squareSize);
}

void AabbGraphicsItem::setRect(const ms8point& point, unsigned squareSize)
{
    _size = QSize(0, 0);
    QGraphicsItem::setPos(point.x, point.y);
    setSize(squareSize);
}

void AabbGraphicsItem::setPen(const QPen& pen)
{
    if (_pen != pen) {
        prepareGeometryChange();
{'fraction_non_alphanumeric': 0.15106951871657753, 'fraction_numerical': 0.011140819964349376, 'mean_word_length': 3.320500481231954, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '6979329', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1583, 'n_words': 332}