File indexing completed on 2024-05-12 04:06:21

0001 /*
0002     SPDX-FileCopyrightText: 2010 Johannes Loehnert <loehnert.kde@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef PALAPELISLICERS_GOLDBERG_UTILITIES_H
0008 #define PALAPELISLICERS_GOLDBERG_UTILITIES_H
0009 
0010 #include <cmath>
0011 #include <QImage>
0012 
0013 inline qreal dotproduct(const QPointF& a, const QPointF& b) { return a.x() * b.x() + a.y() * b.y(); }
0014 
0015 inline qreal dsin(qreal angle) { return sin(angle* M_PI / 180.0); }
0016 inline qreal dcos(qreal angle) { return cos(angle* M_PI / 180.0); }
0017 
0018 
0019 // get recommended cell count for the given aspect.
0020 // aspect is image_width / image_height / (cell_aspect)
0021 //  with cell_aspect = cell_width / cell_height (for non-square grid cell).
0022 // sets xCount, yCount.
0023 void getBestFit(int &xCount, int &yCount, qreal target_aspect, int approx_count); 
0024 void getBestFitExtended(int &xCount, int &yCount, qreal target_aspect, int approx_count,
0025             qreal tiles_per_cell, qreal additional_tiles_per_row, qreal additional_tiles_per_column, qreal additional_tiles);
0026 
0027 //A modified version of QImage::copy, which avoids rendering errors even if rect is outside the bounds of the source image.
0028 QImage safeQImageCopy(const QImage& source, const QRect& rect);
0029 
0030 // skews x with "strength" a.
0031 // x is expected to lie within [0, 1].
0032 // a = +/-1 is already a very strong skew.
0033 // negative a: skew towards x=0, positive: skew towards x=1.
0034 qreal skew_randnum(qreal x, qreal a);
0035 
0036 qreal nonuniform_rand(qreal min, qreal max, qreal sigma, qreal skew);
0037 
0038 
0039 #endif // PALAPELISLICERS_GOLDBERG_UTILITIES_H