Remove unused center control point for color ellipses.

This commit is contained in:
Tats
2014-03-02 21:07:11 -05:00
parent 5de7162a59
commit d0e697d77a
3 changed files with 23 additions and 20 deletions
+11 -16
View File
@@ -419,7 +419,8 @@ void Ellipse::setVertex(int i, const QPointF& v)
// Set vertices.
Shape::setVertex(1, transform.map( getVertex(1) ));
Shape::setVertex(3, transform.map( getVertex(3) ));
Shape::setVertex(4, transform.map( getVertex(4) ));
if (hasCenterControl())
Shape::setVertex(4, transform.map( getVertex(4) ));
}
// If changed one of the two other points, just change the vertical axis.
@@ -459,25 +460,19 @@ void Ellipse::setVertex(int i, const QPointF& v)
transform *= fromUnitCircle();
// Set vertices.
Shape::setVertex(4, transform.map( getVertex(4) ));
if (hasCenterControl())
Shape::setVertex(4, transform.map( getVertex(4) ));
}
// Center control point (make sure it stays inside!).
else
else if (hasCenterControl())
{
if (includesPoint(v))
Shape::setVertex(i, v);
// Map point as vector on a unit circle.
QVector2D vector(toUnitCircle().map(v));
else
{
// Map point as vector on a unit circle.
QVector2D vector(toUnitCircle().map(v));
// Normalize it.
vector.normalize();
// Remap it to ellipse.
Shape::setVertex(4, fromUnitCircle().map(vector.toPointF()));
}
// Clip control point.
Shape::setVertex(4, vector.length() <= 1 ?
v :
fromUnitCircle().map(vector.toPointF()));
}
}
+8 -2
View File
@@ -213,13 +213,14 @@ protected:
class Ellipse : public Shape {
public:
Ellipse() {}
Ellipse(QPointF p1, QPointF p2, QPointF p3, QPointF p4)
Ellipse(QPointF p1, QPointF p2, QPointF p3, QPointF p4, bool hasCenterControl=true)
{
_addVertex(p1);
_addVertex(p2);
_addVertex(p3);
_addVertex(p4);
_addVertex(getCenter()); // add a point in the center
if (hasCenterControl)
_addVertex(getCenter()); // add a point in the center
}
virtual ~Ellipse() {}
@@ -234,6 +235,10 @@ public:
return radiansToDegrees( getRotationRadians() );
}
bool hasCenterControl() const {
return (nVertices() == 5);
}
// QRect getBoundingRect() const {
// return QRect(0, getVerticalAxis().manhattanLength(),
// getHorizontalAxis().manhattanLength(), getVerticalAxis().manhattanLength());
@@ -264,6 +269,7 @@ public:
/// Remaps point from circle with radius 1 set at origin (0,0) to ellipse coordinates.
QTransform fromUnitCircle() const;
/** Return true if Shape includes point (x,y), false otherwise
* Algorithm should work for all polygons, including non-convex
* Found at http://www.cs.tufts.edu/comp/163/notes05/point_inclusion_handout.pdf
+4 -2
View File
@@ -99,7 +99,8 @@ Ellipse* createEllipseForTexture(Texture* texture, int frameWidth,
QPointF(texture->getX(), texture->getY() + halfHeight),
QPointF(texture->getX() + halfWidth, texture->getY()),
QPointF(texture->getX() + texture->getWidth(), texture->getY() + halfHeight),
QPointF(texture->getX() + halfWidth, texture->getY() + texture->getHeight())
QPointF(texture->getX() + halfWidth, texture->getY() + texture->getHeight()),
true
);
}
@@ -130,7 +131,8 @@ Ellipse* createEllipseForColor(int frameWidth, int frameHeight)
QPointF(frameWidth / 4, frameHeight / 2),
QPointF(frameWidth / 2, frameHeight / 4),
QPointF(frameWidth * 3 / 4, frameHeight / 2),
QPointF(frameWidth / 2, frameHeight * 3 / 4)
QPointF(frameWidth / 2, frameHeight * 3 / 4),
false
);
}