From 70c0b9422de8cb43045448c8c63a79ea3d1d13c6 Mon Sep 17 00:00:00 2001 From: Jiaming Guo Date: Wed, 24 May 2017 15:40:27 -0500 Subject: [PATCH] fixed bug when height < n * radius --- flow.h | 97 +++++++++++++++++++++++++++++++++++-------------------------------------------------------------- 1 file changed, 35 insertions(+), 62 deletions(-) diff --git a/flow.h b/flow.h index f44b8ea..e05bfdf 100644 --- a/flow.h +++ b/flow.h @@ -1305,60 +1305,6 @@ namespace stim { } } - // inlet connection - for (unsigned i = 0; i < inlet.size(); i++) { - v1 = inlet[i].V[2] - inlet[i].V[1]; - v2 = v0 - inlet[i].V[1]; - v3 = v0 - inlet[i].V[2]; - - tmp_d = v2.dot(v1); // av·ab - - // check the line relative position - a = v2.dot(v1.norm()); - b = v3.dot(v1.norm()); - if (a < v1.len() && b < v1.len()) // if the length of projection fragment is longer than the line-segment - online = true; - else - online = false; - - if (tmp_d <= 0.0 || tmp_d > std::pow(v1.len(), 2) && !online) // projection lies outside the line-segment - continue; - else { - tmp_d = v1.cross(v2).len() / v1.len(); // perpendicular distance of point to segment: |v1 x v2| / |v1| - if (tmp_d < d) { - d = tmp_d; - tmp_i = i; - } - } - } - - // outlet connection - for (unsigned i = 0; i < outlet.size(); i++) { - v1 = outlet[i].V[2] - outlet[i].V[1]; - v2 = v0 - outlet[i].V[1]; - v3 = v0 - outlet[i].V[2]; - - tmp_d = v2.dot(v1); // av·ab - - // check the line relative position - a = v2.dot(v1.norm()); - b = v3.dot(v1.norm()); - if (a < v1.len() && b < v1.len()) // if the length of projection fragment is longer than the line-segment - online = true; - else - online = false; - - if (tmp_d <= 0.0 || tmp_d > std::pow(v1.len(), 2) && !online) // projection lies outside the line-segment - continue; - else { - tmp_d = v1.cross(v2).len() / v1.len(); // perpendicular distance of point to segment: |v1 x v2| / |v1| - if (tmp_d < d) { - d = tmp_d; - tmp_i = i; - } - } - } - eps += get_radius(tmp_i, tmp_j); if (d < eps) { @@ -1568,7 +1514,7 @@ namespace stim { int find_number_square(T origin_l, T desire_l, T radius = 5.0f, int times = 4) { bool done = false; // flag indicates the current number of square shape structure is feasible - int n = origin_l / (times * 2 * radius); // number of square shape structure + int n = origin_l / (times * 4 * radius);// number of square shape structure T need_l = desire_l - origin_l; T height; // height of the square shapce structure @@ -1596,9 +1542,9 @@ namespace stim { std::pair, stim::vec3> tmp_bb; stim::vec3 tmp_v; if (feeder == 1) - tmp_v = inlet[i].V[0]; + tmp_v = inlet[i].V[inlet[i].V.size() - 1]; else if (feeder == 0) - tmp_v = outlet[i].V[0]; + tmp_v = outlet[i].V[outlet[i].V.size() - 1]; tmp_bb.first = tmp_v; // check whether the height of connections is acceptable @@ -1723,6 +1669,15 @@ namespace stim { } } else { + if (height < times * radius) { // if height is too small, decrease n and re-calculate height and width + height = times * radius; + T need_l = desire_l - origin_l; + n = need_l / (2 * height); + if (n == 0) + n = 1; + height = need_l / (2 * n); + width = origin_l / (2 * n); + } for (int j = 0; j < n; j++) { // up @@ -2000,7 +1955,7 @@ namespace stim { bus_v = inlet[i].V[0]; mid_v = inlet[i].V[1]; - tmp_v = inlet[i].V[2]; + tmp_v = inlet[i].V[2]; // not always pendant vertex if (inlet[i].V[2][1] > main_feeder[0][1]) // check out upper side of lower side upper = true; @@ -2014,8 +1969,17 @@ namespace stim { T origin_l = (inlet[i].V[1] - inlet[i].V[2]).len(); T desire_l = new_l - (inlet[i].V[0] - inlet[i].V[1]).len(); - inlet[i].V.clear(); - inlet[i].V.push_back(tmp_v); + if (inlet[i].V.size() != 3) { + desire_l = new_l - (inlet[i].V[0] - inlet[i].V[1]).len() - (inlet[i].V[2] - inlet[i].V[3]).len(); + stim::vec3 tmp = inlet[i].V[3]; + inlet[i].V.clear(); + inlet[i].V.push_back(tmp); + inlet[i].V.push_back(tmp_v); + } + else { + inlet[i].V.clear(); + inlet[i].V.push_back(tmp_v); + } inlet[i].l = new_l; n = find_number_square(origin_l, desire_l); @@ -2054,8 +2018,17 @@ namespace stim { T origin_l = (outlet[i].V[1] - outlet[i].V[2]).len(); T desire_l = new_l - (outlet[i].V[0] - outlet[i].V[1]).len(); - outlet[i].V.clear(); - outlet[i].V.push_back(tmp_v); + if (outlet[i].V.size() != 3) { + desire_l = new_l - (outlet[i].V[0] - outlet[i].V[1]).len() - (outlet[i].V[2] - outlet[i].V[3]).len(); + stim::vec3 tmp = outlet[i].V[3]; + outlet[i].V.clear(); + outlet[i].V.push_back(tmp); + outlet[i].V.push_back(tmp_v); + } + else { + outlet[i].V.clear(); + outlet[i].V.push_back(tmp_v); + } outlet[i].l = new_l; n = find_number_square(origin_l, desire_l); -- libgit2 0.21.4