mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Fabric: Applying a transformation matrix to a point
Summary: The diff implements a function that applies given transformation to a point. Reviewed By: JoshuaGross Differential Revision: D15219263 fbshipit-source-id: 4cc0595b0dda38c1ede1f2885b800cbe57f54243
This commit is contained in:
committed by
Facebook Github Bot
parent
0e35406e4e
commit
40bf82898f
@@ -149,5 +149,31 @@ Transform Transform::operator*(Transform const &rhs) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
Float &Transform::at(int i, int j) {
|
||||
return matrix[(i * 4) + j];
|
||||
}
|
||||
|
||||
Float const &Transform::at(int i, int j) const {
|
||||
return matrix[(i * 4) + j];
|
||||
}
|
||||
|
||||
Point operator*(Point const &point, Transform const &transform) {
|
||||
if (transform == Transform::Identity()) {
|
||||
return point;
|
||||
}
|
||||
|
||||
auto result = Point{};
|
||||
result.x = transform.at(3, 0) + point.x * transform.at(0, 0) + point.y * transform.at(1, 0);
|
||||
result.y = transform.at(3, 1) + point.x * transform.at(0, 1) + point.y * transform.at(1, 1);
|
||||
auto w = transform.at(3, 3) + point.x * transform.at(0, 3) + point.y * transform.at(1, 3);
|
||||
|
||||
if (w != 1 && w != 0) {
|
||||
result.x /= w;
|
||||
result.y /= w;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <folly/Hash.h>
|
||||
#include <react/graphics/Float.h>
|
||||
#include <react/graphics/Geometry.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -59,12 +60,23 @@ struct Transform {
|
||||
bool operator==(Transform const &rhs) const;
|
||||
bool operator!=(Transform const &rhs) const;
|
||||
|
||||
/*
|
||||
* Matrix subscript.
|
||||
*/
|
||||
Float &at(int x, int y);
|
||||
Float const &at(int x, int y) const;
|
||||
|
||||
/*
|
||||
* Concatenates (multiplies) transform matrices.
|
||||
*/
|
||||
Transform operator*(Transform const &rhs) const;
|
||||
};
|
||||
|
||||
/*
|
||||
* Applies tranformation to the given point.
|
||||
*/
|
||||
Point operator*(Point const &point, Transform const &transform);
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
|
||||
Reference in New Issue
Block a user