20 #ifndef GNASH_GEOMETRY_H
21 #define GNASH_GEOMETRY_H
58 Edge(boost::int32_t cx, boost::int32_t cy, boost::int32_t ax,
93 boost::int32_t dx = B.
x - A.
x;
94 boost::int32_t dy = B.
y - A.
y;
96 if ( dx == 0 && dy == 0 )
101 boost::int32_t pdx = p.
x - A.
x;
102 boost::int32_t pdy = p.
y - A.
y;
104 double u = (
static_cast<double>(pdx) * dx + static_cast<double>(pdy) * dy ) /
105 (static_cast<double>(dx)*dx +
static_cast<double>(dy)*dy );
126 return std::sqrt(square);
196 reset(0, 0, 0, 0, 0);
201 m_fill0(from.m_fill0),
202 m_fill1(from.m_fill1),
205 m_edges(from.m_edges)
231 Path(boost::int32_t ax, boost::int32_t ay,
232 unsigned fill0,
unsigned fill1,
unsigned line)
234 reset(ax, ay, fill0, fill1, line);
254 void reset(boost::int32_t ax, boost::int32_t ay,
255 unsigned fill0,
unsigned fill1,
unsigned line)
284 const Path&
p = *
this;
285 size_t nedges = m_edges.size();
287 if ( ! nedges )
return;
294 unsigned int radius = swfVersion < 8 ? thickness : thickness/2;
297 for (
unsigned int j = 0;
j<nedges;
j++)
306 for (
unsigned int j = 0;
j<nedges;
j++)
333 m_edges.push_back(
Edge(dx, dy, dx, dy));
354 drawCurveTo(boost::int32_t cdx, boost::int32_t cdy, boost::int32_t adx, boost::int32_t ady)
356 m_edges.push_back(
Edge(cdx, cdy, adx, ady));
363 m_fill0 = m_fill1 = m_line = 0;
372 if (m_edges.empty())
return true;
373 return m_edges.back().ap == ap;
379 if ( m_edges.empty() )
return;
382 const Edge& lastedge = m_edges.back();
383 if ( lastedge.
ap != ap )
385 Edge newedge(ap, ap);
386 m_edges.push_back(newedge);
399 size_t nedges = m_edges.size();
401 if ( ! nedges )
return false;
404 for (
size_t i=0;
i<nedges; ++
i)
406 const Edge&
e = m_edges[
i];
412 if ( d <= dist )
return true;
430 for (
int i=1;
i<=segCount; ++
i)
432 float t1 =
static_cast<float>(
i) / segCount;
438 if ( d <= dist )
return true;
453 std::vector<Edge>::iterator it = m_edges.begin(), ie = m_edges.end();
454 for(; it != ie; ++it)
456 (*it).transform(mat);
463 return m_edges.empty();
526 return m_edges.size();
536 const Edge& operator[] (
size_t n)
const
545 bool pointTest(
const std::vector<Path>& paths,
546 const std::vector<LineStyle>& lineStyles, boost::int32_t
x,
547 boost::int32_t
y,
const SWFMatrix& wm);
554 #endif // GNASH_GEOMETRY_H
void drawLineTo(boost::int32_t dx, boost::int32_t dy)
Draw a straight line.
Definition: Geometry.h:331
Edge()
Definition: Geometry.h:52
bool withinSquareDistance(const point &p, double dist) const
Return true if the given point is within the given squared distance from this path edges...
Definition: Geometry.h:397
static double squareDistancePtSeg(const point &p, const point &A, const point &B)
Return squared distance between point pt and segment A-B.
Definition: Geometry.h:91
void expandBounds(SWFRect &r, unsigned int thickness, int swfVersion) const
Expand given SWFRect to include bounds of this path.
Definition: Geometry.h:282
void expand_to_circle(boost::int32_t x, boost::int32_t y, boost::int32_t radius)
Expand this rectangle to enclose the given circle.
Definition: SWFRect.h:186
Definition: GnashKey.h:150
void expand_to_point(boost::int32_t x, boost::int32_t y)
Expand this rectangle to enclose the given point.
Definition: SWFRect.h:171
bool isClosed() const
Returns true if the last and the first point of the path match.
Definition: Geometry.h:370
bool pointTest(const std::vector< Path > &paths, const std::vector< LineStyle > &lineStyles, boost::int32_t x, boost::int32_t y, const SWFMatrix &wm)
Definition: Geometry.cpp:125
boost::int32_t x
The x coordinate.
Definition: Point2d.h:43
Edge(const Edge &from)
Definition: Geometry.h:65
Path(const Path &from)
Definition: Geometry.h:199
Path(boost::int32_t ax, boost::int32_t ay, unsigned fill0, unsigned fill1, unsigned line)
Initialize a path.
Definition: Geometry.h:231
void reset(boost::int32_t ax, boost::int32_t ay, unsigned fill0, unsigned fill1, unsigned line)
Re-initialize a path, maintaining the "new shape" flag untouched.
Definition: Geometry.h:254
void transform(const SWFMatrix &mat)
Transform the edge according to the given SWFMatrix.
Definition: Geometry.h:83
Definition: SWFMatrix.h:53
Definition: GnashKey.h:114
Edge(const point &ncp, const point &nap)
Definition: Geometry.h:71
Definition: GnashKey.h:167
point cp
Definition: Geometry.h:49
unsigned getLeftFill() const
Definition: Geometry.h:480
void drawCurveTo(boost::int32_t cdx, boost::int32_t cdy, boost::int32_t adx, boost::int32_t ady)
Draw a curve.
Definition: Geometry.h:354
unsigned getLineStyle() const
Definition: Geometry.h:518
2D Point class
Definition: Point2d.h:38
Definition: GnashKey.h:152
void transform(const SWFMatrix &mat)
Transform all path coordinates according to the given SWFMatrix.
Definition: Geometry.h:450
Definition: GnashKey.h:115
Edge(boost::int32_t cx, boost::int32_t cy, boost::int32_t ax, boost::int32_t ay)
Definition: Geometry.h:58
Definition: GnashKey.h:156
static double distancePtSeg(const point &pt, const point &A, const point &B)
Return distance between point pt and segment A-B.
Definition: Geometry.h:123
Definition: GnashKey.h:160
Definition: GnashKey.h:164
void setLeftFill(unsigned f)
Set the fill to use on the left side.
Definition: Geometry.h:475
Definition: GnashKey.h:166
unsigned m_fill1
Right fill style index (1-based)
Definition: Geometry.h:173
static point pointOnCurve(const point &A, const point &C, const point &B, float t)
Find point of the quadratic curve defined by points A,C,B.
Definition: Geometry.h:137
A subset of a shape, a series of edges sharing a single set of styles.
Definition: Geometry.h:166
unsigned m_fill0
Left fill style index (1-based)
Definition: Geometry.h:170
std::vector< Edge > m_edges
Edges forming the path.
Definition: Geometry.h:182
boost::int32_t x
Definition: BitmapData_as.cpp:434
Definition: GnashKey.h:130
#define DSOEXPORT
Definition: dsodefs.h:55
void setLineStyle(unsigned i)
Set the line style to use for this path.
Definition: Geometry.h:513
unsigned m_line
Line style index (1-based)
Definition: Geometry.h:176
boost::int32_t y
Definition: BitmapData_as.cpp:435
size_t size() const
Return the number of edges in this path.
Definition: Geometry.h:524
Dist dist
Definition: BitmapData_as.cpp:198
bool empty() const
Return true if this path contains no edges.
Definition: Geometry.h:461
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
void transform(geometry::Point2d &p) const
Transform a given point by our SWFMatrix.
Definition: SWFMatrix.cpp:99
Definition: GnashKey.h:162
Definition: GnashKey.h:155
Definition: GnashKey.h:151
Defines an edge with a control point and an anchor point.
Definition: Geometry.h:44
void clear()
Remove all edges and reset style infomation.
Definition: Geometry.h:360
Point2d & setTo(const boost::int32_t cx, const boost::int32_t cy)
Set coordinates to given values.
Definition: Point2d.h:79
static boost::int64_t squareDistance(const Point2d &p0, const Point2d &p1)
Return square distance between two given points.
Definition: Point2d.h:103
point ap
Definition: Geometry.h:50
Definition: GnashKey.h:113
bool straight() const
Definition: Geometry.h:77
unsigned getRightFill() const
Definition: Geometry.h:499
boost::int32_t y
The y coordinate.
Definition: Point2d.h:46
static boost::int64_t squareDistancePtCurve(const point &A, const point &C, const point &B, const point &p, float t)
Definition: Geometry.h:155
point ap
Start point of the path.
Definition: Geometry.h:179
Path()
Default constructor.
Definition: Geometry.h:194
void close()
Close this path with a straight line, if not already closed.
Definition: Geometry.h:377
void setRightFill(unsigned f)
Set the fill to use on the left side.
Definition: Geometry.h:494