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.

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