DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1030 lines
21KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifdef _MSC_VER
  17. // instantiated template classes whose methods are defined elsewhere
  18. # pragma warning(disable:4661)
  19. #endif
  20. #include "../Geometry.hpp"
  21. #include <cmath>
  22. START_NAMESPACE_DGL
  23. static const float M_2PIf = 3.14159265358979323846f*2.0f;
  24. // -----------------------------------------------------------------------
  25. // Point
  26. template<typename T>
  27. Point<T>::Point() noexcept
  28. : x(0),
  29. y(0) {}
  30. template<typename T>
  31. Point<T>::Point(const T& x2, const T& y2) noexcept
  32. : x(x2),
  33. y(y2) {}
  34. template<typename T>
  35. Point<T>::Point(const Point<T>& pos) noexcept
  36. : x(pos.x),
  37. y(pos.y) {}
  38. template<typename T>
  39. const T& Point<T>::getX() const noexcept
  40. {
  41. return x;
  42. }
  43. template<typename T>
  44. const T& Point<T>::getY() const noexcept
  45. {
  46. return y;
  47. }
  48. template<typename T>
  49. void Point<T>::setX(const T& x2) noexcept
  50. {
  51. x = x2;
  52. }
  53. template<typename T>
  54. void Point<T>::setY(const T& y2) noexcept
  55. {
  56. y = y2;
  57. }
  58. template<typename T>
  59. void Point<T>::setPos(const T& x2, const T& y2) noexcept
  60. {
  61. x = x2;
  62. y = y2;
  63. }
  64. template<typename T>
  65. void Point<T>::setPos(const Point<T>& pos) noexcept
  66. {
  67. x = pos.x;
  68. y = pos.y;
  69. }
  70. template<typename T>
  71. void Point<T>::moveBy(const T& x2, const T& y2) noexcept
  72. {
  73. x = static_cast<T>(x+x2);
  74. y = static_cast<T>(y+y2);
  75. }
  76. template<typename T>
  77. void Point<T>::moveBy(const Point<T>& pos) noexcept
  78. {
  79. x = static_cast<T>(x+pos.x);
  80. y = static_cast<T>(y+pos.y);
  81. }
  82. template<typename T>
  83. bool Point<T>::isZero() const noexcept
  84. {
  85. return x == 0 && y == 0;
  86. }
  87. template<typename T>
  88. bool Point<T>::isNotZero() const noexcept
  89. {
  90. return x != 0 || y != 0;
  91. }
  92. template<typename T>
  93. Point<T> Point<T>::operator+(const Point<T>& pos) noexcept
  94. {
  95. return Point<T>(x+pos.x, y+pos.y);
  96. }
  97. template<typename T>
  98. Point<T> Point<T>::operator-(const Point<T>& pos) noexcept
  99. {
  100. return Point<T>(x-pos.x, y-pos.y);
  101. }
  102. template<typename T>
  103. Point<T>& Point<T>::operator=(const Point<T>& pos) noexcept
  104. {
  105. x = pos.x;
  106. y = pos.y;
  107. return *this;
  108. }
  109. template<typename T>
  110. Point<T>& Point<T>::operator+=(const Point<T>& pos) noexcept
  111. {
  112. x = static_cast<T>(x+pos.x);
  113. y = static_cast<T>(y+pos.y);
  114. return *this;
  115. }
  116. template<typename T>
  117. Point<T>& Point<T>::operator-=(const Point<T>& pos) noexcept
  118. {
  119. x = static_cast<T>(x-pos.x);
  120. y = static_cast<T>(y-pos.y);
  121. return *this;
  122. }
  123. template<typename T>
  124. bool Point<T>::operator==(const Point<T>& pos) const noexcept
  125. {
  126. return (x == pos.x && y == pos.y);
  127. }
  128. template<typename T>
  129. bool Point<T>::operator!=(const Point<T>& pos) const noexcept
  130. {
  131. return (x != pos.x || y != pos.y);
  132. }
  133. // -----------------------------------------------------------------------
  134. // Size
  135. template<typename T>
  136. Size<T>::Size() noexcept
  137. : fWidth(0),
  138. fHeight(0) {}
  139. template<typename T>
  140. Size<T>::Size(const T& width, const T& height) noexcept
  141. : fWidth(width),
  142. fHeight(height) {}
  143. template<typename T>
  144. Size<T>::Size(const Size<T>& size) noexcept
  145. : fWidth(size.fWidth),
  146. fHeight(size.fHeight) {}
  147. template<typename T>
  148. const T& Size<T>::getWidth() const noexcept
  149. {
  150. return fWidth;
  151. }
  152. template<typename T>
  153. const T& Size<T>::getHeight() const noexcept
  154. {
  155. return fHeight;
  156. }
  157. template<typename T>
  158. void Size<T>::setWidth(const T& width) noexcept
  159. {
  160. fWidth = width;
  161. }
  162. template<typename T>
  163. void Size<T>::setHeight(const T& height) noexcept
  164. {
  165. fHeight = height;
  166. }
  167. template<typename T>
  168. void Size<T>::setSize(const T& width, const T& height) noexcept
  169. {
  170. fWidth = width;
  171. fHeight = height;
  172. }
  173. template<typename T>
  174. void Size<T>::setSize(const Size<T>& size) noexcept
  175. {
  176. fWidth = size.fWidth;
  177. fHeight = size.fHeight;
  178. }
  179. template<typename T>
  180. void Size<T>::growBy(double multiplier) noexcept
  181. {
  182. fWidth = static_cast<T>(static_cast<double>(fWidth)*multiplier);
  183. fHeight = static_cast<T>(static_cast<double>(fHeight)*multiplier);
  184. }
  185. template<typename T>
  186. void Size<T>::shrinkBy(double divider) noexcept
  187. {
  188. fWidth = static_cast<T>(static_cast<double>(fWidth)/divider);
  189. fHeight = static_cast<T>(static_cast<double>(fHeight)/divider);
  190. }
  191. template<typename T>
  192. bool Size<T>::isNull() const noexcept
  193. {
  194. return fWidth == 0 && fHeight == 0;
  195. }
  196. template<typename T>
  197. bool Size<T>::isNotNull() const noexcept
  198. {
  199. return fWidth != 0 || fHeight != 0;
  200. }
  201. template<typename T>
  202. bool Size<T>::isValid() const noexcept
  203. {
  204. return fWidth > 0 && fHeight > 0;
  205. }
  206. template<typename T>
  207. bool Size<T>::isInvalid() const noexcept
  208. {
  209. return fWidth <= 0 || fHeight <= 0;
  210. }
  211. template<typename T>
  212. Size<int> Size<T>::toInt() const noexcept
  213. {
  214. return Size<int>(static_cast<int>(fWidth),
  215. static_cast<int>(fHeight));
  216. }
  217. template<>
  218. Size<int> Size<double>::toInt() const noexcept
  219. {
  220. return Size<int>(static_cast<int>(fWidth + 0.5),
  221. static_cast<int>(fHeight + 0.5));
  222. }
  223. template<>
  224. Size<int> Size<float>::toInt() const noexcept
  225. {
  226. return Size<int>(static_cast<int>(fWidth + 0.5f),
  227. static_cast<int>(fHeight + 0.5f));
  228. }
  229. template<typename T>
  230. Size<T> Size<T>::operator+(const Size<T>& size) noexcept
  231. {
  232. return Size<T>(fWidth+size.fWidth, fHeight+size.fHeight);
  233. }
  234. template<typename T>
  235. Size<T> Size<T>::operator-(const Size<T>& size) noexcept
  236. {
  237. return Size<T>(fWidth-size.fWidth, fHeight-size.fHeight);
  238. }
  239. template<typename T>
  240. Size<T>& Size<T>::operator=(const Size<T>& size) noexcept
  241. {
  242. fWidth = size.fWidth;
  243. fHeight = size.fHeight;
  244. return *this;
  245. }
  246. template<typename T>
  247. Size<T>& Size<T>::operator+=(const Size<T>& size) noexcept
  248. {
  249. fWidth = static_cast<T>(fWidth+size.fWidth);
  250. fHeight = static_cast<T>(fHeight+size.fHeight);
  251. return *this;
  252. }
  253. template<typename T>
  254. Size<T>& Size<T>::operator-=(const Size<T>& size) noexcept
  255. {
  256. fWidth = static_cast<T>(fWidth-size.fWidth);
  257. fHeight = static_cast<T>(fHeight-size.fHeight);
  258. return *this;
  259. }
  260. template<typename T>
  261. Size<T>& Size<T>::operator*=(double m) noexcept
  262. {
  263. fWidth = static_cast<T>(static_cast<double>(fWidth)*m);
  264. fHeight = static_cast<T>(static_cast<double>(fHeight)*m);
  265. return *this;
  266. }
  267. template<typename T>
  268. Size<T>& Size<T>::operator/=(double d) noexcept
  269. {
  270. fWidth = static_cast<T>(static_cast<double>(fWidth)/d);
  271. fHeight = static_cast<T>(static_cast<double>(fHeight)/d);
  272. return *this;
  273. }
  274. template<typename T>
  275. bool Size<T>::operator==(const Size<T>& size) const noexcept
  276. {
  277. return (fWidth == size.fWidth && fHeight == size.fHeight);
  278. }
  279. template<typename T>
  280. bool Size<T>::operator!=(const Size<T>& size) const noexcept
  281. {
  282. return (fWidth != size.fWidth || fHeight != size.fHeight);
  283. }
  284. // -----------------------------------------------------------------------
  285. // Line
  286. template<typename T>
  287. Line<T>::Line() noexcept
  288. : posStart(0, 0),
  289. posEnd(0, 0) {}
  290. template<typename T>
  291. Line<T>::Line(const T& startX, const T& startY, const T& endX, const T& endY) noexcept
  292. : posStart(startX, startY),
  293. posEnd(endX, endY) {}
  294. template<typename T>
  295. Line<T>::Line(const T& startX, const T& startY, const Point<T>& endPos) noexcept
  296. : posStart(startX, startY),
  297. posEnd(endPos) {}
  298. template<typename T>
  299. Line<T>::Line(const Point<T>& startPos, const T& endX, const T& endY) noexcept
  300. : posStart(startPos),
  301. posEnd(endX, endY) {}
  302. template<typename T>
  303. Line<T>::Line(const Point<T>& startPos, const Point<T>& endPos) noexcept
  304. : posStart(startPos),
  305. posEnd(endPos) {}
  306. template<typename T>
  307. Line<T>::Line(const Line<T>& line) noexcept
  308. : posStart(line.posStart),
  309. posEnd(line.posEnd) {}
  310. template<typename T>
  311. const T& Line<T>::getStartX() const noexcept
  312. {
  313. return posStart.x;
  314. }
  315. template<typename T>
  316. const T& Line<T>::getStartY() const noexcept
  317. {
  318. return posStart.y;
  319. }
  320. template<typename T>
  321. const T& Line<T>::getEndX() const noexcept
  322. {
  323. return posEnd.x;
  324. }
  325. template<typename T>
  326. const T& Line<T>::getEndY() const noexcept
  327. {
  328. return posEnd.y;
  329. }
  330. template<typename T>
  331. const Point<T>& Line<T>::getStartPos() const noexcept
  332. {
  333. return posStart;
  334. }
  335. template<typename T>
  336. const Point<T>& Line<T>::getEndPos() const noexcept
  337. {
  338. return posEnd;
  339. }
  340. template<typename T>
  341. void Line<T>::setStartX(const T& x) noexcept
  342. {
  343. posStart.x = x;
  344. }
  345. template<typename T>
  346. void Line<T>::setStartY(const T& y) noexcept
  347. {
  348. posStart.y = y;
  349. }
  350. template<typename T>
  351. void Line<T>::setStartPos(const T& x, const T& y) noexcept
  352. {
  353. posStart = Point<T>(x, y);
  354. }
  355. template<typename T>
  356. void Line<T>::setStartPos(const Point<T>& pos) noexcept
  357. {
  358. posStart = pos;
  359. }
  360. template<typename T>
  361. void Line<T>::setEndX(const T& x) noexcept
  362. {
  363. posEnd.x = x;
  364. }
  365. template<typename T>
  366. void Line<T>::setEndY(const T& y) noexcept
  367. {
  368. posEnd.y = y;
  369. }
  370. template<typename T>
  371. void Line<T>::setEndPos(const T& x, const T& y) noexcept
  372. {
  373. posEnd = Point<T>(x, y);
  374. }
  375. template<typename T>
  376. void Line<T>::setEndPos(const Point<T>& pos) noexcept
  377. {
  378. posEnd = pos;
  379. }
  380. template<typename T>
  381. void Line<T>::moveBy(const T& x, const T& y) noexcept
  382. {
  383. posStart.moveBy(x, y);
  384. posEnd.moveBy(x, y);
  385. }
  386. template<typename T>
  387. void Line<T>::moveBy(const Point<T>& pos) noexcept
  388. {
  389. posStart.moveBy(pos);
  390. posEnd.moveBy(pos);
  391. }
  392. template<typename T>
  393. bool Line<T>::isNull() const noexcept
  394. {
  395. return posStart == posEnd;
  396. }
  397. template<typename T>
  398. bool Line<T>::isNotNull() const noexcept
  399. {
  400. return posStart != posEnd;
  401. }
  402. template<typename T>
  403. Line<T>& Line<T>::operator=(const Line<T>& line) noexcept
  404. {
  405. posStart = line.posStart;
  406. posEnd = line.posEnd;
  407. return *this;
  408. }
  409. template<typename T>
  410. bool Line<T>::operator==(const Line<T>& line) const noexcept
  411. {
  412. return (posStart == line.posStart && posEnd == line.posEnd);
  413. }
  414. template<typename T>
  415. bool Line<T>::operator!=(const Line<T>& line) const noexcept
  416. {
  417. return (posStart != line.posStart || posEnd != line.posEnd);
  418. }
  419. // -----------------------------------------------------------------------
  420. // Circle
  421. template<typename T>
  422. Circle<T>::Circle() noexcept
  423. : fPos(0, 0),
  424. fSize(0.0f),
  425. fNumSegments(0),
  426. fTheta(0.0f),
  427. fCos(0.0f),
  428. fSin(0.0f) {}
  429. template<typename T>
  430. Circle<T>::Circle(const T& x, const T& y, const float size, const uint numSegments)
  431. : fPos(x, y),
  432. fSize(size),
  433. fNumSegments(numSegments >= 3 ? numSegments : 3),
  434. fTheta(M_2PIf / static_cast<float>(fNumSegments)),
  435. fCos(std::cos(fTheta)),
  436. fSin(std::sin(fTheta))
  437. {
  438. DISTRHO_SAFE_ASSERT(fSize > 0.0f);
  439. }
  440. template<typename T>
  441. Circle<T>::Circle(const Point<T>& pos, const float size, const uint numSegments)
  442. : fPos(pos),
  443. fSize(size),
  444. fNumSegments(numSegments >= 3 ? numSegments : 3),
  445. fTheta(M_2PIf / static_cast<float>(fNumSegments)),
  446. fCos(std::cos(fTheta)),
  447. fSin(std::sin(fTheta))
  448. {
  449. DISTRHO_SAFE_ASSERT(fSize > 0.0f);
  450. }
  451. template<typename T>
  452. Circle<T>::Circle(const Circle<T>& cir) noexcept
  453. : fPos(cir.fPos),
  454. fSize(cir.fSize),
  455. fNumSegments(cir.fNumSegments),
  456. fTheta(cir.fTheta),
  457. fCos(cir.fCos),
  458. fSin(cir.fSin)
  459. {
  460. DISTRHO_SAFE_ASSERT(fSize > 0.0f);
  461. }
  462. template<typename T>
  463. const T& Circle<T>::getX() const noexcept
  464. {
  465. return fPos.x;
  466. }
  467. template<typename T>
  468. const T& Circle<T>::getY() const noexcept
  469. {
  470. return fPos.y;
  471. }
  472. template<typename T>
  473. const Point<T>& Circle<T>::getPos() const noexcept
  474. {
  475. return fPos;
  476. }
  477. template<typename T>
  478. void Circle<T>::setX(const T& x) noexcept
  479. {
  480. fPos.x = x;
  481. }
  482. template<typename T>
  483. void Circle<T>::setY(const T& y) noexcept
  484. {
  485. fPos.y = y;
  486. }
  487. template<typename T>
  488. void Circle<T>::setPos(const T& x, const T& y) noexcept
  489. {
  490. fPos.x = x;
  491. fPos.y = y;
  492. }
  493. template<typename T>
  494. void Circle<T>::setPos(const Point<T>& pos) noexcept
  495. {
  496. fPos = pos;
  497. }
  498. template<typename T>
  499. float Circle<T>::getSize() const noexcept
  500. {
  501. return fSize;
  502. }
  503. template<typename T>
  504. void Circle<T>::setSize(const float size) noexcept
  505. {
  506. DISTRHO_SAFE_ASSERT_RETURN(size > 0.0f,);
  507. fSize = size;
  508. }
  509. template<typename T>
  510. uint Circle<T>::getNumSegments() const noexcept
  511. {
  512. return fNumSegments;
  513. }
  514. template<typename T>
  515. void Circle<T>::setNumSegments(const uint num)
  516. {
  517. DISTRHO_SAFE_ASSERT_RETURN(num >= 3,);
  518. if (fNumSegments == num)
  519. return;
  520. fNumSegments = num;
  521. fTheta = M_2PIf / static_cast<float>(fNumSegments);
  522. fCos = std::cos(fTheta);
  523. fSin = std::sin(fTheta);
  524. }
  525. template<typename T>
  526. Circle<T>& Circle<T>::operator=(const Circle<T>& cir) noexcept
  527. {
  528. fPos = cir.fPos;
  529. fSize = cir.fSize;
  530. fTheta = cir.fTheta;
  531. fCos = cir.fCos;
  532. fSin = cir.fSin;
  533. fNumSegments = cir.fNumSegments;
  534. return *this;
  535. }
  536. template<typename T>
  537. bool Circle<T>::operator==(const Circle<T>& cir) const noexcept
  538. {
  539. return (fPos == cir.fPos && d_isEqual(fSize, cir.fSize) && fNumSegments == cir.fNumSegments);
  540. }
  541. template<typename T>
  542. bool Circle<T>::operator!=(const Circle<T>& cir) const noexcept
  543. {
  544. return (fPos != cir.fPos || d_isNotEqual(fSize, cir.fSize) || fNumSegments != cir.fNumSegments);
  545. }
  546. // -----------------------------------------------------------------------
  547. // Triangle
  548. template<typename T>
  549. Triangle<T>::Triangle() noexcept
  550. : pos1(0, 0),
  551. pos2(0, 0),
  552. pos3(0, 0) {}
  553. template<typename T>
  554. Triangle<T>::Triangle(const T& x1, const T& y1, const T& x2, const T& y2, const T& x3, const T& y3) noexcept
  555. : pos1(x1, y1),
  556. pos2(x2, y2),
  557. pos3(x3, y3) {}
  558. template<typename T>
  559. Triangle<T>::Triangle(const Point<T>& p1, const Point<T>& p2, const Point<T>& p3) noexcept
  560. : pos1(p1),
  561. pos2(p2),
  562. pos3(p3) {}
  563. template<typename T>
  564. Triangle<T>::Triangle(const Triangle<T>& tri) noexcept
  565. : pos1(tri.pos1),
  566. pos2(tri.pos2),
  567. pos3(tri.pos3) {}
  568. template<typename T>
  569. bool Triangle<T>::isNull() const noexcept
  570. {
  571. return pos1 == pos2 && pos1 == pos3;
  572. }
  573. template<typename T>
  574. bool Triangle<T>::isNotNull() const noexcept
  575. {
  576. return pos1 != pos2 || pos1 != pos3;
  577. }
  578. template<typename T>
  579. bool Triangle<T>::isValid() const noexcept
  580. {
  581. return pos1 != pos2 && pos1 != pos3;
  582. }
  583. template<typename T>
  584. bool Triangle<T>::isInvalid() const noexcept
  585. {
  586. return pos1 == pos2 || pos1 == pos3;
  587. }
  588. template<typename T>
  589. Triangle<T>& Triangle<T>::operator=(const Triangle<T>& tri) noexcept
  590. {
  591. pos1 = tri.pos1;
  592. pos2 = tri.pos2;
  593. pos3 = tri.pos3;
  594. return *this;
  595. }
  596. template<typename T>
  597. bool Triangle<T>::operator==(const Triangle<T>& tri) const noexcept
  598. {
  599. return (pos1 == tri.pos1 && pos2 == tri.pos2 && pos3 == tri.pos3);
  600. }
  601. template<typename T>
  602. bool Triangle<T>::operator!=(const Triangle<T>& tri) const noexcept
  603. {
  604. return (pos1 != tri.pos1 || pos2 != tri.pos2 || pos3 != tri.pos3);
  605. }
  606. // -----------------------------------------------------------------------
  607. // Rectangle
  608. template<typename T>
  609. Rectangle<T>::Rectangle() noexcept
  610. : pos(0, 0),
  611. size(0, 0) {}
  612. template<typename T>
  613. Rectangle<T>::Rectangle(const T& x, const T& y, const T& w, const T& h) noexcept
  614. : pos(x, y),
  615. size(w, h) {}
  616. template<typename T>
  617. Rectangle<T>::Rectangle(const T& x, const T& y, const Size<T>& s) noexcept
  618. : pos(x, y),
  619. size(s) {}
  620. template<typename T>
  621. Rectangle<T>::Rectangle(const Point<T>& p, const T& w, const T& h) noexcept
  622. : pos(p),
  623. size(w, h) {}
  624. template<typename T>
  625. Rectangle<T>::Rectangle(const Point<T>& p, const Size<T>& s) noexcept
  626. : pos(p),
  627. size(s) {}
  628. template<typename T>
  629. Rectangle<T>::Rectangle(const Rectangle<T>& rect) noexcept
  630. : pos(rect.pos),
  631. size(rect.size) {}
  632. template<typename T>
  633. const T& Rectangle<T>::getX() const noexcept
  634. {
  635. return pos.x;
  636. }
  637. template<typename T>
  638. const T& Rectangle<T>::getY() const noexcept
  639. {
  640. return pos.y;
  641. }
  642. template<typename T>
  643. const T& Rectangle<T>::getWidth() const noexcept
  644. {
  645. return size.fWidth;
  646. }
  647. template<typename T>
  648. const T& Rectangle<T>::getHeight() const noexcept
  649. {
  650. return size.fHeight;
  651. }
  652. template<typename T>
  653. const Point<T>& Rectangle<T>::getPos() const noexcept
  654. {
  655. return pos;
  656. }
  657. template<typename T>
  658. const Size<T>& Rectangle<T>::getSize() const noexcept
  659. {
  660. return size;
  661. }
  662. template<typename T>
  663. void Rectangle<T>::setX(const T& x) noexcept
  664. {
  665. pos.x = x;
  666. }
  667. template<typename T>
  668. void Rectangle<T>::setY(const T& y) noexcept
  669. {
  670. pos.y = y;
  671. }
  672. template<typename T>
  673. void Rectangle<T>::setPos(const T& x, const T& y) noexcept
  674. {
  675. pos.x = x;
  676. pos.y = y;
  677. }
  678. template<typename T>
  679. void Rectangle<T>::setPos(const Point<T>& pos2) noexcept
  680. {
  681. pos = pos2;
  682. }
  683. template<typename T>
  684. void Rectangle<T>::moveBy(const T& x, const T& y) noexcept
  685. {
  686. pos.moveBy(x, y);
  687. }
  688. template<typename T>
  689. void Rectangle<T>::moveBy(const Point<T>& pos2) noexcept
  690. {
  691. pos.moveBy(pos2);
  692. }
  693. template<typename T>
  694. void Rectangle<T>::setWidth(const T& width) noexcept
  695. {
  696. size.fWidth = width;
  697. }
  698. template<typename T>
  699. void Rectangle<T>::setHeight(const T& height) noexcept
  700. {
  701. size.fHeight = height;
  702. }
  703. template<typename T>
  704. void Rectangle<T>::setSize(const T& width, const T& height) noexcept
  705. {
  706. size.fWidth = width;
  707. size.fHeight = height;
  708. }
  709. template<typename T>
  710. void Rectangle<T>::setSize(const Size<T>& size2) noexcept
  711. {
  712. size = size2;
  713. }
  714. template<typename T>
  715. void Rectangle<T>::growBy(double multiplier) noexcept
  716. {
  717. size.growBy(multiplier);
  718. }
  719. template<typename T>
  720. void Rectangle<T>::shrinkBy(double divider) noexcept
  721. {
  722. size.shrinkBy(divider);
  723. }
  724. template<typename T>
  725. void Rectangle<T>::setRectangle(const Point<T>& pos2, const Size<T>& size2) noexcept
  726. {
  727. pos = pos2;
  728. size = size2;
  729. }
  730. template<typename T>
  731. void Rectangle<T>::setRectangle(const Rectangle<T>& rect) noexcept
  732. {
  733. pos = rect.pos;
  734. size = rect.size;
  735. }
  736. template<typename T>
  737. bool Rectangle<T>::contains(const T& x, const T& y) const noexcept
  738. {
  739. return (x >= pos.x && y >= pos.y && x <= pos.x+size.fWidth && y <= pos.y+size.fHeight);
  740. }
  741. template<typename T>
  742. bool Rectangle<T>::contains(const Point<T>& p) const noexcept
  743. {
  744. return contains(p.x, p.y);
  745. }
  746. template<typename T>
  747. template<typename T2>
  748. bool Rectangle<T>::contains(const Point<T2>& p) const noexcept
  749. {
  750. return (p.x >= pos.x && p.y >= pos.y && p.x <= pos.x+size.fWidth && p.y <= pos.y+size.fHeight);
  751. }
  752. template<> template<>
  753. bool Rectangle<int>::contains(const Point<double>& p) const noexcept
  754. {
  755. return (p.x >= pos.x && p.y >= pos.y && p.x <= pos.x+size.fWidth && p.y <= pos.y+size.fHeight);
  756. }
  757. template<> template<>
  758. bool Rectangle<uint>::contains(const Point<double>& p) const noexcept
  759. {
  760. return (p.x >= pos.x && p.y >= pos.y && p.x <= pos.x+size.fWidth && p.y <= pos.y+size.fHeight);
  761. }
  762. template<typename T>
  763. bool Rectangle<T>::containsX(const T& x) const noexcept
  764. {
  765. return (x >= pos.x && x <= pos.x + size.fWidth);
  766. }
  767. template<typename T>
  768. bool Rectangle<T>::containsY(const T& y) const noexcept
  769. {
  770. return (y >= pos.y && y <= pos.y + size.fHeight);
  771. }
  772. template<typename T>
  773. bool Rectangle<T>::isNull() const noexcept
  774. {
  775. return size.isNull();
  776. }
  777. template<typename T>
  778. bool Rectangle<T>::isNotNull() const noexcept
  779. {
  780. return size.isNotNull();
  781. }
  782. template<typename T>
  783. bool Rectangle<T>::isValid() const noexcept
  784. {
  785. return size.isValid();
  786. }
  787. template<typename T>
  788. bool Rectangle<T>::isInvalid() const noexcept
  789. {
  790. return size.isInvalid();
  791. }
  792. template<typename T>
  793. Rectangle<T>& Rectangle<T>::operator=(const Rectangle<T>& rect) noexcept
  794. {
  795. pos = rect.pos;
  796. size = rect.size;
  797. return *this;
  798. }
  799. template<typename T>
  800. Rectangle<T>& Rectangle<T>::operator*=(double m) noexcept
  801. {
  802. size *= m;
  803. return *this;
  804. }
  805. template<typename T>
  806. Rectangle<T>& Rectangle<T>::operator/=(double d) noexcept
  807. {
  808. size /= d;
  809. return *this;
  810. }
  811. template<typename T>
  812. bool Rectangle<T>::operator==(const Rectangle<T>& rect) const noexcept
  813. {
  814. return (pos == rect.pos && size == rect.size);
  815. }
  816. template<typename T>
  817. bool Rectangle<T>::operator!=(const Rectangle<T>& rect) const noexcept
  818. {
  819. return (pos != rect.pos || size != rect.size);
  820. }
  821. // -----------------------------------------------------------------------
  822. // Possible template data types
  823. template class Point<double>;
  824. template class Point<float>;
  825. template class Point<int>;
  826. template class Point<uint>;
  827. template class Point<short>;
  828. template class Point<ushort>;
  829. template class Size<double>;
  830. template class Size<float>;
  831. template class Size<int>;
  832. template class Size<uint>;
  833. template class Size<short>;
  834. template class Size<ushort>;
  835. template class Line<double>;
  836. template class Line<float>;
  837. template class Line<int>;
  838. template class Line<uint>;
  839. template class Line<short>;
  840. template class Line<ushort>;
  841. template class Circle<double>;
  842. template class Circle<float>;
  843. template class Circle<int>;
  844. template class Circle<uint>;
  845. template class Circle<short>;
  846. template class Circle<ushort>;
  847. template class Triangle<double>;
  848. template class Triangle<float>;
  849. template class Triangle<int>;
  850. template class Triangle<uint>;
  851. template class Triangle<short>;
  852. template class Triangle<ushort>;
  853. template class Rectangle<double>;
  854. template class Rectangle<float>;
  855. template class Rectangle<int>;
  856. template class Rectangle<uint>;
  857. template class Rectangle<short>;
  858. template class Rectangle<ushort>;
  859. // -----------------------------------------------------------------------
  860. END_NAMESPACE_DGL