LCD LIB

Dependents:   HagridOS5

Fork of RA8875 by David Smart

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Mon Jun 12 22:15:08 2017 +0000
Parent:
146:373d59f08357
Child:
148:33e99de1aca6
Commit message:
Improved the Intersect(rect_t, rect_t) to look for any intersection, and added an Intersect(rect_t *, rect_t *) which will identify and make available a new rect_t which is the intersection (if any).

Changed in this revision

RA8875.cpp Show annotated file Show diff for this revision Revisions of this file
RA8875.h Show annotated file Show diff for this revision Revisions of this file
--- a/RA8875.cpp	Thu Jun 01 11:00:40 2017 +0000
+++ b/RA8875.cpp	Mon Jun 12 22:15:08 2017 +0000
@@ -525,20 +525,47 @@
 
 bool RA8875::Intersect(rect_t rect1, rect_t rect2)
 {
+#if 1
+    // If one rectangle is on left side of other
+    if (max(rect1.p1.x,rect1.p2.x) < min(rect2.p1.x,rect2.p2.x)
+        || min(rect1.p1.x, rect1.p2.x) > max(rect2.p1.x, rect2.p2.x))
+        return false;
+    // If one rectangle is above other
+    if (max(rect1.p1.y, rect1.p2.y) < min(rect2.p1.y, rect2.p2.y)
+        || min(rect1.p1.y, rect1.p2.y) > max(rect2.p1.y, rect2.p2.y))
+        return false;
+    return true;            // all that's left is they overlap
+#else
     point_t bl, tr;
-    
     bl.x = rect2.p1.x;
     bl.y = rect2.p2.y;
     tr.x = rect2.p2.x;
     tr.y = rect2.p1.y;
     if (Intersect(rect1, rect2.p1) || Intersect(rect1, rect2.p2)
-    || Intersect(rect1, bl) || Intersect(rect1, tr))
+        || Intersect(rect1, bl) || Intersect(rect1, tr))
         return true;
     else
         return false;
+#endif
 }
 
 
+bool RA8875::Intersect(rect_t * pRect1, const rect_t * pRect2)
+{
+    if (Intersect(*pRect1, *pRect2)) {
+        rect_t iSect;
+        
+        iSect.p1.x = max(pRect1->p1.x, pRect2->p1.x);
+        iSect.p1.y = max(pRect1->p1.y, pRect2->p1.y);
+        iSect.p2.x = min(pRect1->p2.x, pRect2->p2.x);
+        iSect.p2.y = min(pRect1->p2.y, pRect2->p2.y);
+        *pRect1 = iSect;
+        return true;
+    } else {
+        return false;
+    }
+}
+
 
 RetCode_t RA8875::WriteCommandW(uint8_t command, uint16_t data)
 {
--- a/RA8875.h	Thu Jun 01 11:00:40 2017 +0000
+++ b/RA8875.h	Mon Jun 12 22:15:08 2017 +0000
@@ -1163,10 +1163,36 @@
     ///
     /// @param[in] rect1 is a rectangular region.
     /// @param[in] rect2 is a second rectangular region.
-    /// @returns true if rect1 and rect2 intersect.
+    /// @returns true if any part of rect2 intersects rect1.
     ///
     bool Intersect(rect_t rect1, rect_t rect2);
     
+    /// Determine if a rectangle intersects another rectangle and provides
+    /// the area of intersection.
+    ///
+    /// @code
+    ///     +---------------------+
+    ///     | rect1               |
+    ///     |                     |
+    ///     |          +------------------+
+    ///     |          | rect3    |       |
+    ///     |          |          |       |
+    ///     +---------------------+       |
+    ///                | rect2            |
+    ///                +------------------+
+    /// @endcode
+    ///
+    /// @note that the first parameter is a pointer to a rect and the 
+    ///
+    /// @param[inout] pRect1 is a pointer to a rectangular region, and returns
+    ///             the area of intersection.
+    /// @param[in] pRect2 is a pointer to a second rectangular region.
+    /// @returns true if pRect1 and pRect2 intersect and pRect1 is written with
+    ///             the rectangle describing the intersection.
+    ///
+    bool Intersect(rect_t * rect1, const rect_t * rect2);
+    
+    
     /// Write a command to the display with a word of data.
     ///
     /// This is a high level command, and may invoke several primitives.