Go to the documentation of this file.
20 #ifndef GNASH_GEOMETRY_H
21 #define GNASH_GEOMETRY_H
58 constexpr
Edge(std::int32_t cx, std::int32_t cy, std::int32_t ax,
93 std::int32_t dx =
B.x -
A.x;
94 std::int32_t dy =
B.y -
A.y;
96 if ( dx == 0 && dy == 0 )
98 return p.squareDistance(
A);
101 std::int32_t pdx =
p.x -
A.x;
102 std::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 );
109 return p.squareDistance(
A);
114 return p.squareDistance(
B);
118 return p.squareDistance(px);
126 return std::sqrt(square);
193 reset(0, 0, 0, 0, 0);
198 m_fill0(from.m_fill0),
199 m_fill1(from.m_fill1),
202 m_edges(from.m_edges)
225 Path(std::int32_t ax, std::int32_t ay,
226 unsigned fill0,
unsigned fill1,
unsigned line)
228 reset(ax, ay, fill0, fill1, line);
248 void reset(std::int32_t ax, std::int32_t ay,
249 unsigned fill0,
unsigned fill1,
unsigned line)
278 const Path&
p = *
this;
279 size_t nedges = m_edges.size();
281 if ( ! nedges )
return;
288 unsigned int radius = swfVersion < 8 ? thickness : thickness/2;
290 r.expand_to_circle(ap.
x, ap.
y, radius);
291 for (
unsigned int j = 0;
j<nedges;
j++)
293 r.expand_to_circle(m_edges[
j].ap.
x, m_edges[
j].ap.y, radius);
294 r.expand_to_circle(m_edges[
j].cp.x, m_edges[
j].cp.y, radius);
299 r.expand_to_point(ap.
x, ap.
y);
300 for (
unsigned int j = 0;
j<nedges;
j++)
302 r.expand_to_point(m_edges[
j].ap.
x,
p.m_edges[
j].ap.y);
303 r.expand_to_point(m_edges[
j].cp.x,
p.m_edges[
j].cp.y);
327 m_edges.emplace_back(dx, dy, dx, dy);
348 drawCurveTo(std::int32_t cdx, std::int32_t cdy, std::int32_t adx, std::int32_t ady)
350 m_edges.emplace_back(cdx, cdy, adx, ady);
357 m_fill0 = m_fill1 = m_line = 0;
366 if (m_edges.empty())
return true;
367 return m_edges.back().ap == ap;
373 if ( m_edges.empty() )
return;
376 const Edge& lastedge = m_edges.back();
377 if ( lastedge.
ap != ap )
379 m_edges.emplace_back(ap, ap);
392 size_t nedges = m_edges.size();
394 if ( ! nedges )
return false;
397 for (
size_t i=0;
i<nedges; ++
i)
399 const Edge&
e = m_edges[
i];
405 if (
d <= dist )
return true;
423 for (
int i=1;
i<=segCount; ++
i)
425 float t1 =
static_cast<float>(
i) / segCount;
431 if (
d <= dist )
return true;
446 std::vector<Edge>::iterator it = m_edges.begin(), ie = m_edges.end();
447 for(; it != ie; ++it)
449 (*it).transform(mat);
456 return m_edges.empty();
519 return m_edges.size();
529 const Edge& operator[] (
size_t n)
const
538 bool pointTest(
const std::vector<Path>& paths,
539 const std::vector<LineStyle>& lineStyles, std::int32_t
x,
540 std::int32_t
y,
const SWFMatrix& wm);
547 #endif // GNASH_GEOMETRY_H
constexpr Edge(std::int32_t cx, std::int32_t cy, std::int32_t ax, std::int32_t ay)
Definition: Geometry.h:58
@ R
Definition: GnashKey.h:130
Path(std::int32_t ax, std::int32_t ay, unsigned fill0, unsigned fill1, unsigned line)
Initialize a path.
Definition: Geometry.h:225
point ap
Start point of the path.
Definition: Geometry.h:179
size_t size() const
Return the number of edges in this path.
Definition: Geometry.h:517
Path(const Path &from)
Definition: Geometry.h:196
void transform(const SWFMatrix &mat)
Transform the edge according to the given SWFMatrix.
Definition: Geometry.h:83
@ d
Definition: GnashKey.h:150
unsigned getLineStyle() const
Definition: Geometry.h:511
point ap
Definition: Geometry.h:50
@ T
Definition: GnashKey.h:132
unsigned getLeftFill() const
Definition: Geometry.h:473
std::int32_t y
Definition: BitmapData_as.cpp:435
@ i
Definition: GnashKey.h:155
#define LOG_ONCE(x)
Definition: log.h:49
bool empty() const
Return true if this path contains no edges.
Definition: Geometry.h:454
#define _(String)
Definition: log.h:44
bool straight() const
Definition: Geometry.h:77
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
static std::int64_t squareDistancePtCurve(const point &A, const point &C, const point &B, const point &p, float t)
Definition: Geometry.h:155
void close()
Close this path with a straight line, if not already closed.
Definition: Geometry.h:371
void setRightFill(unsigned f)
Set the fill to use on the left side.
Definition: Geometry.h:487
@ n
Definition: GnashKey.h:160
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:390
void setLeftFill(unsigned f)
Set the fill to use on the left side.
Definition: Geometry.h:468
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:45
unsigned m_line
Line style index (1-based)
Definition: Geometry.h:176
@ t
Definition: GnashKey.h:166
@ r
Definition: GnashKey.h:164
unsigned getRightFill() const
Definition: Geometry.h:492
std::int32_t x
The x coordinate.
Definition: Point2d.h:43
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
void drawLineTo(std::int32_t dx, std::int32_t dy)
Draw a straight line.
Definition: Geometry.h:325
bool isClosed() const
Returns true if the last and the first point of the path match.
Definition: Geometry.h:364
unsigned m_fill0
Left fill style index (1-based)
Definition: Geometry.h:170
void transform(geometry::Point2d &p) const
Transform a given point by our SWFMatrix.
Definition: SWFMatrix.cpp:99
@ B
Definition: GnashKey.h:114
A subset of a shape, a series of edges sharing a single set of styles.
Definition: Geometry.h:167
For the outside of outline shapes, or just bare lines.
Definition: LineStyle.h:51
bool scaleThicknessHorizontally() const
Return true if line thickness should be scaled horizontally.
Definition: LineStyle.h:120
bool scaleThicknessVertically() const
Return true if line thickness should be scaled vertically.
Definition: LineStyle.h:115
@ p
Definition: GnashKey.h:162
@ C
Definition: GnashKey.h:115
@ q
Definition: GnashKey.h:163
Definition: SWFMatrix.h:54
2D Point class
Definition: Point2d.h:39
unsigned m_fill1
Right fill style index (1-based)
Definition: Geometry.h:173
double get_x_scale() const
return the magnitude scale of our x coord output
Definition: SWFMatrix.cpp:314
constexpr Edge(const point &ncp, const point &nap)
Definition: Geometry.h:71
@ j
Definition: GnashKey.h:156
bool pointTest(const std::vector< Path > &paths, const std::vector< LineStyle > &lineStyles, std::int32_t x, std::int32_t y, const SWFMatrix &wm)
Definition: Geometry.cpp:125
constexpr Edge()
Definition: Geometry.h:52
@ f
Definition: GnashKey.h:152
std::uint16_t getThickness() const
Return thickness of the line, in TWIPS.
Definition: LineStyle.h:110
void setLineStyle(unsigned i)
Set the line style to use for this path.
Definition: Geometry.h:506
point cp
Definition: Geometry.h:49
#define DSOEXPORT
Definition: dsodefs.h:55
std::int32_t y
The y coordinate.
Definition: Point2d.h:46
double get_y_scale() const
return the magnitude scale of our y coord output
Definition: SWFMatrix.cpp:322
void reset(std::int32_t ax, std::int32_t ay, unsigned fill0, unsigned fill1, unsigned line)
Re-initialize a path, maintaining the "new shape" flag untouched.
Definition: Geometry.h:248
Path()
Default constructor.
Definition: Geometry.h:191
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
Defines an edge with a control point and an anchor point.
Definition: Geometry.h:45
void transform(const SWFMatrix &mat)
Transform all path coordinates according to the given SWFMatrix.
Definition: Geometry.h:443
void expandBounds(SWFRect &r, unsigned int thickness, int swfVersion) const
Expand given SWFRect to include bounds of this path.
Definition: Geometry.h:276
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
std::vector< Edge > m_edges
Edges forming the path.
Definition: Geometry.h:182
@ u
Definition: GnashKey.h:167
void clear()
Remove all edges and reset style infomation.
Definition: Geometry.h:354
void drawCurveTo(std::int32_t cdx, std::int32_t cdy, std::int32_t adx, std::int32_t ady)
Draw a curve.
Definition: Geometry.h:348
std::int32_t x
Definition: BitmapData_as.cpp:434
Point2d & setTo(const std::int32_t cx, const std::int32_t cy)
Set coordinates to given values.
Definition: Point2d.h:79
@ e
Definition: GnashKey.h:151
constexpr Edge(const Edge &from)
Definition: Geometry.h:65
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
@ A
Definition: GnashKey.h:113