42 const std::vector<VGM::TwoVector>& vertices,
Arb8Split& split)
45 if (!(halfLength > 0.) || !std::isfinite(halfLength) ||
46 vertices.size() != 8) {
49 for (
const auto& vertex : vertices) {
50 if (!std::isfinite(vertex.first) || !std::isfinite(vertex.second)) {
58 double lowerBound = 0.;
59 double upperBound = 1.;
60 bool splitNeeded =
false;
61 for (
int i = 0; i < 4; ++i) {
62 const Vector2 bottom = Edge(vertices, 0, i);
63 const Vector2 top = Edge(vertices, 4, i);
64 const double bottom2 = Dot(bottom, bottom);
65 const double top2 = Dot(top, top);
68 if (bottom2 == 0. || top2 == 0.)
continue;
70 const double product = Dot(bottom, top);
71 if (product >= 0.)
continue;
74 lowerBound = std::max(lowerBound, -product / (top2 - product));
75 upperBound = std::min(upperBound, bottom2 / (bottom2 - product));
82 const double margin = 64. * std::numeric_limits<double>::epsilon();
83 if (!(upperBound - lowerBound > 2. * margin)) {
87 double fraction = 0.5;
88 if (fraction <= lowerBound + margin || fraction >= upperBound - margin) {
89 fraction = 0.5 * (lowerBound + upperBound);
92 std::vector<VGM::TwoVector> middle;
94 for (
int i = 0; i < 4; ++i) {
95 middle.emplace_back(vertices[i].first + fraction * (vertices[i + 4].first -
98 fraction * (vertices[i + 4].second - vertices[i].second));
110 split.
lowerVertices.end(), vertices.begin(), vertices.begin() + 4);
116 split.
upperVertices.end(), vertices.begin() + 4, vertices.end());
Arb8SplitResult SplitArb8ForGenericTrap(double halfLength, const std::vector< VGM::TwoVector > &vertices, Arb8Split &split)
Split an Arb8 whose corresponding end edges form angles greater than 90 degrees into two pieces accep...