24 #include "wtf/Platform.h"
30 #include <wtf/MathExtras.h>
35 : RefCounted<SVGAngle>(0)
36 , m_unitType(SVG_ANGLETYPE_UNKNOWN)
38 , m_valueInSpecifiedUnits(0)
46 SVGAngle::SVGAngleType SVGAngle::unitType()
const
51 void SVGAngle::setValue(
float value)
56 float SVGAngle::value()
const
62 void SVGAngle::calculate()
64 if (m_unitType == SVG_ANGLETYPE_GRAD)
65 m_value = grad2deg(m_valueInSpecifiedUnits);
66 else if (m_unitType == SVG_ANGLETYPE_RAD)
67 m_value = rad2deg(m_valueInSpecifiedUnits);
68 else if (m_unitType == SVG_ANGLETYPE_UNSPECIFIED || m_unitType == SVG_ANGLETYPE_DEG)
69 m_value = m_valueInSpecifiedUnits;
72 void SVGAngle::setValueInSpecifiedUnits(
float valueInSpecifiedUnits)
74 m_valueInSpecifiedUnits = valueInSpecifiedUnits;
78 float SVGAngle::valueInSpecifiedUnits()
const
80 return m_valueInSpecifiedUnits;
83 void SVGAngle::setValueAsString(
const String& s)
88 m_valueInSpecifiedUnits = m_valueAsString.toFloat(&bOK);
89 m_unitType = SVG_ANGLETYPE_UNSPECIFIED;
92 if (m_valueAsString.endsWith(
"deg"))
93 m_unitType = SVG_ANGLETYPE_DEG;
94 else if (m_valueAsString.endsWith(
"grad"))
95 m_unitType = SVG_ANGLETYPE_GRAD;
96 else if (m_valueAsString.endsWith(
"rad"))
97 m_unitType = SVG_ANGLETYPE_RAD;
103 String SVGAngle::valueAsString()
const
105 m_valueAsString = String::number(m_valueInSpecifiedUnits);
107 switch (m_unitType) {
108 case SVG_ANGLETYPE_UNSPECIFIED:
109 case SVG_ANGLETYPE_DEG:
110 m_valueAsString +=
"deg";
112 case SVG_ANGLETYPE_RAD:
113 m_valueAsString +=
"rad";
115 case SVG_ANGLETYPE_GRAD:
116 m_valueAsString +=
"grad";
118 case SVG_ANGLETYPE_UNKNOWN:
122 return m_valueAsString;
125 void SVGAngle::newValueSpecifiedUnits(
unsigned short unitType,
float valueInSpecifiedUnits)
127 m_unitType = (SVGAngleType)unitType;
128 m_valueInSpecifiedUnits = valueInSpecifiedUnits;
132 void SVGAngle::convertToSpecifiedUnits(
unsigned short unitType)
134 if (m_unitType == unitType)
137 if (m_unitType == SVG_ANGLETYPE_DEG && unitType == SVG_ANGLETYPE_RAD)
138 m_valueInSpecifiedUnits = deg2rad(m_valueInSpecifiedUnits);
139 else if (m_unitType == SVG_ANGLETYPE_GRAD && unitType == SVG_ANGLETYPE_RAD)
140 m_valueInSpecifiedUnits = grad2rad(m_valueInSpecifiedUnits);
141 else if (m_unitType == SVG_ANGLETYPE_DEG && unitType == SVG_ANGLETYPE_GRAD)
142 m_valueInSpecifiedUnits = deg2grad(m_valueInSpecifiedUnits);
143 else if (m_unitType == SVG_ANGLETYPE_RAD && unitType == SVG_ANGLETYPE_GRAD)
144 m_valueInSpecifiedUnits = rad2grad(m_valueInSpecifiedUnits);
145 else if (m_unitType == SVG_ANGLETYPE_RAD && unitType == SVG_ANGLETYPE_DEG)
146 m_valueInSpecifiedUnits = rad2deg(m_valueInSpecifiedUnits);
147 else if (m_unitType == SVG_ANGLETYPE_GRAD && unitType == SVG_ANGLETYPE_DEG)
148 m_valueInSpecifiedUnits = grad2deg(m_valueInSpecifiedUnits);
150 m_unitType = (SVGAngleType)unitType;
154 double SVGAngle::todeg(
double rad)
159 double SVGAngle::torad(
double deg)
164 double SVGAngle::shortestArcBisector(
double angle1,
double angle2)
166 double bisector = (angle1 + angle2) / 2;
168 if (fabs(angle1 - angle2) > 180)
176 #endif // ENABLE(SVG)