SVGHMI : documentation for new geometry intersection computation code + little fixes... svghmi
authorEdouard Tisserant
Fri, 28 Feb 2020 17:52:35 +0100
branchsvghmi
changeset 2845 61548f7d1bef
parent 2844 eee5dcd9fc92
child 2846 7b1db17287b6
SVGHMI : documentation for new geometry intersection computation code + little fixes...
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Fri Feb 28 16:09:21 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Fri Feb 28 17:52:35 2020 +0100
@@ -75,7 +75,10 @@
       <xsl:when test="$d0 and not($d1)">
         <func:result select="2"/>
       </xsl:when>
-      <xsl:when test="$d0 = $d1 and $b0 &lt; $a1">
+      <xsl:when test="$d0 and $d1 and $a0 &lt; $b1">
+        <func:result select="1"/>
+      </xsl:when>
+      <xsl:when test="not($d0) and not($d1) and $b0 &lt; $a1">
         <func:result select="1"/>
       </xsl:when>
       <xsl:otherwise>
@@ -89,7 +92,7 @@
     <xsl:variable name="x_intersect" select="func:intersect_1d($a/@x, $a/@x+$a/@w, $b/@x, $b/@x+$b/@w)"/>
     <xsl:choose>
       <xsl:when test="$x_intersect != 0">
-        <xsl:variable name="y_intersect" select="func:intersect_1d($a/@y, $a/@y+$a/@w, $b/@y, $b/@y+$b/@w)"/>
+        <xsl:variable name="y_intersect" select="func:intersect_1d($a/@y, $a/@y+$a/@h, $b/@y, $b/@y+$b/@h)"/>
         <func:result select="$x_intersect * $y_intersect"/>
       </xsl:when>
       <xsl:otherwise>
@@ -100,7 +103,8 @@
   <func:function name="func:overlapping_geometry">
     <xsl:param name="elt"/>
     <xsl:variable name="g" select="$geometry[@Id = $elt/@id]"/>
-    <func:result select="$geometry[@Id != $elt/@id and func:intersect(., $g) = 4]"/>
+    <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/>
+    <func:result select="$candidates[func:intersect($g, .) = 9]"/>
   </func:function>
   <func:function name="func:sumarized_elements">
     <xsl:param name="elements"/>
--- a/svghmi/gen_index_xhtml.ysl2	Fri Feb 28 16:09:21 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2	Fri Feb 28 17:52:35 2020 +0100
@@ -78,6 +78,7 @@
         param "elems";
         const "descend", "$elems/descendant-or-self::svg:*";
         const "clones", "$descend[self::svg:use]";
+        // TODO optimize using Xpath' id()
         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
         choose {
             when "$originals" 
@@ -98,16 +99,89 @@
         const "d1", "$a1 >= $b1";
         choose {
             when "not($d0) and $d1"
-                result "3"; /* a included in b */
+                // b contained in a
+                //   a0<b0 b1<a1
+                // a +--------+
+                // b    +--+
+                result "3";
             when "$d0 and not($d1)"
-                result "2"; /* b included in a */
-            when "$d0 = $d1 and $b0 < $a1"
-                result "1"; /* a and b are overlapped */
+                // a contained in b
+                //   b0<a0 a1<b1
+                // a    +--+
+                // b +--------+
+                result "2";
+            when "$d0 and $d1 and $a0 < $b1"
+                // a and b are overlapped 
+                //   b0<a0<b1<a1
+                // a    +-----+
+                // b +-----+
+                result "1";
+            when "not($d0) and not($d1) and $b0 < $a1"
+                // a and b are overlapped
+                //   a0<b0<a1<b1
+                // a +-----+
+                // b    +-----+
+                result "1";
             otherwise
                 result "0"; /* no intersection*/
         }
     }
 
+    // returns :
+    // 0 - no intersection
+    //            .-----.
+    //    .-----. |    b|
+    //    |     | |     |
+    //    |     | '-----'
+    //    |a    |
+    //    '-----'
+    //
+    // 1 - overlapping
+    //        .-----.
+    //    .---|--. b|
+    //    |   |  |  |
+    //    |   '-----'
+    //    |a     |
+    //    '------'
+    //
+    // 2 - overlapping 
+    //        .-----.    
+    //        |  a  |
+    //    .---|-----|---.
+    //    |   '-----'   |
+    //    | b           |
+    //    '-------------'
+    //
+    // 3 - overlapping 
+    //        .-----.    
+    //        |  b  |    
+    //    .---|-----|---.
+    //    |   '-----'   |
+    //    | a           |
+    //    '-------------'
+    //
+    // 4 - a contained in b
+    //    .-------------.
+    //    |   .-----.   |
+    //    |   |  a  |   |
+    //    |b  '-----'   |
+    //    '-------------'
+    //
+    // 6 - overlapping
+    //        .----.    
+    //        |   b|    
+    //    .---|----|---.
+    //    |a  |    |   |
+    //    '---|----|---'
+    //        '----'
+    //
+    // 9 - b contained in a
+    //    .-------------.
+    //    |   .-----.   |
+    //    |   |  b  |   |
+    //    |a  '-----'   |
+    //    '-------------'
+    //
     def "func:intersect" {
         param "a";
         param "b";
@@ -116,20 +190,26 @@
 
         choose{
             when "$x_intersect != 0"{
-                const "y_intersect", "func:intersect_1d($a/@y, $a/@y+$a/@w, $b/@y, $b/@y+$b/@w)";
+                const "y_intersect", "func:intersect_1d($a/@y, $a/@y+$a/@h, $b/@y, $b/@y+$b/@h)";
                 result "$x_intersect * $y_intersect";
             }
             otherwise result "0";
         }
     }
 
-    // return overlapping geometry a given element
+    // return overlapping geometry for a given element
+    // all intersercting element are returned
+    // except groups, that must be contained to be counted in
     def "func:overlapping_geometry" {
         param "elt";
-        /* only included groups are returned */
-        /* all other elemenst are returne when overlapping*/
         const "g", "$geometry[@Id = $elt/@id]"; 
-        result """$geometry[@Id != $elt/@id and func:intersect(., $g) = 4]""";
+        const "candidates", "$geometry[@Id != $elt/@id]";
+        result "$candidates[func:intersect($g, .) = 9]";
+/*
+        const "groups", "$candidates[@Id = //svg:g/@id]"; 
+        const "graphic", "$candidates[@Id != $groups/@Id]"; 
+        result "$groups[func:intersect($g, .) = 9] | $graphic[func:intersect($g, .) > 0]";
+        */
     }
 
     def "func:sumarized_elements" {