2
0

edge-segments.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. #include "edge-segments.h"
  2. #include "arithmetics.hpp"
  3. #include "equation-solver.h"
  4. namespace msdfgen {
  5. EdgeSegment *EdgeSegment::create(Point2 p0, Point2 p1, EdgeColor edgeColor) {
  6. return new LinearSegment(p0, p1, edgeColor);
  7. }
  8. EdgeSegment *EdgeSegment::create(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor) {
  9. if (!crossProduct(p1-p0, p2-p1))
  10. return new LinearSegment(p0, p2, edgeColor);
  11. return new QuadraticSegment(p0, p1, p2, edgeColor);
  12. }
  13. EdgeSegment *EdgeSegment::create(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor) {
  14. Vector2 p12 = p2-p1;
  15. if (!crossProduct(p1-p0, p12) && !crossProduct(p12, p3-p2))
  16. return new LinearSegment(p0, p3, edgeColor);
  17. if ((p12 = 1.5*p1-.5*p0) == 1.5*p2-.5*p3)
  18. return new QuadraticSegment(p0, p12, p3, edgeColor);
  19. return new CubicSegment(p0, p1, p2, p3, edgeColor);
  20. }
  21. void EdgeSegment::distanceToPerpendicularDistance(SignedDistance &distance, Point2 origin, double param) const {
  22. if (param < 0) {
  23. Vector2 dir = direction(0).normalize();
  24. Vector2 aq = origin-point(0);
  25. double ts = dotProduct(aq, dir);
  26. if (ts < 0) {
  27. double perpendicularDistance = crossProduct(aq, dir);
  28. if (fabs(perpendicularDistance) <= fabs(distance.distance)) {
  29. distance.distance = perpendicularDistance;
  30. distance.dot = 0;
  31. }
  32. }
  33. } else if (param > 1) {
  34. Vector2 dir = direction(1).normalize();
  35. Vector2 bq = origin-point(1);
  36. double ts = dotProduct(bq, dir);
  37. if (ts > 0) {
  38. double perpendicularDistance = crossProduct(bq, dir);
  39. if (fabs(perpendicularDistance) <= fabs(distance.distance)) {
  40. distance.distance = perpendicularDistance;
  41. distance.dot = 0;
  42. }
  43. }
  44. }
  45. }
  46. LinearSegment::LinearSegment(Point2 p0, Point2 p1, EdgeColor edgeColor) : EdgeSegment(edgeColor) {
  47. p[0] = p0;
  48. p[1] = p1;
  49. }
  50. QuadraticSegment::QuadraticSegment(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor) : EdgeSegment(edgeColor) {
  51. p[0] = p0;
  52. p[1] = p1;
  53. p[2] = p2;
  54. }
  55. CubicSegment::CubicSegment(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor) : EdgeSegment(edgeColor) {
  56. p[0] = p0;
  57. p[1] = p1;
  58. p[2] = p2;
  59. p[3] = p3;
  60. }
  61. LinearSegment *LinearSegment::clone() const {
  62. return new LinearSegment(p[0], p[1], color);
  63. }
  64. QuadraticSegment *QuadraticSegment::clone() const {
  65. return new QuadraticSegment(p[0], p[1], p[2], color);
  66. }
  67. CubicSegment *CubicSegment::clone() const {
  68. return new CubicSegment(p[0], p[1], p[2], p[3], color);
  69. }
  70. int LinearSegment::type() const {
  71. return (int) EDGE_TYPE;
  72. }
  73. int QuadraticSegment::type() const {
  74. return (int) EDGE_TYPE;
  75. }
  76. int CubicSegment::type() const {
  77. return (int) EDGE_TYPE;
  78. }
  79. const Point2 *LinearSegment::controlPoints() const {
  80. return p;
  81. }
  82. const Point2 *QuadraticSegment::controlPoints() const {
  83. return p;
  84. }
  85. const Point2 *CubicSegment::controlPoints() const {
  86. return p;
  87. }
  88. Point2 LinearSegment::point(double param) const {
  89. return mix(p[0], p[1], param);
  90. }
  91. Point2 QuadraticSegment::point(double param) const {
  92. return mix(mix(p[0], p[1], param), mix(p[1], p[2], param), param);
  93. }
  94. Point2 CubicSegment::point(double param) const {
  95. Vector2 p12 = mix(p[1], p[2], param);
  96. return mix(mix(mix(p[0], p[1], param), p12, param), mix(p12, mix(p[2], p[3], param), param), param);
  97. }
  98. Vector2 LinearSegment::direction(double param) const {
  99. return p[1]-p[0];
  100. }
  101. Vector2 QuadraticSegment::direction(double param) const {
  102. Vector2 tangent = mix(p[1]-p[0], p[2]-p[1], param);
  103. if (!tangent)
  104. return p[2]-p[0];
  105. return tangent;
  106. }
  107. Vector2 CubicSegment::direction(double param) const {
  108. Vector2 tangent = mix(mix(p[1]-p[0], p[2]-p[1], param), mix(p[2]-p[1], p[3]-p[2], param), param);
  109. if (!tangent) {
  110. if (param == 0) return p[2]-p[0];
  111. if (param == 1) return p[3]-p[1];
  112. }
  113. return tangent;
  114. }
  115. Vector2 LinearSegment::directionChange(double param) const {
  116. return Vector2();
  117. }
  118. Vector2 QuadraticSegment::directionChange(double param) const {
  119. return (p[2]-p[1])-(p[1]-p[0]);
  120. }
  121. Vector2 CubicSegment::directionChange(double param) const {
  122. return mix((p[2]-p[1])-(p[1]-p[0]), (p[3]-p[2])-(p[2]-p[1]), param);
  123. }
  124. double LinearSegment::length() const {
  125. return (p[1]-p[0]).length();
  126. }
  127. double QuadraticSegment::length() const {
  128. Vector2 ab = p[1]-p[0];
  129. Vector2 br = p[2]-p[1]-ab;
  130. double abab = dotProduct(ab, ab);
  131. double abbr = dotProduct(ab, br);
  132. double brbr = dotProduct(br, br);
  133. double abLen = sqrt(abab);
  134. double brLen = sqrt(brbr);
  135. double crs = crossProduct(ab, br);
  136. double h = sqrt(abab+abbr+abbr+brbr);
  137. return (
  138. brLen*((abbr+brbr)*h-abbr*abLen)+
  139. crs*crs*log((brLen*h+abbr+brbr)/(brLen*abLen+abbr))
  140. )/(brbr*brLen);
  141. }
  142. SignedDistance LinearSegment::signedDistance(Point2 origin, double &param) const {
  143. Vector2 aq = origin-p[0];
  144. Vector2 ab = p[1]-p[0];
  145. param = dotProduct(aq, ab)/dotProduct(ab, ab);
  146. Vector2 eq = p[param > .5]-origin;
  147. double endpointDistance = eq.length();
  148. if (param > 0 && param < 1) {
  149. double orthoDistance = dotProduct(ab.getOrthonormal(false), aq);
  150. if (fabs(orthoDistance) < endpointDistance)
  151. return SignedDistance(orthoDistance, 0);
  152. }
  153. return SignedDistance(nonZeroSign(crossProduct(aq, ab))*endpointDistance, fabs(dotProduct(ab.normalize(), eq.normalize())));
  154. }
  155. SignedDistance QuadraticSegment::signedDistance(Point2 origin, double &param) const {
  156. Vector2 qa = p[0]-origin;
  157. Vector2 ab = p[1]-p[0];
  158. Vector2 br = p[2]-p[1]-ab;
  159. double a = dotProduct(br, br);
  160. double b = 3*dotProduct(ab, br);
  161. double c = 2*dotProduct(ab, ab)+dotProduct(qa, br);
  162. double d = dotProduct(qa, ab);
  163. double t[3];
  164. int solutions = solveCubic(t, a, b, c, d);
  165. Vector2 epDir = direction(0);
  166. double minDistance = nonZeroSign(crossProduct(epDir, qa))*qa.length(); // distance from A
  167. param = -dotProduct(qa, epDir)/dotProduct(epDir, epDir);
  168. {
  169. double distance = (p[2]-origin).length(); // distance from B
  170. if (distance < fabs(minDistance)) {
  171. epDir = direction(1);
  172. minDistance = nonZeroSign(crossProduct(epDir, p[2]-origin))*distance;
  173. param = dotProduct(origin-p[1], epDir)/dotProduct(epDir, epDir);
  174. }
  175. }
  176. for (int i = 0; i < solutions; ++i) {
  177. if (t[i] > 0 && t[i] < 1) {
  178. Point2 qe = qa+2*t[i]*ab+t[i]*t[i]*br;
  179. double distance = qe.length();
  180. if (distance <= fabs(minDistance)) {
  181. minDistance = nonZeroSign(crossProduct(ab+t[i]*br, qe))*distance;
  182. param = t[i];
  183. }
  184. }
  185. }
  186. if (param >= 0 && param <= 1)
  187. return SignedDistance(minDistance, 0);
  188. if (param < .5)
  189. return SignedDistance(minDistance, fabs(dotProduct(direction(0).normalize(), qa.normalize())));
  190. else
  191. return SignedDistance(minDistance, fabs(dotProduct(direction(1).normalize(), (p[2]-origin).normalize())));
  192. }
  193. SignedDistance CubicSegment::signedDistance(Point2 origin, double &param) const {
  194. Vector2 qa = p[0]-origin;
  195. Vector2 ab = p[1]-p[0];
  196. Vector2 br = p[2]-p[1]-ab;
  197. Vector2 as = (p[3]-p[2])-(p[2]-p[1])-br;
  198. Vector2 epDir = direction(0);
  199. double minDistance = nonZeroSign(crossProduct(epDir, qa))*qa.length(); // distance from A
  200. param = -dotProduct(qa, epDir)/dotProduct(epDir, epDir);
  201. {
  202. double distance = (p[3]-origin).length(); // distance from B
  203. if (distance < fabs(minDistance)) {
  204. epDir = direction(1);
  205. minDistance = nonZeroSign(crossProduct(epDir, p[3]-origin))*distance;
  206. param = dotProduct(epDir-(p[3]-origin), epDir)/dotProduct(epDir, epDir);
  207. }
  208. }
  209. // Iterative minimum distance search
  210. for (int i = 0; i <= MSDFGEN_CUBIC_SEARCH_STARTS; ++i) {
  211. double t = 1./MSDFGEN_CUBIC_SEARCH_STARTS*i;
  212. Vector2 qe = qa+3*t*ab+3*t*t*br+t*t*t*as;
  213. Vector2 d1 = 3*ab+6*t*br+3*t*t*as;
  214. Vector2 d2 = 6*br+6*t*as;
  215. double improvedT = t-dotProduct(qe, d1)/(dotProduct(d1, d1)+dotProduct(qe, d2));
  216. if (improvedT > 0 && improvedT < 1) {
  217. int remainingSteps = MSDFGEN_CUBIC_SEARCH_STEPS;
  218. do {
  219. t = improvedT;
  220. qe = qa+3*t*ab+3*t*t*br+t*t*t*as;
  221. d1 = 3*ab+6*t*br+3*t*t*as;
  222. if (!--remainingSteps)
  223. break;
  224. d2 = 6*br+6*t*as;
  225. improvedT = t-dotProduct(qe, d1)/(dotProduct(d1, d1)+dotProduct(qe, d2));
  226. } while (improvedT > 0 && improvedT < 1);
  227. double distance = qe.length();
  228. if (distance < fabs(minDistance)) {
  229. minDistance = nonZeroSign(crossProduct(d1, qe))*distance;
  230. param = t;
  231. }
  232. }
  233. }
  234. if (param >= 0 && param <= 1)
  235. return SignedDistance(minDistance, 0);
  236. if (param < .5)
  237. return SignedDistance(minDistance, fabs(dotProduct(direction(0).normalize(), qa.normalize())));
  238. else
  239. return SignedDistance(minDistance, fabs(dotProduct(direction(1).normalize(), (p[3]-origin).normalize())));
  240. }
  241. int LinearSegment::scanlineIntersections(double x[3], int dy[3], double y) const {
  242. if ((y >= p[0].y && y < p[1].y) || (y >= p[1].y && y < p[0].y)) {
  243. double param = (y-p[0].y)/(p[1].y-p[0].y);
  244. x[0] = mix(p[0].x, p[1].x, param);
  245. dy[0] = sign(p[1].y-p[0].y);
  246. return 1;
  247. }
  248. return 0;
  249. }
  250. int QuadraticSegment::scanlineIntersections(double x[3], int dy[3], double y) const {
  251. int total = 0;
  252. int nextDY = y > p[0].y ? 1 : -1;
  253. x[total] = p[0].x;
  254. if (p[0].y == y) {
  255. if (p[0].y < p[1].y || (p[0].y == p[1].y && p[0].y < p[2].y))
  256. dy[total++] = 1;
  257. else
  258. nextDY = 1;
  259. }
  260. {
  261. Vector2 ab = p[1]-p[0];
  262. Vector2 br = p[2]-p[1]-ab;
  263. double t[2];
  264. int solutions = solveQuadratic(t, br.y, 2*ab.y, p[0].y-y);
  265. // Sort solutions
  266. double tmp;
  267. if (solutions >= 2 && t[0] > t[1])
  268. tmp = t[0], t[0] = t[1], t[1] = tmp;
  269. for (int i = 0; i < solutions && total < 2; ++i) {
  270. if (t[i] >= 0 && t[i] <= 1) {
  271. x[total] = p[0].x+2*t[i]*ab.x+t[i]*t[i]*br.x;
  272. if (nextDY*(ab.y+t[i]*br.y) >= 0) {
  273. dy[total++] = nextDY;
  274. nextDY = -nextDY;
  275. }
  276. }
  277. }
  278. }
  279. if (p[2].y == y) {
  280. if (nextDY > 0 && total > 0) {
  281. --total;
  282. nextDY = -1;
  283. }
  284. if ((p[2].y < p[1].y || (p[2].y == p[1].y && p[2].y < p[0].y)) && total < 2) {
  285. x[total] = p[2].x;
  286. if (nextDY < 0) {
  287. dy[total++] = -1;
  288. nextDY = 1;
  289. }
  290. }
  291. }
  292. if (nextDY != (y >= p[2].y ? 1 : -1)) {
  293. if (total > 0)
  294. --total;
  295. else {
  296. if (fabs(p[2].y-y) < fabs(p[0].y-y))
  297. x[total] = p[2].x;
  298. dy[total++] = nextDY;
  299. }
  300. }
  301. return total;
  302. }
  303. int CubicSegment::scanlineIntersections(double x[3], int dy[3], double y) const {
  304. int total = 0;
  305. int nextDY = y > p[0].y ? 1 : -1;
  306. x[total] = p[0].x;
  307. if (p[0].y == y) {
  308. if (p[0].y < p[1].y || (p[0].y == p[1].y && (p[0].y < p[2].y || (p[0].y == p[2].y && p[0].y < p[3].y))))
  309. dy[total++] = 1;
  310. else
  311. nextDY = 1;
  312. }
  313. {
  314. Vector2 ab = p[1]-p[0];
  315. Vector2 br = p[2]-p[1]-ab;
  316. Vector2 as = (p[3]-p[2])-(p[2]-p[1])-br;
  317. double t[3];
  318. int solutions = solveCubic(t, as.y, 3*br.y, 3*ab.y, p[0].y-y);
  319. // Sort solutions
  320. double tmp;
  321. if (solutions >= 2) {
  322. if (t[0] > t[1])
  323. tmp = t[0], t[0] = t[1], t[1] = tmp;
  324. if (solutions >= 3 && t[1] > t[2]) {
  325. tmp = t[1], t[1] = t[2], t[2] = tmp;
  326. if (t[0] > t[1])
  327. tmp = t[0], t[0] = t[1], t[1] = tmp;
  328. }
  329. }
  330. for (int i = 0; i < solutions && total < 3; ++i) {
  331. if (t[i] >= 0 && t[i] <= 1) {
  332. x[total] = p[0].x+3*t[i]*ab.x+3*t[i]*t[i]*br.x+t[i]*t[i]*t[i]*as.x;
  333. if (nextDY*(ab.y+2*t[i]*br.y+t[i]*t[i]*as.y) >= 0) {
  334. dy[total++] = nextDY;
  335. nextDY = -nextDY;
  336. }
  337. }
  338. }
  339. }
  340. if (p[3].y == y) {
  341. if (nextDY > 0 && total > 0) {
  342. --total;
  343. nextDY = -1;
  344. }
  345. if ((p[3].y < p[2].y || (p[3].y == p[2].y && (p[3].y < p[1].y || (p[3].y == p[1].y && p[3].y < p[0].y)))) && total < 3) {
  346. x[total] = p[3].x;
  347. if (nextDY < 0) {
  348. dy[total++] = -1;
  349. nextDY = 1;
  350. }
  351. }
  352. }
  353. if (nextDY != (y >= p[3].y ? 1 : -1)) {
  354. if (total > 0)
  355. --total;
  356. else {
  357. if (fabs(p[3].y-y) < fabs(p[0].y-y))
  358. x[total] = p[3].x;
  359. dy[total++] = nextDY;
  360. }
  361. }
  362. return total;
  363. }
  364. static void pointBounds(Point2 p, double &l, double &b, double &r, double &t) {
  365. if (p.x < l) l = p.x;
  366. if (p.y < b) b = p.y;
  367. if (p.x > r) r = p.x;
  368. if (p.y > t) t = p.y;
  369. }
  370. void LinearSegment::bound(double &l, double &b, double &r, double &t) const {
  371. pointBounds(p[0], l, b, r, t);
  372. pointBounds(p[1], l, b, r, t);
  373. }
  374. void QuadraticSegment::bound(double &l, double &b, double &r, double &t) const {
  375. pointBounds(p[0], l, b, r, t);
  376. pointBounds(p[2], l, b, r, t);
  377. Vector2 bot = (p[1]-p[0])-(p[2]-p[1]);
  378. if (bot.x) {
  379. double param = (p[1].x-p[0].x)/bot.x;
  380. if (param > 0 && param < 1)
  381. pointBounds(point(param), l, b, r, t);
  382. }
  383. if (bot.y) {
  384. double param = (p[1].y-p[0].y)/bot.y;
  385. if (param > 0 && param < 1)
  386. pointBounds(point(param), l, b, r, t);
  387. }
  388. }
  389. void CubicSegment::bound(double &l, double &b, double &r, double &t) const {
  390. pointBounds(p[0], l, b, r, t);
  391. pointBounds(p[3], l, b, r, t);
  392. Vector2 a0 = p[1]-p[0];
  393. Vector2 a1 = 2*(p[2]-p[1]-a0);
  394. Vector2 a2 = p[3]-3*p[2]+3*p[1]-p[0];
  395. double params[2];
  396. int solutions;
  397. solutions = solveQuadratic(params, a2.x, a1.x, a0.x);
  398. for (int i = 0; i < solutions; ++i)
  399. if (params[i] > 0 && params[i] < 1)
  400. pointBounds(point(params[i]), l, b, r, t);
  401. solutions = solveQuadratic(params, a2.y, a1.y, a0.y);
  402. for (int i = 0; i < solutions; ++i)
  403. if (params[i] > 0 && params[i] < 1)
  404. pointBounds(point(params[i]), l, b, r, t);
  405. }
  406. void LinearSegment::reverse() {
  407. Point2 tmp = p[0];
  408. p[0] = p[1];
  409. p[1] = tmp;
  410. }
  411. void QuadraticSegment::reverse() {
  412. Point2 tmp = p[0];
  413. p[0] = p[2];
  414. p[2] = tmp;
  415. }
  416. void CubicSegment::reverse() {
  417. Point2 tmp = p[0];
  418. p[0] = p[3];
  419. p[3] = tmp;
  420. tmp = p[1];
  421. p[1] = p[2];
  422. p[2] = tmp;
  423. }
  424. void LinearSegment::moveStartPoint(Point2 to) {
  425. p[0] = to;
  426. }
  427. void QuadraticSegment::moveStartPoint(Point2 to) {
  428. Vector2 origSDir = p[0]-p[1];
  429. Point2 origP1 = p[1];
  430. p[1] += crossProduct(p[0]-p[1], to-p[0])/crossProduct(p[0]-p[1], p[2]-p[1])*(p[2]-p[1]);
  431. p[0] = to;
  432. if (dotProduct(origSDir, p[0]-p[1]) < 0)
  433. p[1] = origP1;
  434. }
  435. void CubicSegment::moveStartPoint(Point2 to) {
  436. p[1] += to-p[0];
  437. p[0] = to;
  438. }
  439. void LinearSegment::moveEndPoint(Point2 to) {
  440. p[1] = to;
  441. }
  442. void QuadraticSegment::moveEndPoint(Point2 to) {
  443. Vector2 origEDir = p[2]-p[1];
  444. Point2 origP1 = p[1];
  445. p[1] += crossProduct(p[2]-p[1], to-p[2])/crossProduct(p[2]-p[1], p[0]-p[1])*(p[0]-p[1]);
  446. p[2] = to;
  447. if (dotProduct(origEDir, p[2]-p[1]) < 0)
  448. p[1] = origP1;
  449. }
  450. void CubicSegment::moveEndPoint(Point2 to) {
  451. p[2] += to-p[3];
  452. p[3] = to;
  453. }
  454. void LinearSegment::splitInThirds(EdgeSegment *&part0, EdgeSegment *&part1, EdgeSegment *&part2) const {
  455. part0 = new LinearSegment(p[0], point(1/3.), color);
  456. part1 = new LinearSegment(point(1/3.), point(2/3.), color);
  457. part2 = new LinearSegment(point(2/3.), p[1], color);
  458. }
  459. void QuadraticSegment::splitInThirds(EdgeSegment *&part0, EdgeSegment *&part1, EdgeSegment *&part2) const {
  460. part0 = new QuadraticSegment(p[0], mix(p[0], p[1], 1/3.), point(1/3.), color);
  461. part1 = new QuadraticSegment(point(1/3.), mix(mix(p[0], p[1], 5/9.), mix(p[1], p[2], 4/9.), .5), point(2/3.), color);
  462. part2 = new QuadraticSegment(point(2/3.), mix(p[1], p[2], 2/3.), p[2], color);
  463. }
  464. void CubicSegment::splitInThirds(EdgeSegment *&part0, EdgeSegment *&part1, EdgeSegment *&part2) const {
  465. part0 = new CubicSegment(p[0], p[0] == p[1] ? p[0] : mix(p[0], p[1], 1/3.), mix(mix(p[0], p[1], 1/3.), mix(p[1], p[2], 1/3.), 1/3.), point(1/3.), color);
  466. part1 = new CubicSegment(point(1/3.),
  467. mix(mix(mix(p[0], p[1], 1/3.), mix(p[1], p[2], 1/3.), 1/3.), mix(mix(p[1], p[2], 1/3.), mix(p[2], p[3], 1/3.), 1/3.), 2/3.),
  468. mix(mix(mix(p[0], p[1], 2/3.), mix(p[1], p[2], 2/3.), 2/3.), mix(mix(p[1], p[2], 2/3.), mix(p[2], p[3], 2/3.), 2/3.), 1/3.),
  469. point(2/3.), color);
  470. part2 = new CubicSegment(point(2/3.), mix(mix(p[1], p[2], 2/3.), mix(p[2], p[3], 2/3.), 2/3.), p[2] == p[3] ? p[3] : mix(p[2], p[3], 2/3.), p[3], color);
  471. }
  472. EdgeSegment *QuadraticSegment::convertToCubic() const {
  473. return new CubicSegment(p[0], mix(p[0], p[1], 2/3.), mix(p[1], p[2], 1/3.), p[2], color);
  474. }
  475. }