GeometryUtils.h
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
//  GeometryUtils.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 20.05.2017.
//
//
#ifndef GeometryUtils_h
#define GeometryUtils_h
#include "cocos2d.h"
class GeometryUtils
{
    public:
    
        struct ThickSegment
        {
            cocos2d::Point point1;
            cocos2d::Point point2;
            float thickness;
            
            ThickSegment(){
                point1 = cocos2d::Point(0,0);
                point2 = cocos2d::Point(0,0);
                thickness = 0;
            }
            
            ThickSegment(cocos2d::Point p1, cocos2d::Point p2, float pThickness){
                point1 = p1;
                point2 = p2;
                thickness = pThickness;
            }
        };
    
        static void flipChildX(cocos2d::Node* flippedParent, cocos2d::Node* child);
        static cocos2d::Rect flippedXRect(cocos2d::Node* flippedParent, cocos2d::Rect rect);
        static cocos2d::Point flippedXPoint(cocos2d::Node* flippedParent, cocos2d::Point point);
        static cocos2d::Rect getBoundingBoxToWorld(cocos2d::Node* node, bool ignoreTransformations = true);
        static cocos2d::Rect getBoundingBoxToWorldForSubrect(cocos2d::Node* node, cocos2d::Rect subrect);
        static cocos2d::Rect getRectIntersection(cocos2d::Rect rect1, cocos2d::Rect rect2);
        static bool segmentIntersectsRect(cocos2d::Rect rect, cocos2d::Point lineP1, cocos2d::Point lineP2);
        static cocos2d::Point addPoints(std::vector<cocos2d::Point> points);
        static void getLineABCFromPoints(cocos2d::Point pointA, cocos2d::Point pointB, float (&line)[3]);
        static bool segmentCrossesLine(cocos2d::Point sPointA, cocos2d::Point sPointB, float lineA, float lineB, float lineC);
        static float calculateIntersectionPercentage(cocos2d::Rect rect1, cocos2d::Rect rect2, int percentageOfWhichRect = 0);
};
#endif /* GeometryUtils_h */
