void mgnear::beziersBox( Box2d& box, int count, const Point2d* points, bool closed) { box.empty(); for (int i = 0; i + 3 < count; i += 3) { box.unionWith(computeCubicBox(points + i)); } if (closed && count > 3) { box.unionWith(computeCubicBox(points[count - 1], points[count - 1] * 2 - points[count - 2].asVector(), points[0] * 2 - points[1].asVector(), points[0])); } }
Box2d MgShapeDoc::getExtent() const { Box2d rect; for (unsigned i = 0; i < im->layers.size(); i++) { rect.unionWith(im->layers[i]->getExtent()); } return rect; }
Box2d calcButtonPosition(mgvector<float>& pos, int n, const Box2d& selbox) { Box2d rect; for (int i = 0; i < n; i++) { switch (i) { case 0: if (n == 1) { pos.set(2 * i, selbox.center().x, selbox.ymin); // MT } else { pos.set(2 * i, selbox.xmin, selbox.ymin); // LT } break; case 1: if (n == 3) { pos.set(2 * i, selbox.center().x, selbox.ymin); // MT } else { pos.set(2 * i, selbox.xmax, selbox.ymin); // RT } break; case 2: if (n == 3) { pos.set(2 * i, selbox.xmax, selbox.ymin); // RT } else { pos.set(2 * i, selbox.xmax, selbox.ymax); // RB } break; case 3: pos.set(2 * i, selbox.xmin, selbox.ymax); // LB break; case 4: pos.set(2 * i, selbox.center().x, selbox.ymin); // MT break; case 5: pos.set(2 * i, selbox.center().x, selbox.ymax); // MB break; case 6: pos.set(2 * i, selbox.xmax, selbox.center().y); // RM break; case 7: pos.set(2 * i, selbox.xmin, selbox.center().y); // LM break; default: return rect; } rect.unionWith(Box2d(Point2d(pos.get(2 * i), pos.get(2 * i + 1)), 32, 32)); } return rect; }
void mgnear::cubicSplinesBox( Box2d& box, int n, const Point2d* knots, const Vector2d* knotvs, bool closed, bool hermite) { int n2 = (closed && n > 1) ? n + 1 : n; float d = hermite ? 1.f/3.f : 1.f; box.empty(); for (int i = 0; i + 1 < n2; i++) { box.unionWith(computeCubicBox(knots[i], knots[i] + knotvs[i] * d, knots[(i + 1) % n] - knotvs[(i + 1) % n] * d, knots[(i + 1) % n])); } }