svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2845 61548f7d1bef
parent 2844 eee5dcd9fc92
child 2846 7b1db17287b6
equal deleted inserted replaced
2844:eee5dcd9fc92 2845:61548f7d1bef
    76     // returns all directly or indirectly refered elements
    76     // returns all directly or indirectly refered elements
    77     def "func:refered_elements" {
    77     def "func:refered_elements" {
    78         param "elems";
    78         param "elems";
    79         const "descend", "$elems/descendant-or-self::svg:*";
    79         const "descend", "$elems/descendant-or-self::svg:*";
    80         const "clones", "$descend[self::svg:use]";
    80         const "clones", "$descend[self::svg:use]";
       
    81         // TODO optimize using Xpath' id()
    81         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
    82         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
    82         choose {
    83         choose {
    83             when "$originals" 
    84             when "$originals" 
    84                 result "$descend | func:refered_elements($originals)";
    85                 result "$descend | func:refered_elements($originals)";
    85             otherwise
    86             otherwise
    96 
    97 
    97         const "d0", "$a0 >= $b0";
    98         const "d0", "$a0 >= $b0";
    98         const "d1", "$a1 >= $b1";
    99         const "d1", "$a1 >= $b1";
    99         choose {
   100         choose {
   100             when "not($d0) and $d1"
   101             when "not($d0) and $d1"
   101                 result "3"; /* a included in b */
   102                 // b contained in a
       
   103                 //   a0<b0 b1<a1
       
   104                 // a +--------+
       
   105                 // b    +--+
       
   106                 result "3";
   102             when "$d0 and not($d1)"
   107             when "$d0 and not($d1)"
   103                 result "2"; /* b included in a */
   108                 // a contained in b
   104             when "$d0 = $d1 and $b0 < $a1"
   109                 //   b0<a0 a1<b1
   105                 result "1"; /* a and b are overlapped */
   110                 // a    +--+
       
   111                 // b +--------+
       
   112                 result "2";
       
   113             when "$d0 and $d1 and $a0 < $b1"
       
   114                 // a and b are overlapped 
       
   115                 //   b0<a0<b1<a1
       
   116                 // a    +-----+
       
   117                 // b +-----+
       
   118                 result "1";
       
   119             when "not($d0) and not($d1) and $b0 < $a1"
       
   120                 // a and b are overlapped
       
   121                 //   a0<b0<a1<b1
       
   122                 // a +-----+
       
   123                 // b    +-----+
       
   124                 result "1";
   106             otherwise
   125             otherwise
   107                 result "0"; /* no intersection*/
   126                 result "0"; /* no intersection*/
   108         }
   127         }
   109     }
   128     }
   110 
   129 
       
   130     // returns :
       
   131     // 0 - no intersection
       
   132     //            .-----.
       
   133     //    .-----. |    b|
       
   134     //    |     | |     |
       
   135     //    |     | '-----'
       
   136     //    |a    |
       
   137     //    '-----'
       
   138     //
       
   139     // 1 - overlapping
       
   140     //        .-----.
       
   141     //    .---|--. b|
       
   142     //    |   |  |  |
       
   143     //    |   '-----'
       
   144     //    |a     |
       
   145     //    '------'
       
   146     //
       
   147     // 2 - overlapping 
       
   148     //        .-----.    
       
   149     //        |  a  |
       
   150     //    .---|-----|---.
       
   151     //    |   '-----'   |
       
   152     //    | b           |
       
   153     //    '-------------'
       
   154     //
       
   155     // 3 - overlapping 
       
   156     //        .-----.    
       
   157     //        |  b  |    
       
   158     //    .---|-----|---.
       
   159     //    |   '-----'   |
       
   160     //    | a           |
       
   161     //    '-------------'
       
   162     //
       
   163     // 4 - a contained in b
       
   164     //    .-------------.
       
   165     //    |   .-----.   |
       
   166     //    |   |  a  |   |
       
   167     //    |b  '-----'   |
       
   168     //    '-------------'
       
   169     //
       
   170     // 6 - overlapping
       
   171     //        .----.    
       
   172     //        |   b|    
       
   173     //    .---|----|---.
       
   174     //    |a  |    |   |
       
   175     //    '---|----|---'
       
   176     //        '----'
       
   177     //
       
   178     // 9 - b contained in a
       
   179     //    .-------------.
       
   180     //    |   .-----.   |
       
   181     //    |   |  b  |   |
       
   182     //    |a  '-----'   |
       
   183     //    '-------------'
       
   184     //
   111     def "func:intersect" {
   185     def "func:intersect" {
   112         param "a";
   186         param "a";
   113         param "b";
   187         param "b";
   114 
   188 
   115         const "x_intersect", "func:intersect_1d($a/@x, $a/@x+$a/@w, $b/@x, $b/@x+$b/@w)";
   189         const "x_intersect", "func:intersect_1d($a/@x, $a/@x+$a/@w, $b/@x, $b/@x+$b/@w)";
   116 
   190 
   117         choose{
   191         choose{
   118             when "$x_intersect != 0"{
   192             when "$x_intersect != 0"{
   119                 const "y_intersect", "func:intersect_1d($a/@y, $a/@y+$a/@w, $b/@y, $b/@y+$b/@w)";
   193                 const "y_intersect", "func:intersect_1d($a/@y, $a/@y+$a/@h, $b/@y, $b/@y+$b/@h)";
   120                 result "$x_intersect * $y_intersect";
   194                 result "$x_intersect * $y_intersect";
   121             }
   195             }
   122             otherwise result "0";
   196             otherwise result "0";
   123         }
   197         }
   124     }
   198     }
   125 
   199 
   126     // return overlapping geometry a given element
   200     // return overlapping geometry for a given element
       
   201     // all intersercting element are returned
       
   202     // except groups, that must be contained to be counted in
   127     def "func:overlapping_geometry" {
   203     def "func:overlapping_geometry" {
   128         param "elt";
   204         param "elt";
   129         /* only included groups are returned */
       
   130         /* all other elemenst are returne when overlapping*/
       
   131         const "g", "$geometry[@Id = $elt/@id]"; 
   205         const "g", "$geometry[@Id = $elt/@id]"; 
   132         result """$geometry[@Id != $elt/@id and func:intersect(., $g) = 4]""";
   206         const "candidates", "$geometry[@Id != $elt/@id]";
       
   207         result "$candidates[func:intersect($g, .) = 9]";
       
   208 /*
       
   209         const "groups", "$candidates[@Id = //svg:g/@id]"; 
       
   210         const "graphic", "$candidates[@Id != $groups/@Id]"; 
       
   211         result "$groups[func:intersect($g, .) = 9] | $graphic[func:intersect($g, .) > 0]";
       
   212         */
   133     }
   213     }
   134 
   214 
   135     def "func:sumarized_elements" {
   215     def "func:sumarized_elements" {
   136         param "elements";
   216         param "elements";
   137         const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
   217         const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";