Commit 70c0b9422de8cb43045448c8c63a79ea3d1d13c6

Authored by Jiaming Guo
1 parent f4105b89

fixed bug when height < n * radius

Showing 1 changed file with 35 additions and 62 deletions   Show diff stats
@@ -1305,60 +1305,6 @@ namespace stim { @@ -1305,60 +1305,6 @@ namespace stim {
1305 } 1305 }
1306 } 1306 }
1307 1307
1308 - // inlet connection  
1309 - for (unsigned i = 0; i < inlet.size(); i++) {  
1310 - v1 = inlet[i].V[2] - inlet[i].V[1];  
1311 - v2 = v0 - inlet[i].V[1];  
1312 - v3 = v0 - inlet[i].V[2];  
1313 -  
1314 - tmp_d = v2.dot(v1); // av·ab  
1315 -  
1316 - // check the line relative position  
1317 - a = v2.dot(v1.norm());  
1318 - b = v3.dot(v1.norm());  
1319 - if (a < v1.len() && b < v1.len()) // if the length of projection fragment is longer than the line-segment  
1320 - online = true;  
1321 - else  
1322 - online = false;  
1323 -  
1324 - if (tmp_d <= 0.0 || tmp_d > std::pow(v1.len(), 2) && !online) // projection lies outside the line-segment  
1325 - continue;  
1326 - else {  
1327 - tmp_d = v1.cross(v2).len() / v1.len(); // perpendicular distance of point to segment: |v1 x v2| / |v1|  
1328 - if (tmp_d < d) {  
1329 - d = tmp_d;  
1330 - tmp_i = i;  
1331 - }  
1332 - }  
1333 - }  
1334 -  
1335 - // outlet connection  
1336 - for (unsigned i = 0; i < outlet.size(); i++) {  
1337 - v1 = outlet[i].V[2] - outlet[i].V[1];  
1338 - v2 = v0 - outlet[i].V[1];  
1339 - v3 = v0 - outlet[i].V[2];  
1340 -  
1341 - tmp_d = v2.dot(v1); // av·ab  
1342 -  
1343 - // check the line relative position  
1344 - a = v2.dot(v1.norm());  
1345 - b = v3.dot(v1.norm());  
1346 - if (a < v1.len() && b < v1.len()) // if the length of projection fragment is longer than the line-segment  
1347 - online = true;  
1348 - else  
1349 - online = false;  
1350 -  
1351 - if (tmp_d <= 0.0 || tmp_d > std::pow(v1.len(), 2) && !online) // projection lies outside the line-segment  
1352 - continue;  
1353 - else {  
1354 - tmp_d = v1.cross(v2).len() / v1.len(); // perpendicular distance of point to segment: |v1 x v2| / |v1|  
1355 - if (tmp_d < d) {  
1356 - d = tmp_d;  
1357 - tmp_i = i;  
1358 - }  
1359 - }  
1360 - }  
1361 -  
1362 eps += get_radius(tmp_i, tmp_j); 1308 eps += get_radius(tmp_i, tmp_j);
1363 1309
1364 if (d < eps) { 1310 if (d < eps) {
@@ -1568,7 +1514,7 @@ namespace stim { @@ -1568,7 +1514,7 @@ namespace stim {
1568 int find_number_square(T origin_l, T desire_l, T radius = 5.0f, int times = 4) { 1514 int find_number_square(T origin_l, T desire_l, T radius = 5.0f, int times = 4) {
1569 1515
1570 bool done = false; // flag indicates the current number of square shape structure is feasible 1516 bool done = false; // flag indicates the current number of square shape structure is feasible
1571 - int n = origin_l / (times * 2 * radius); // number of square shape structure 1517 + int n = origin_l / (times * 4 * radius);// number of square shape structure
1572 T need_l = desire_l - origin_l; 1518 T need_l = desire_l - origin_l;
1573 T height; // height of the square shapce structure 1519 T height; // height of the square shapce structure
1574 1520
@@ -1596,9 +1542,9 @@ namespace stim { @@ -1596,9 +1542,9 @@ namespace stim {
1596 std::pair<stim::vec3<T>, stim::vec3<T>> tmp_bb; 1542 std::pair<stim::vec3<T>, stim::vec3<T>> tmp_bb;
1597 stim::vec3<T> tmp_v; 1543 stim::vec3<T> tmp_v;
1598 if (feeder == 1) 1544 if (feeder == 1)
1599 - tmp_v = inlet[i].V[0]; 1545 + tmp_v = inlet[i].V[inlet[i].V.size() - 1];
1600 else if (feeder == 0) 1546 else if (feeder == 0)
1601 - tmp_v = outlet[i].V[0]; 1547 + tmp_v = outlet[i].V[outlet[i].V.size() - 1];
1602 tmp_bb.first = tmp_v; 1548 tmp_bb.first = tmp_v;
1603 1549
1604 // check whether the height of connections is acceptable 1550 // check whether the height of connections is acceptable
@@ -1723,6 +1669,15 @@ namespace stim { @@ -1723,6 +1669,15 @@ namespace stim {
1723 } 1669 }
1724 } 1670 }
1725 else { 1671 else {
  1672 + if (height < times * radius) { // if height is too small, decrease n and re-calculate height and width
  1673 + height = times * radius;
  1674 + T need_l = desire_l - origin_l;
  1675 + n = need_l / (2 * height);
  1676 + if (n == 0)
  1677 + n = 1;
  1678 + height = need_l / (2 * n);
  1679 + width = origin_l / (2 * n);
  1680 + }
1726 for (int j = 0; j < n; j++) { 1681 for (int j = 0; j < n; j++) {
1727 1682
1728 // up 1683 // up
@@ -2000,7 +1955,7 @@ namespace stim { @@ -2000,7 +1955,7 @@ namespace stim {
2000 1955
2001 bus_v = inlet[i].V[0]; 1956 bus_v = inlet[i].V[0];
2002 mid_v = inlet[i].V[1]; 1957 mid_v = inlet[i].V[1];
2003 - tmp_v = inlet[i].V[2]; 1958 + tmp_v = inlet[i].V[2]; // not always pendant vertex
2004 1959
2005 if (inlet[i].V[2][1] > main_feeder[0][1]) // check out upper side of lower side 1960 if (inlet[i].V[2][1] > main_feeder[0][1]) // check out upper side of lower side
2006 upper = true; 1961 upper = true;
@@ -2014,8 +1969,17 @@ namespace stim { @@ -2014,8 +1969,17 @@ namespace stim {
2014 1969
2015 T origin_l = (inlet[i].V[1] - inlet[i].V[2]).len(); 1970 T origin_l = (inlet[i].V[1] - inlet[i].V[2]).len();
2016 T desire_l = new_l - (inlet[i].V[0] - inlet[i].V[1]).len(); 1971 T desire_l = new_l - (inlet[i].V[0] - inlet[i].V[1]).len();
2017 - inlet[i].V.clear();  
2018 - inlet[i].V.push_back(tmp_v); 1972 + if (inlet[i].V.size() != 3) {
  1973 + desire_l = new_l - (inlet[i].V[0] - inlet[i].V[1]).len() - (inlet[i].V[2] - inlet[i].V[3]).len();
  1974 + stim::vec3<T> tmp = inlet[i].V[3];
  1975 + inlet[i].V.clear();
  1976 + inlet[i].V.push_back(tmp);
  1977 + inlet[i].V.push_back(tmp_v);
  1978 + }
  1979 + else {
  1980 + inlet[i].V.clear();
  1981 + inlet[i].V.push_back(tmp_v);
  1982 + }
2019 inlet[i].l = new_l; 1983 inlet[i].l = new_l;
2020 1984
2021 n = find_number_square(origin_l, desire_l); 1985 n = find_number_square(origin_l, desire_l);
@@ -2054,8 +2018,17 @@ namespace stim { @@ -2054,8 +2018,17 @@ namespace stim {
2054 2018
2055 T origin_l = (outlet[i].V[1] - outlet[i].V[2]).len(); 2019 T origin_l = (outlet[i].V[1] - outlet[i].V[2]).len();
2056 T desire_l = new_l - (outlet[i].V[0] - outlet[i].V[1]).len(); 2020 T desire_l = new_l - (outlet[i].V[0] - outlet[i].V[1]).len();
2057 - outlet[i].V.clear();  
2058 - outlet[i].V.push_back(tmp_v); 2021 + if (outlet[i].V.size() != 3) {
  2022 + desire_l = new_l - (outlet[i].V[0] - outlet[i].V[1]).len() - (outlet[i].V[2] - outlet[i].V[3]).len();
  2023 + stim::vec3<T> tmp = outlet[i].V[3];
  2024 + outlet[i].V.clear();
  2025 + outlet[i].V.push_back(tmp);
  2026 + outlet[i].V.push_back(tmp_v);
  2027 + }
  2028 + else {
  2029 + outlet[i].V.clear();
  2030 + outlet[i].V.push_back(tmp_v);
  2031 + }
2059 outlet[i].l = new_l; 2032 outlet[i].l = new_l;
2060 2033
2061 n = find_number_square(origin_l, desire_l); 2034 n = find_number_square(origin_l, desire_l);