File indexing completed on 2024-04-28 03:42:46
0001 /* 0002 SPDX-FileCopyrightText: 2023 Hy Murveit <hy@murveit.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 Based on https://github.com/lennig/rectangleOverlap 0007 with permission from Matt Lennig 0008 */ 0009 0010 #pragma once 0011 0012 #include <QVector> 0013 #include <QPoint> 0014 0015 /** 0016 * @class RectangleOverlap 0017 * 0018 * This class checks if two rectangles overlap. It is more general that QRect::intersects 0019 * in that the rectangles are not necessarily aligned to the axes (that is they can be 0020 * specified as rotated around their center points). 0021 * 0022 * @short Checks if two potentially rotated rectangles intersect. 0023 * @author Hy Murveit 0024 */ 0025 0026 class RectangleOverlap 0027 { 0028 public: 0029 /** Constructor specifying reference rectangle 0030 * @param center the center of the rectangle 0031 * @param width its width 0032 * @param height its height 0033 * @param rotationDegrees amount in degrees the rectangle is rotated counter-clockwise 0034 */ 0035 RectangleOverlap(const QPointF ¢er, int width, int height, double rotationDegrees = 0.0); 0036 0037 /** 0038 * @brief Check if the input rectangle overlaps the reference rectangle 0039 * 0040 * @param center the center of the input rectangle 0041 * @param width its width 0042 * @param height its height 0043 * @param rotationDegrees amount in degrees the rectangle is rotated counter-clockwise 0044 * @return true if the rectangles overlap 0045 **/ 0046 bool intersects(const QPointF ¢er, int width, int height, double rotationDegrees = 0.0) const; 0047 0048 private: 0049 // The coordinates of the reference triangle's vertices, counter-clockwise. 0050 QVector<QPointF> m_Vertices; 0051 }; 0052 0053