This source file includes following definitions.
- ellipseXIntercept
- shapeMarginBounds
- getExcludedIntervals
#include "config.h"
#include "core/rendering/shapes/RectangleShape.h"
#include "wtf/MathExtras.h"
namespace WebCore {
static inline float ellipseXIntercept(float y, float rx, float ry)
{
ASSERT(ry > 0);
return rx * sqrt(1 - (y * y) / (ry * ry));
}
FloatRect RectangleShape::shapeMarginBounds() const
{
ASSERT(shapeMargin() >= 0);
if (!shapeMargin())
return m_bounds;
float boundsX = x() - shapeMargin();
float boundsY = y() - shapeMargin();
float boundsWidth = width() + shapeMargin() * 2;
float boundsHeight = height() + shapeMargin() * 2;
return FloatRect(boundsX, boundsY, boundsWidth, boundsHeight);
}
void RectangleShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
{
const FloatRect& bounds = shapeMarginBounds();
if (bounds.isEmpty())
return;
float y1 = logicalTop.toFloat();
float y2 = (logicalTop + logicalHeight).toFloat();
if (y2 < bounds.y() || y1 >= bounds.maxY())
return;
float x1 = bounds.x();
float x2 = bounds.maxX();
float marginRadiusX = rx() + shapeMargin();
float marginRadiusY = ry() + shapeMargin();
if (marginRadiusY > 0) {
if (y2 < bounds.y() + marginRadiusY) {
float yi = y2 - bounds.y() - marginRadiusY;
float xi = ellipseXIntercept(yi, marginRadiusX, marginRadiusY);
x1 = bounds.x() + marginRadiusX - xi;
x2 = bounds.maxX() - marginRadiusX + xi;
} else if (y1 > bounds.maxY() - marginRadiusY) {
float yi = y1 - (bounds.maxY() - marginRadiusY);
float xi = ellipseXIntercept(yi, marginRadiusX, marginRadiusY);
x1 = bounds.x() + marginRadiusX - xi;
x2 = bounds.maxX() - marginRadiusX + xi;
}
}
result.append(LineSegment(x1, x2));
}
}