// JL rewrote to handle transformed case GRectangle GCompound::getBounds() const { double x1, y1, x2, y2; x1 = 1E20; x2 = -1E20; y1 = 1E20; y2 = -1E20; for (int i = 0; i < contents.size(); i++) { GRectangle bounds = contents.get(i)->getBounds(); GPoint vertices[4]; vertices[0] = GPoint(bounds.getX(), bounds.getY()); vertices[1] = GPoint(bounds.getX() + bounds.getWidth(), bounds.getY()); vertices[2] = GPoint(bounds.getX(), bounds.getY() + bounds.getHeight()); vertices[3] = GPoint(bounds.getX()+ bounds.getWidth(), bounds.getY() + bounds.getHeight()); if (transformed) { for (int j = 0; j < 4; j++) vertices[j] = matrix.image(vertices[j]); } for (int j = 0; j < 4; j++) { double x = vertices[j].getX(); double y = vertices[j].getY(); if (x < x1) x1 = x; if (y < y1) y1 = y; if (x > x2) x2 = x; if (y > y2) y2 = y; } } return GRectangle(x + x1, y + y1, x2 - x1, y2 - y1); }
GRectangle GOval::getBounds() const { if (transformed) { return stanfordcpplib::getPlatform()->gobject_getBounds(this); } else { return GRectangle(x, y, width, height); } }
GRectangle GArc::getBounds() const { if (transformed) { return stanfordcpplib::getPlatform()->gobject_getBounds(this); } double rx = frameWidth / 2; double ry = frameHeight / 2; double cx = x + rx; double cy = y + ry; double startRadians = start * PI / 180; double sweepRadians = sweep * PI / 180; double p1x = cx + cos(startRadians) * rx; double p1y = cy - sin(startRadians) * ry; double p2x = cx + cos(startRadians + sweepRadians) * rx; double p2y = cy - sin(startRadians + sweepRadians) * ry; double xMin = std::min(p1x, p2x); double xMax = std::max(p1x, p2x); double yMin = std::min(p1y, p2y); double yMax = std::max(p1y, p2y); if (containsAngle(0)) xMax = cx + rx; if (containsAngle(90)) yMin = cy - ry; if (containsAngle(180)) xMin = cx - rx; if (containsAngle(270)) yMax = cy + ry; if (isFilled()) { xMin = std::min(xMin, cx); yMin = std::min(yMin, cy); xMax = std::max(xMax, cx); yMax = std::max(yMax, cy); } return GRectangle(xMin, yMin, xMax - xMin, yMax - yMin); }
GRectangle GLine::getBounds() const { if (transformed) { return stanfordcpplib::getPlatform()->gobject_getBounds(this); } double x0 = (dx < 0) ? x + dx : x; double y0 = (dy < 0) ? y + dy : y; return GRectangle(x0, y0, std::fabs(dx), std::fabs(dy)); }
// JL rewrote to handle transformed case GRectangle GLabel::getBounds() const { if (!transformed) return GRectangle(x, y - ascent, width, height); GPoint vertices[4]; vertices[0] = matrix.image(0, -ascent); vertices[1] = matrix.image(0, -ascent + height); vertices[2] = matrix.image(width, -ascent + height); vertices[3] = matrix.image(width, -ascent); double x1, y1, x2, y2; for (int i = 0; i < 4; i++) { double x = vertices[i].getX(); double y = vertices[i].getY(); if (i == 0 || x < x1) x1 = x; if (i == 0 || y < y1) y1 = y; if (i == 0 || x > x2) x2 = x; if (i == 0 || y > y2) y2 = y; } return GRectangle(x + x1, y + y1, x2 - x1, y2 - y1); }
// JL rewrote to handle transformed case GRectangle GImage::getBounds() const { if (!transformed) return GRectangle(x, y, width, height); GPoint vertices[4]; vertices[0] = GPoint(0, 0); // unused! vertices[1] = matrix.image(0, height); vertices[2] = matrix.image(width, height); vertices[3] = matrix.image(width, 0); double x1, y1, x2, y2; x1 = x2 = y1 = y2 = 0; for (int i = 1; i < 4; i++) { double x = vertices[i].getX(); double y = vertices[i].getY(); if (x < x1) x1 = x; if (y < y1) y1 = y; if (x > x2) x2 = x; if (y > y2) y2 = y; } return GRectangle(this->x + x1, this->y + y1, x2 - x1, y2 - y1); }
// JL rewrote to include transformed case in front end GRectangle GLine::getBounds() const { double tdx = dx; double tdy = dy; if (transformed) { GPoint pt = matrix.image(dx, dy); tdx = pt.getX(); tdy = pt.getY(); } double x0 = (tdx < 0) ? x + tdx : x; double y0 = (tdy < 0) ? y + tdy : y; return GRectangle(x0, y0, abs(tdx), abs(tdy)); }
GRectangle GCompound::getBounds() const { if (transformed) return pp->getBounds(this); double xMin = +1E20; double yMin = +1E20; double xMax = -1E20; double yMax = -1E20; for (int i = 0; i < contents.size(); i++) { GRectangle bounds = contents.get(i)->getBounds(); xMin = min(xMin, bounds.getX()); yMin = min(yMin, bounds.getY()); xMax = max(xMax, bounds.getX()); yMin = min(yMax, bounds.getY()); } return GRectangle(xMin, yMin, xMax - xMin, yMax - yMin); }
GRectangle GPolygon::getBounds() const { if (transformed) return pp->getBounds(this); double xMin = 0; double yMin = 0; double xMax = 0; double yMax = 0; for (int i = 0; i < vertices.size(); i++) { double x = vertices[i].getX(); double y = vertices[i].getY(); if (i == 0 || x < xMin) xMin = x; if (i == 0 || y < yMin) yMin = y; if (i == 0 || x > xMax) xMax = x; if (i == 0 || y > yMax) yMax = y; } return GRectangle(xMin, yMin, xMax - xMin, yMax - yMin); }
GRectangle GCompound::getBounds() const { if (transformed) { return stanfordcpplib::getPlatform()->gobject_getBounds(this); } double xMin = +1E20; double yMin = +1E20; double xMax = -1E20; double yMax = -1E20; for (int i = 0; i < contents.size(); i++) { GRectangle bounds = contents.get(i)->getBounds(); xMin = std::min(xMin, bounds.getX()); yMin = std::min(yMin, bounds.getY()); xMax = std::max(xMax, bounds.getX()); yMin = std::max(yMax, bounds.getY()); // JL BUGFIX 2016/10/11 } // JL BUGFIX: shifted anchor point return GRectangle(xMin + getX(), yMin + getY(), xMax - xMin, yMax - yMin); }
GRectangle GPolygon::getBounds() const { if (transformed) { return stanfordcpplib::getPlatform()->gobject_getBounds(this); } double xMin = 0; double yMin = 0; double xMax = 0; double yMax = 0; for (int i = 0; i < vertices.size(); i++) { double x = vertices[i].getX(); double y = vertices[i].getY(); if (i == 0 || x < xMin) xMin = x; if (i == 0 || y < yMin) yMin = y; if (i == 0 || x > xMax) xMax = x; if (i == 0 || y > yMax) yMax = y; } // JL BUGFIX: add getX, getY return GRectangle(xMin + getX(), yMin + getY(), xMax - xMin, yMax - yMin); }
// JL added code to handle transformed case GRectangle GPolygon::getBounds() const { double xMin = 0; double yMin = 0; double xMax = 0; double yMax = 0; double x0 = getX(); double y0 = getY(); for (int i = 0; i < vertices.size(); i++) { double x = vertices[i].getX(); double y = vertices[i].getY(); if (transformed) { GPoint pt = matrix.image(x, y); x = pt.getX(); y = pt.getY(); } if (i == 0 || x < xMin) xMin = x; if (i == 0 || y < yMin) yMin = y; if (i == 0 || x > xMax) xMax = x; if (i == 0 || y > yMax) yMax = y; } return GRectangle(xMin + x0, yMin + y0, xMax - xMin, yMax - yMin); // BUGFIX (JL): Must translate by x0, y0. }
GRectangle GLine::getBounds() const { if (transformed) return pp->getBounds(this); double x0 = (dx < 0) ? x + dx : x; double y0 = (dy < 0) ? y + dy : y; return GRectangle(x0, y0, abs(dx), abs(dy)); }
GRectangle GInteractor::getBounds() const { GDimension size = getPlatform()->ginteractor_getSize((GObject *) this); return GRectangle(x, y, size.getWidth(), size.getHeight()); }
GRectangle GImage::getBounds() const { if (transformed) return pp->getBounds(this); return GRectangle(x, y, width, height); }
GRectangle GArc::getFrameRectangle() const { return GRectangle(0, 0, 0, 0); }
GRectangle GLabel::getBounds() const { if (transformed) return pp->getBounds(this); return GRectangle(x, y - ascent, width, height); }
GRectangle GLabel::getBounds() const { if (transformed) { return stanfordcpplib::getPlatform()->gobject_getBounds(this); } return GRectangle(x, y - ascent, width, height); }
GRectangle GBufferedImage::getBounds() const { return GRectangle(x, y, m_width, m_height); }