1 //////////////////////////////////////////////////////////////////////////////
2 // Name: SVGEllipseElement.cpp
3 // Purpose: Implementation of wxSVGEllipseElement
4 // Author: Alex Thuering
5 // Created: 2005/05/10
6 // RCS-ID: $Id: SVGEllipseElement.cpp,v 1.6 2014/03/24 21:16:35 ntalex Exp $
7 // Copyright: (c) 2005 Alex Thuering
8 // Licence: wxWindows licence
9 //////////////////////////////////////////////////////////////////////////////
10
11 #include "SVGEllipseElement.h"
12 #include "SVGCanvas.h"
13 #include "SVGAnimatedPoints.h"
14
15 #include "math.h"
16
17 const double pi = 3.1415926;
18
GetBBox(wxSVG_COORDINATES coordinates)19 wxSVGRect wxSVGEllipseElement::GetBBox(wxSVG_COORDINATES coordinates) {
20 if (coordinates == wxSVG_COORDINATES_USER)
21 return wxSVGRect(GetCx().GetBaseVal() - GetRx().GetBaseVal(), GetCy().GetBaseVal() - GetRy().GetBaseVal(),
22 2 * GetRx().GetBaseVal(), 2 * GetRy().GetBaseVal());
23
24 wxSVGMatrix matrix = GetMatrix(coordinates);
25
26 double angles[4];
27 angles[0] = atan((GetRy().GetBaseVal() * matrix.GetC()) / (GetRx().GetBaseVal() * matrix.GetA()));
28 angles[1] = atan((GetRy().GetBaseVal() * matrix.GetD()) / (GetRx().GetBaseVal() * matrix.GetB()));
29 angles[2] = angles[0] + pi;
30 angles[3] = angles[1] + pi;
31
32 wxSVGPointList points = wxSVGPointList();
33 for (int i = 0; i < 4; i++) {
34 points.Add(wxSVGPoint(GetRx().GetBaseVal() * cos(angles[i]) + GetCx().GetBaseVal(),
35 GetRy().GetBaseVal() * sin(angles[i]) + GetCy().GetBaseVal()));
36 }
37
38 wxSVGPoint p0 = points[0].MatrixTransform(matrix);
39 wxSVGRect bbox(p0.GetX(), p0.GetY(), 0, 0);
40
41 wxSVGPoint pi = wxSVGPoint();
42 for (int i = 1; i < (int) points.Count(); i++) {
43 pi = points[i].MatrixTransform(matrix);
44 if (bbox.GetX() > pi.GetX()) {
45 bbox.SetWidth(bbox.GetWidth() + bbox.GetX() - pi.GetX());
46 bbox.SetX(pi.GetX());
47 }
48 if (bbox.GetY() > pi.GetY()) {
49 bbox.SetHeight(bbox.GetHeight() + bbox.GetY() - pi.GetY());
50 bbox.SetY(pi.GetY());
51 }
52
53 if (bbox.GetX() + bbox.GetWidth() < pi.GetX())
54 bbox.SetWidth(pi.GetX() - bbox.GetX());
55 if (bbox.GetY() + bbox.GetHeight() < pi.GetY())
56 bbox.SetHeight(pi.GetY() - bbox.GetY());
57 }
58
59 return bbox;
60 }
61
GetResultBBox(wxSVG_COORDINATES coordinates)62 wxSVGRect wxSVGEllipseElement::GetResultBBox(wxSVG_COORDINATES coordinates) {
63 wxSVGRect bbox = GetBBox(coordinates);
64 if (GetStroke().GetPaintType() == wxSVG_PAINTTYPE_NONE)
65 return bbox;
66
67 double strokeWidthX = GetStrokeWidth();
68 double strokeWidthY = strokeWidthX;
69 if (coordinates != wxSVG_COORDINATES_USER) {
70 wxSVGMatrix matrix = GetMatrix(coordinates);
71 strokeWidthX *= matrix.GetA();
72 strokeWidthY *= matrix.GetD();
73 }
74
75 return wxSVGRect(bbox.GetX() - strokeWidthX / 2, bbox.GetY() - strokeWidthY / 2, bbox.GetWidth() + strokeWidthX,
76 bbox.GetHeight() + strokeWidthY);
77 }
78
SetCanvasItem(wxSVGCanvasItem * canvasItem)79 void wxSVGEllipseElement::SetCanvasItem(wxSVGCanvasItem* canvasItem) {
80 if (m_canvasItem)
81 delete m_canvasItem;
82 m_canvasItem = canvasItem;
83 }
84