Allow rotations when checking bounds of symbol parts.

This will be needed to determine the correct symbol size when there are symmetries.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@976 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-06-05 20:17:32 +00:00
parent 5ae7f6b3ab
commit 08a156c113
7 changed files with 36 additions and 20 deletions
+15 -13
View File
@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/rotation.hpp>
#include <gfx/bezier.hpp>
#include <gfx/polynomial.hpp>
@@ -93,20 +94,20 @@ void segment_subdivide(const ControlPoint& p0, const ControlPoint& p1, const Vec
// ----------------------------------------------------------------------------- : Bounds
void segment_bounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max) {
void segment_bounds(const Rotation& rot, const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max) {
assert(p1.segment_after == p2.segment_before);
if (p1.segment_after == SEGMENT_LINE) {
line_bounds (p1.pos, p2.pos, min, max);
line_bounds (rot, p1.pos, p2.pos, min, max);
} else {
bezier_bounds(p1, p2, min, max);
bezier_bounds(rot, p1, p2, min, max);
}
}
void bezier_bounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max) {
void bezier_bounds(const Rotation& rot, const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max) {
assert(p1.segment_after == SEGMENT_CURVE);
// First of all, the corners should be in the bounding box
point_bounds(p1.pos, min, max);
point_bounds(p2.pos, min, max);
point_bounds(rot, p1.pos, min, max);
point_bounds(rot, p2.pos, min, max);
// Solve the derivative of the bezier curve to find its extremes
// It's only a quadtratic equation :)
BezierCurve curve(p1,p2);
@@ -118,19 +119,20 @@ void bezier_bounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min
for (UInt i = 0 ; i < count ; ++i) {
double t = roots[i];
if (t >=0 && t <= 1) {
point_bounds(curve.pointAt(t), min, max);
point_bounds(rot, curve.pointAt(t), min, max);
}
}
}
void line_bounds(const Vector2D& p1, const Vector2D& p2, Vector2D& min, Vector2D& max) {
point_bounds(p1, min, max);
point_bounds(p2, min, max);
void line_bounds(const Rotation& rot, const Vector2D& p1, const Vector2D& p2, Vector2D& min, Vector2D& max) {
point_bounds(rot, p1, min, max);
point_bounds(rot, p2, min, max);
}
void point_bounds(const Vector2D& p, Vector2D& min, Vector2D& max) {
min = piecewise_min(min, p);
max = piecewise_max(max, p);
void point_bounds(const Rotation& rot, const Vector2D& p, Vector2D& min, Vector2D& max) {
Vector2D pr = rot.tr(p);
min = piecewise_min(min, pr);
max = piecewise_max(max, pr);
}
// Is a point inside the bounds <min...max>?
+6 -4
View File
@@ -18,6 +18,8 @@
#include <util/vector2d.hpp>
#include <data/symbol.hpp>
class Rotation;
// ----------------------------------------------------------------------------- : Evaluation
/// A bezier curve for evaluation
@@ -76,25 +78,25 @@ void segment_subdivide(const ControlPoint& p0, const ControlPoint& p1, const Vec
* min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger.
*/
void segment_bounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
void segment_bounds(const Rotation& rot, const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
/// Find a bounding box that fits a curve between p1 and p2, stores the results in min and max.
/** min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger
*/
void bezier_bounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
void bezier_bounds(const Rotation& rot, const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
/// Find a bounding box that fits around p1 and p2, stores the result in min and max
/** min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger
*/
void line_bounds(const Vector2D& p1, const Vector2D& p2, Vector2D& min, Vector2D& max);
void line_bounds(const Rotation& rot, const Vector2D& p1, const Vector2D& p2, Vector2D& min, Vector2D& max);
/// Find a bounding 'box' that fits around a single point
/** min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger
*/
void point_bounds(const Vector2D& p, Vector2D& min, Vector2D& max);
void point_bounds(const Rotation& rot, const Vector2D& p, Vector2D& min, Vector2D& max);
// ----------------------------------------------------------------------------- : Point tests