static HomogeneousCoordinate ProjectHomogeneousPoint(
const gfx::Transform& transform,
- gfx::PointF p) {
+ const gfx::PointF& p) {
// In this case, the layer we are trying to project onto is perpendicular to
// ray (point p and z-axis direction) that we are trying to project. This
// happens when the layer is rotated so that it is infinitesimally thin, or
float* xmax,
float* ymin,
float* ymax,
- gfx::PointF p) {
+ const gfx::PointF& p) {
*xmin = std::min(p.x(), *xmin);
*xmax = std::max(p.x(), *xmax);
*ymin = std::min(p.y(), *ymin);
*ymax = std::max(p.y(), *ymax);
}
-static inline void AddVertexToClippedQuad(gfx::PointF new_vertex,
+static inline void AddVertexToClippedQuad(const gfx::PointF& new_vertex,
gfx::PointF clipped_quad[8],
int* num_vertices_in_clipped_quad) {
clipped_quad[*num_vertices_in_clipped_quad] = new_vertex;
(*num_vertices_in_clipped_quad)++;
}
-gfx::Rect MathUtil::MapClippedRect(const gfx::Transform& transform,
- gfx::Rect src_rect) {
+gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform,
+ const gfx::Rect& src_rect) {
+ if (transform.IsIdentityOrIntegerTranslation()) {
+ return src_rect +
+ gfx::Vector2d(
+ static_cast<int>(SkMScalarToFloat(transform.matrix().get(0, 3))),
+ static_cast<int>(
+ SkMScalarToFloat(transform.matrix().get(1, 3))));
+ }
return gfx::ToEnclosingRect(MapClippedRect(transform, gfx::RectF(src_rect)));
}
return ComputeEnclosingClippedRect(hc0, hc1, hc2, hc3);
}
+gfx::Rect MathUtil::ProjectEnclosingClippedRect(const gfx::Transform& transform,
+ const gfx::Rect& src_rect) {
+ if (transform.IsIdentityOrIntegerTranslation()) {
+ return src_rect +
+ gfx::Vector2d(
+ static_cast<int>(SkMScalarToFloat(transform.matrix().get(0, 3))),
+ static_cast<int>(
+ SkMScalarToFloat(transform.matrix().get(1, 3))));
+ }
+ return gfx::ToEnclosingRect(
+ ProjectClippedRect(transform, gfx::RectF(src_rect)));
+}
+
gfx::RectF MathUtil::ProjectClippedRect(const gfx::Transform& transform,
const gfx::RectF& src_rect) {
if (transform.IsIdentityOrTranslation()) {
DCHECK_LE(*num_vertices_in_clipped_quad, 8);
}
-gfx::RectF MathUtil::ComputeEnclosingRectOfVertices(gfx::PointF vertices[],
- int num_vertices) {
+gfx::RectF MathUtil::ComputeEnclosingRectOfVertices(
+ const gfx::PointF vertices[],
+ int num_vertices) {
if (num_vertices < 2)
return gfx::RectF();
}
gfx::PointF MathUtil::MapPoint(const gfx::Transform& transform,
- gfx::PointF p,
+ const gfx::PointF& p,
bool* clipped) {
HomogeneousCoordinate h = MapHomogeneousPoint(transform, gfx::Point3F(p));
}
gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform,
- gfx::PointF p,
+ const gfx::PointF& p,
bool* clipped) {
HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p);
return gfx::Vector2dF(x_scale, y_scale);
}
-float MathUtil::SmallestAngleBetweenVectors(gfx::Vector2dF v1,
- gfx::Vector2dF v2) {
+float MathUtil::SmallestAngleBetweenVectors(const gfx::Vector2dF& v1,
+ const gfx::Vector2dF& v2) {
double dot_product = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length();
// Clamp to compensate for rounding errors.
dot_product = std::max(-1.0, std::min(1.0, dot_product));
return static_cast<float>(Rad2Deg(std::acos(dot_product)));
}
-gfx::Vector2dF MathUtil::ProjectVector(gfx::Vector2dF source,
- gfx::Vector2dF destination) {
+gfx::Vector2dF MathUtil::ProjectVector(const gfx::Vector2dF& source,
+ const gfx::Vector2dF& destination) {
float projected_length =
gfx::DotProduct(source, destination) / destination.LengthSquared();
return gfx::Vector2dF(projected_length * destination.x(),
projected_length * destination.y());
}
-scoped_ptr<base::Value> MathUtil::AsValue(gfx::Size s) {
+scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Size& s) {
scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
res->SetDouble("width", s.width());
res->SetDouble("height", s.height());
return res.PassAs<base::Value>();
}
-scoped_ptr<base::Value> MathUtil::AsValue(gfx::SizeF s) {
+scoped_ptr<base::Value> MathUtil::AsValue(const gfx::SizeF& s) {
scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
res->SetDouble("width", s.width());
res->SetDouble("height", s.height());
return res.PassAs<base::Value>();
}
-scoped_ptr<base::Value> MathUtil::AsValue(gfx::Rect r) {
+scoped_ptr<base::Value> MathUtil::AsValue(const gfx::Rect& r) {
scoped_ptr<base::ListValue> res(new base::ListValue());
res->AppendInteger(r.x());
res->AppendInteger(r.y());
return true;
}
-scoped_ptr<base::Value> MathUtil::AsValue(gfx::PointF pt) {
+scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) {
scoped_ptr<base::ListValue> res(new base::ListValue());
res->AppendDouble(pt.x());
res->AppendDouble(pt.y());
return res.PassAs<base::Value>();
}
+scoped_ptr<base::Value> MathUtil::AsValue(const gfx::BoxF& box) {
+ scoped_ptr<base::ListValue> res(new base::ListValue());
+ res->AppendInteger(box.x());
+ res->AppendInteger(box.y());
+ res->AppendInteger(box.z());
+ res->AppendInteger(box.width());
+ res->AppendInteger(box.height());
+ res->AppendInteger(box.depth());
+ return res.PassAs<base::Value>();
+}
+
scoped_ptr<base::Value> MathUtil::AsValueSafely(double value) {
return scoped_ptr<base::Value>(base::Value::CreateDoubleValue(
std::min(value, std::numeric_limits<double>::max())));