1 /****************************************************************************************************** 2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released * 3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file * 4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. * 5 ******************************************************************************************************/ 6 7 #ifndef MM_SUBS_H 8 #define MM_SUBS_H 9 10 #include <QRgb> 11 12 class QImage; 13 class QPointF; 14 15 /// Angle between two vectors. Direction is unimportant, so result is between 0 to pi radians 16 extern double angleBetweenVectors (const QPointF &v1, 17 const QPointF &v2); 18 19 /// Angle between two vectors. Direction is positive when rotation is about +z vector, so result is betwen -pi to pi radians 20 extern double angleFromVectorToVector (const QPointF &vFrom, 21 const QPointF &vTo); 22 23 /// Calculate ellipse parameters that is incribed in a parallelogram centered at the origin, 24 /// given three successive corners of that parallelogram. By symmetry the other corner is 25 /// not needed. 26 extern void ellipseFromParallelogram (double xTL, 27 double yTL, 28 double xTR, 29 double yTR, 30 double xBR, 31 double yBR, 32 double &angleRadians, 33 double &aAligned, 34 double &bAligned); 35 36 /// Get pixel method for any bit depth 37 extern QRgb pixelRGB (const QImage &image, int x, int y); 38 39 /// Get pixel method for one bit depth 40 extern QRgb pixelRGB1 (const QImage &image1Bit, int x, int y); 41 42 /// Get pixel method for 8 bit depth 43 extern QRgb pixelRGB8 (const QImage &image8Bit, int x, int y); 44 45 /// Get pixel method for 32 bit depth 46 extern QRgb pixelRGB32 (const QImage &image32Bit, int x, int y); 47 48 /// Find the projection of a point onto a line segment such that the line through the point and its projection are normal to 49 /// the original line, subject to one constraint. The constraint is that if the project point is outside the (xStart,yStart) 50 /// to (xStop,yStop) line segment then it will be moved to (xStart,yStart) or (xStop,yStop), whichever is closer. 51 /// \param xToProject X/theta coordinate to project 52 /// \param yToProject Y/radius coordinate to project 53 /// \param xStart X/theta at start 54 /// \param yStart Y/radius at start 55 /// \param xStop X/theta at end 56 /// \param yStop Y/radius at end 57 /// \param xProjection X/theta coordinate of point projected onto line, moved to between start and end points if outside 58 /// \param yProjection Y/radius coordinate of point projected onto line, moved to between start and end points if outside 59 /// \param projectedDistanceOutsideLine Specifies how far the projected point was moved because of 60 /// this constraint - zero if it was not moved or greater than zero if it was moved. 61 /// \param distanceToLine Distance between point and close point on the line segment 62 extern void projectPointOntoLine(double xToProject, 63 double yToProject, 64 double xStart, 65 double yStart, 66 double xStop, 67 double yStop, 68 double *xProjection, 69 double *yProjection, 70 double *projectedDistanceOutsideLine, 71 double *distanceToLine); 72 73 /// Set pixel method for any bit depth 74 extern void setPixelRGB (QImage &image, int x, int y, QRgb q); 75 76 /// Set pixel method for one bit depth 77 extern void setPixelRGB1 (QImage &image1Bit, int x, int y, QRgb q); 78 79 /// Set pixel method for 8 bit depth 80 extern void setPixelRGB8 (QImage &image8Bit, int x, int y, QRgb q); 81 82 /// Set pixel method for 32 bit depth 83 extern void setPixelRGB32 (QImage &image32Bit, int x, int y, QRgb q); 84 85 #endif // MM_SUBS_H 86