This source file includes following definitions.
- m_x2
- set
- intervalAt
- computeShapeMarginIntervals
- initializeBounds
- marginIntervals
- getExcludedIntervals
#include "config.h"
#include "core/rendering/shapes/RasterShape.h"
#include "wtf/MathExtras.h"
namespace WebCore {
class MarginIntervalGenerator {
public:
MarginIntervalGenerator(unsigned radius);
void set(int y, const IntShapeInterval&);
IntShapeInterval intervalAt(int y) const;
private:
Vector<int> m_xIntercepts;
int m_y;
int m_x1;
int m_x2;
};
MarginIntervalGenerator::MarginIntervalGenerator(unsigned radius)
: m_y(0)
, m_x1(0)
, m_x2(0)
{
m_xIntercepts.resize(radius + 1);
unsigned radiusSquared = radius * radius;
for (unsigned y = 0; y <= radius; y++)
m_xIntercepts[y] = sqrt(static_cast<double>(radiusSquared - y * y));
}
void MarginIntervalGenerator::set(int y, const IntShapeInterval& interval)
{
ASSERT(y >= 0 && interval.x1() >= 0);
m_y = y;
m_x1 = interval.x1();
m_x2 = interval.x2();
}
IntShapeInterval MarginIntervalGenerator::intervalAt(int y) const
{
unsigned xInterceptsIndex = abs(y - m_y);
int dx = (xInterceptsIndex >= m_xIntercepts.size()) ? 0 : m_xIntercepts[xInterceptsIndex];
return IntShapeInterval(m_x1 - dx, m_x2 + dx);
}
PassOwnPtr<RasterShapeIntervals> RasterShapeIntervals::computeShapeMarginIntervals(int shapeMargin) const
{
int marginIntervalsSize = (offset() > shapeMargin) ? size() : size() - offset() * 2 + shapeMargin * 2;
OwnPtr<RasterShapeIntervals> result = adoptPtr(new RasterShapeIntervals(marginIntervalsSize, std::max(shapeMargin, offset())));
MarginIntervalGenerator marginIntervalGenerator(shapeMargin);
for (int y = bounds().y(); y < bounds().maxY(); ++y) {
const IntShapeInterval& intervalAtY = intervalAt(y);
if (intervalAtY.isEmpty())
continue;
marginIntervalGenerator.set(y, intervalAtY);
int marginY0 = std::max(minY(), y - shapeMargin);
int marginY1 = std::min(maxY(), y + shapeMargin);
for (int marginY = y - 1; marginY >= marginY0; --marginY) {
if (marginY > bounds().y() && intervalAt(marginY).contains(intervalAtY))
break;
result->intervalAt(marginY).unite(marginIntervalGenerator.intervalAt(marginY));
}
result->intervalAt(y).unite(marginIntervalGenerator.intervalAt(y));
for (int marginY = y + 1; marginY <= marginY1; ++marginY) {
if (marginY < bounds().maxY() && intervalAt(marginY).contains(intervalAtY))
break;
result->intervalAt(marginY).unite(marginIntervalGenerator.intervalAt(marginY));
}
}
result->initializeBounds();
return result.release();
}
void RasterShapeIntervals::initializeBounds()
{
m_bounds = IntRect();
for (int y = minY(); y < maxY(); ++y) {
const IntShapeInterval& intervalAtY = intervalAt(y);
if (intervalAtY.isEmpty())
continue;
m_bounds.unite(IntRect(intervalAtY.x1(), y, intervalAtY.width(), 1));
}
}
const RasterShapeIntervals& RasterShape::marginIntervals() const
{
ASSERT(shapeMargin() >= 0);
if (!shapeMargin())
return *m_intervals;
int shapeMarginInt = clampToPositiveInteger(ceil(shapeMargin()));
int maxShapeMarginInt = std::max(m_marginRectSize.width(), m_marginRectSize.height()) * sqrtf(2);
if (!m_marginIntervals)
m_marginIntervals = m_intervals->computeShapeMarginIntervals(std::min(shapeMarginInt, maxShapeMarginInt));
return *m_marginIntervals;
}
void RasterShape::getExcludedIntervals(LayoutUnit logicalTop, LayoutUnit logicalHeight, SegmentList& result) const
{
const RasterShapeIntervals& intervals = marginIntervals();
if (intervals.isEmpty())
return;
int y1 = logicalTop;
int y2 = logicalTop + logicalHeight;
ASSERT(y2 >= y1);
if (y2 < intervals.bounds().y() || y1 >= intervals.bounds().maxY())
return;
y1 = std::max(y1, intervals.bounds().y());
y2 = std::min(y2, intervals.bounds().maxY());
IntShapeInterval excludedInterval;
for (int y = y1; y < y2; y++)
excludedInterval.unite(intervals.intervalAt(y));
result.append(LineSegment(excludedInterval.x1(), excludedInterval.x2() + 1));
}
}