PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/JavApi/org/apache/harmony/awt/gl/MultiRectArea.cs

#
C# | 952 lines | 643 code | 96 blank | 213 comment | 95 complexity | d744e11602919d299caebcdb20af534b MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14. using System;
  15. using java = biz.ritter.javapi;
  16. namespace org.apache.harmony.awt.gl
  17. {
  18. internal class MultiRectArea : java.awt.Shape
  19. {
  20. /**
  21. * If CHECK is true validation check active
  22. */
  23. private const bool CHECK = false;
  24. internal bool sorted = true;
  25. /**
  26. * Rectangle buffer
  27. */
  28. public int[] rect;
  29. /**
  30. * Bounding box
  31. */
  32. java.awt.Rectangle bounds;
  33. /**
  34. * Result rectangle array
  35. */
  36. java.awt.Rectangle[] rectangles;
  37. /**
  38. * LineCash provides creating MultiRectArea line by line. Used in JavaShapeRasterizer.
  39. */
  40. public class LineCash : MultiRectArea
  41. {
  42. int lineY;
  43. int bottomCount;
  44. int[] bottom;
  45. public LineCash(int size)
  46. : base()
  47. {
  48. bottom = new int[size];
  49. bottomCount = 0;
  50. }
  51. public void setLine(int y)
  52. {
  53. lineY = y;
  54. }
  55. public void skipLine()
  56. {
  57. lineY++;
  58. bottomCount = 0;
  59. }
  60. public void addLine(int[] points, int pointCount)
  61. {
  62. int bottomIndex = 0;
  63. int pointIndex = 0;
  64. int rectIndex = 0;
  65. int pointX1 = 0;
  66. int pointX2 = 0;
  67. int bottomX1 = 0;
  68. int bottomX2 = 0;
  69. bool appendRect = false;
  70. bool deleteRect = false;
  71. int lastCount = bottomCount;
  72. while (bottomIndex < lastCount || pointIndex < pointCount)
  73. {
  74. appendRect = false;
  75. deleteRect = false;
  76. if (bottomIndex < lastCount)
  77. {
  78. rectIndex = bottom[bottomIndex];
  79. bottomX1 = rect[rectIndex];
  80. bottomX2 = rect[rectIndex + 2];
  81. }
  82. else
  83. {
  84. appendRect = true;
  85. }
  86. if (pointIndex < pointCount)
  87. {
  88. pointX1 = points[pointIndex];
  89. pointX2 = points[pointIndex + 1];
  90. }
  91. else
  92. {
  93. deleteRect = true;
  94. }
  95. if (!deleteRect && !appendRect)
  96. {
  97. if (pointX1 == bottomX1 && pointX2 == bottomX2)
  98. {
  99. rect[rectIndex + 3] = rect[rectIndex + 3] + 1;
  100. pointIndex += 2;
  101. bottomIndex++;
  102. continue;
  103. }
  104. deleteRect = pointX2 >= bottomX1;
  105. appendRect = pointX1 <= bottomX2;
  106. }
  107. if (deleteRect)
  108. {
  109. if (bottomIndex < bottomCount - 1)
  110. {
  111. java.lang.SystemJ.arraycopy(bottom, bottomIndex + 1, bottom, bottomIndex, bottomCount - bottomIndex - 1);
  112. rectIndex -= 4;
  113. }
  114. bottomCount--;
  115. lastCount--;
  116. }
  117. if (appendRect)
  118. {
  119. int i = rect[0];
  120. bottom[bottomCount++] = i;
  121. rect = MultiRectAreaOp.checkBufSize(rect, 4);
  122. rect[i++] = pointX1;
  123. rect[i++] = lineY;
  124. rect[i++] = pointX2;
  125. rect[i++] = lineY;
  126. pointIndex += 2;
  127. }
  128. }
  129. lineY++;
  130. invalidate();
  131. }
  132. }
  133. /**
  134. * RectCash provides simple creating MultiRectArea
  135. */
  136. internal class RectCash : MultiRectArea
  137. {
  138. int[] cash;
  139. public RectCash()
  140. : base()
  141. {
  142. cash = new int[MultiRectAreaOp.RECT_CAPACITY];
  143. cash[0] = 1;
  144. }
  145. public void addRectCashed(int x1, int y1, int x2, int y2)
  146. {
  147. addRect(x1, y1, x2, y2);
  148. invalidate();
  149. /*
  150. // Exclude from cash unnecessary rectangles
  151. int i = 1;
  152. while(i < cash[0]) {
  153. if (rect[cash[i] + 3] >= y1 - 1) {
  154. if (i > 1) {
  155. System.arraycopy(cash, i, cash, 1, cash[0] - i);
  156. }
  157. break;
  158. }
  159. i++;
  160. }
  161. cash[0] -= i - 1;
  162. // Find in cash rectangle to concatinate
  163. i = 1;
  164. while(i < cash[0]) {
  165. int index = cash[i];
  166. if (rect[index + 3] != y1 - 1) {
  167. break;
  168. }
  169. if (rect[index] == x1 && rect[index + 2] == x2) {
  170. rect[index + 3] += y2 - y1 + 1;
  171. int pos = i + 1;
  172. while(pos < cash[0]) {
  173. if (rect[index + 3] <= rect[cash[i] + 3]) {
  174. System.arraycopy(cash, i + 1, cash, i, pos - i);
  175. break;
  176. }
  177. i++;
  178. }
  179. cash[pos - 1] = index;
  180. invalidate();
  181. return;
  182. }
  183. i++;
  184. }
  185. // Add rectangle to buffer
  186. int index = rect[0];
  187. rect = MultiRectAreaOp.checkBufSize(rect, 4);
  188. rect[index + 0] = x1;
  189. rect[index + 1] = y1;
  190. rect[index + 2] = x2;
  191. rect[index + 3] = y2;
  192. // Add rectangle to cash
  193. int length = cash[0];
  194. cash = MultiRectAreaOp.checkBufSize(cash, 1);
  195. while(i < length) {
  196. if (y2 <= rect[cash[i] + 3]) {
  197. System.arraycopy(cash, i, cash, i + 1, length - i);
  198. break;
  199. }
  200. i++;
  201. }
  202. cash[i] = index;
  203. invalidate();
  204. */
  205. }
  206. public void addRectCashed(int[] rect, int rectOff, int rectLength)
  207. {
  208. for (int i = rectOff; i < rectOff + rectLength; )
  209. {
  210. addRect(rect[i++], rect[i++], rect[i++], rect[i++]);
  211. // addRectCashed(rect[i++], rect[i++], rect[i++], rect[i++]);
  212. }
  213. }
  214. }
  215. /**
  216. * MultiRectArea path iterator
  217. */
  218. internal class Iterator : java.awt.geom.PathIterator
  219. {
  220. int type;
  221. int index;
  222. int pos;
  223. int[] rect;
  224. java.awt.geom.AffineTransform t;
  225. internal Iterator(MultiRectArea mra, java.awt.geom.AffineTransform t)
  226. {
  227. rect = new int[mra.rect[0] - 1];
  228. java.lang.SystemJ.arraycopy(mra.rect, 1, rect, 0, rect.Length);
  229. this.t = t;
  230. }
  231. public int getWindingRule()
  232. {
  233. return java.awt.geom.PathIteratorConstants.WIND_NON_ZERO;
  234. }
  235. public bool isDone()
  236. {
  237. return pos >= rect.Length;
  238. }
  239. public void next()
  240. {
  241. if (index == 4)
  242. {
  243. pos += 4;
  244. }
  245. index = (index + 1) % 5;
  246. }
  247. public int currentSegment(double[] coords)
  248. {
  249. if (isDone())
  250. {
  251. // awt.4B=Iiterator out of bounds
  252. throw new java.util.NoSuchElementException("Iterator out of bounds"); //$NON-NLS-1$
  253. }
  254. int type = 0;
  255. switch (index)
  256. {
  257. case 0:
  258. type = java.awt.geom.PathIteratorConstants.SEG_MOVETO;
  259. coords[0] = rect[pos + 0];
  260. coords[1] = rect[pos + 1];
  261. break;
  262. case 1:
  263. type = java.awt.geom.PathIteratorConstants.SEG_LINETO;
  264. coords[0] = rect[pos + 2];
  265. coords[1] = rect[pos + 1];
  266. break;
  267. case 2:
  268. type = java.awt.geom.PathIteratorConstants.SEG_LINETO;
  269. coords[0] = rect[pos + 2];
  270. coords[1] = rect[pos + 3];
  271. break;
  272. case 3:
  273. type = java.awt.geom.PathIteratorConstants.SEG_LINETO;
  274. coords[0] = rect[pos + 0];
  275. coords[1] = rect[pos + 3];
  276. break;
  277. case 4:
  278. type = java.awt.geom.PathIteratorConstants.SEG_CLOSE;
  279. break;
  280. }
  281. if (t != null)
  282. {
  283. t.transform(coords, 0, coords, 0, 1);
  284. }
  285. return type;
  286. }
  287. public int currentSegment(float[] coords)
  288. {
  289. if (isDone())
  290. {
  291. // awt.4B=Iiterator out of bounds
  292. throw new java.util.NoSuchElementException("Iterator out of bounds"); //$NON-NLS-1$
  293. }
  294. int type = 0;
  295. switch (index)
  296. {
  297. case 0:
  298. type = java.awt.geom.PathIteratorConstants.SEG_MOVETO;
  299. coords[0] = rect[pos + 0];
  300. coords[1] = rect[pos + 1];
  301. break;
  302. case 1:
  303. type = java.awt.geom.PathIteratorConstants.SEG_LINETO;
  304. coords[0] = rect[pos + 2];
  305. coords[1] = rect[pos + 1];
  306. break;
  307. case 2:
  308. type = java.awt.geom.PathIteratorConstants.SEG_LINETO;
  309. coords[0] = rect[pos + 2];
  310. coords[1] = rect[pos + 3];
  311. break;
  312. case 3:
  313. type = java.awt.geom.PathIteratorConstants.SEG_LINETO;
  314. coords[0] = rect[pos + 0];
  315. coords[1] = rect[pos + 3];
  316. break;
  317. case 4:
  318. type = java.awt.geom.PathIteratorConstants.SEG_CLOSE;
  319. break;
  320. }
  321. if (t != null)
  322. {
  323. t.transform(coords, 0, coords, 0, 1);
  324. }
  325. return type;
  326. }
  327. }
  328. /**
  329. * Constructs a new empty MultiRectArea
  330. */
  331. public MultiRectArea()
  332. {
  333. rect = MultiRectAreaOp.createBuf(0);
  334. }
  335. public MultiRectArea(bool sorted)
  336. : this()
  337. {
  338. this.sorted = sorted;
  339. }
  340. /**
  341. * Constructs a new MultiRectArea as a copy of another one
  342. */
  343. public MultiRectArea(MultiRectArea mra)
  344. {
  345. if (mra == null)
  346. {
  347. rect = MultiRectAreaOp.createBuf(0);
  348. }
  349. else
  350. {
  351. rect = new int[mra.rect.Length];
  352. java.lang.SystemJ.arraycopy(mra.rect, 0, rect, 0, mra.rect.Length);
  353. check(this, "MultiRectArea(MRA)"); //$NON-NLS-1$
  354. }
  355. }
  356. /**
  357. * Constructs a new MultiRectArea consists of single rectangle
  358. */
  359. public MultiRectArea(java.awt.Rectangle r)
  360. {
  361. rect = MultiRectAreaOp.createBuf(0);
  362. if (r != null && !r.isEmpty())
  363. {
  364. rect[0] = 5;
  365. rect[1] = r.x;
  366. rect[2] = r.y;
  367. rect[3] = r.x + r.width - 1;
  368. rect[4] = r.y + r.height - 1;
  369. }
  370. check(this, "MultiRectArea(Rectangle)"); //$NON-NLS-1$
  371. }
  372. /**
  373. * Constructs a new MultiRectArea consists of single rectangle
  374. */
  375. public MultiRectArea(int x0, int y0, int x1, int y1)
  376. {
  377. rect = MultiRectAreaOp.createBuf(0);
  378. if (x1 >= x0 && y1 >= y0)
  379. {
  380. rect[0] = 5;
  381. rect[1] = x0;
  382. rect[2] = y0;
  383. rect[3] = x1;
  384. rect[4] = y1;
  385. }
  386. check(this, "MultiRectArea(Rectangle)"); //$NON-NLS-1$
  387. }
  388. /**
  389. * Constructs a new MultiRectArea and append rectangle from buffer
  390. */
  391. public MultiRectArea(java.awt.Rectangle[] buf)
  392. : this()
  393. {
  394. foreach (java.awt.Rectangle element in buf)
  395. {
  396. add(element);
  397. }
  398. }
  399. /**
  400. * Constructs a new MultiRectArea and append rectangle from array
  401. */
  402. public MultiRectArea(java.util.ArrayList<java.awt.Rectangle> buf)
  403. : this()
  404. {
  405. for (int i = 0; i < buf.size(); i++)
  406. { //Basties note: also foreach available...
  407. add(buf.get(i));
  408. }
  409. }
  410. /**
  411. * Sort rectangle buffer
  412. */
  413. internal void resort()
  414. {
  415. int[] buf = new int[4];
  416. for (int i = 1; i < rect[0]; i += 4)
  417. {
  418. int k = i;
  419. int x1 = rect[k];
  420. int y1 = rect[k + 1];
  421. for (int j = i + 4; j < rect[0]; j += 4)
  422. {
  423. int x2 = rect[j];
  424. int y2 = rect[j + 1];
  425. if (y1 > y2 || (y1 == y2 && x1 > x2))
  426. {
  427. x1 = x2;
  428. y1 = y2;
  429. k = j;
  430. }
  431. }
  432. if (k != i)
  433. {
  434. java.lang.SystemJ.arraycopy(rect, i, buf, 0, 4);
  435. java.lang.SystemJ.arraycopy(rect, k, rect, i, 4);
  436. java.lang.SystemJ.arraycopy(buf, 0, rect, k, 4);
  437. }
  438. }
  439. invalidate();
  440. }
  441. /**
  442. * Tests equals with another object
  443. */
  444. public override bool Equals(Object obj)
  445. {
  446. if (obj == this)
  447. {
  448. return true;
  449. }
  450. if (obj is MultiRectArea)
  451. {
  452. MultiRectArea mra = (MultiRectArea)obj;
  453. for (int i = 0; i < rect[0]; i++)
  454. {
  455. if (rect[i] != mra.rect[i])
  456. {
  457. return false;
  458. }
  459. }
  460. return true;
  461. }
  462. return false;
  463. }
  464. /**
  465. * Checks validation of MultiRectArea object
  466. */
  467. static MultiRectArea check(MultiRectArea mra, String msg)
  468. {
  469. if (CHECK && mra != null)
  470. {
  471. if (MultiRectArea.checkValidation(mra.getRectangles(), mra.sorted) != -1)
  472. {
  473. // awt.4C=Invalid MultiRectArea in method {0}
  474. new java.lang.RuntimeException("Invalid MultiRectArea in method " + msg); //$NON-NLS-1$
  475. }
  476. }
  477. return mra;
  478. }
  479. /**
  480. * Checks validation of MultiRectArea object
  481. */
  482. public static int checkValidation(java.awt.Rectangle[] r, bool sorted)
  483. {
  484. // Check width and height
  485. for (int i = 0; i < r.Length; i++)
  486. {
  487. if (r[i].width <= 0 || r[i].height <= 0)
  488. {
  489. return i;
  490. }
  491. }
  492. // Check order
  493. if (sorted)
  494. {
  495. for (int i = 1; i < r.Length; i++)
  496. {
  497. if (r[i - 1].y > r[i].y)
  498. {
  499. return i;
  500. }
  501. if (r[i - 1].y == r[i].y)
  502. {
  503. if (r[i - 1].x > r[i].x)
  504. {
  505. return i;
  506. }
  507. }
  508. }
  509. }
  510. // Check override
  511. for (int i = 0; i < r.Length; i++)
  512. {
  513. for (int j = i + 1; j < r.Length; j++)
  514. {
  515. if (r[i].intersects(r[j]))
  516. {
  517. return i;
  518. }
  519. }
  520. }
  521. return -1;
  522. }
  523. /**
  524. * Assigns rectangle from another buffer
  525. */
  526. protected internal void setRect(int[] buf, bool copy)
  527. {
  528. if (copy)
  529. {
  530. rect = new int[buf.Length];
  531. java.lang.SystemJ.arraycopy(buf, 0, rect, 0, buf.Length);
  532. }
  533. else
  534. {
  535. rect = buf;
  536. }
  537. invalidate();
  538. }
  539. /**
  540. * Union with another MultiRectArea object
  541. */
  542. public void add(MultiRectArea mra)
  543. {
  544. setRect(union(this, mra).rect, false);
  545. invalidate();
  546. }
  547. /**
  548. * Intersect with another MultiRectArea object
  549. */
  550. public void intersect(MultiRectArea mra)
  551. {
  552. setRect(intersect(this, mra).rect, false);
  553. invalidate();
  554. }
  555. /**
  556. * Subtract another MultiRectArea object
  557. */
  558. public void substract(MultiRectArea mra)
  559. {
  560. setRect(subtract(this, mra).rect, false);
  561. invalidate();
  562. }
  563. /**
  564. * Union with Rectangle object
  565. */
  566. public void add(java.awt.Rectangle rect)
  567. {
  568. setRect(union(this, new MultiRectArea(rect)).rect, false);
  569. invalidate();
  570. }
  571. /**
  572. * Intersect with Rectangle object
  573. */
  574. public void intersect(java.awt.Rectangle rect)
  575. {
  576. setRect(intersect(this, new MultiRectArea(rect)).rect, false);
  577. invalidate();
  578. }
  579. /**
  580. * Subtract rectangle object
  581. */
  582. public void substract(java.awt.Rectangle rect)
  583. {
  584. setRect(subtract(this, new MultiRectArea(rect)).rect, false);
  585. }
  586. /**
  587. * Union two MutliRectareArea objects
  588. */
  589. public static MultiRectArea intersect(MultiRectArea src1, MultiRectArea src2)
  590. {
  591. MultiRectArea res = check(MultiRectAreaOp.Intersection.getResult(src1, src2), "intersect(MRA,MRA)"); //$NON-NLS-1$
  592. return res;
  593. }
  594. /**
  595. * Intersect two MultiRectArea objects
  596. */
  597. public static MultiRectArea union(MultiRectArea src1, MultiRectArea src2)
  598. {
  599. MultiRectArea res = check(new MultiRectAreaOp.Union().getResult(src1, src2), "union(MRA,MRA)"); //$NON-NLS-1$
  600. return res;
  601. }
  602. /**
  603. * Subtract two MultiRectArea objects
  604. */
  605. public static MultiRectArea subtract(MultiRectArea src1, MultiRectArea src2)
  606. {
  607. MultiRectArea res = check(MultiRectAreaOp.Subtraction.getResult(src1, src2), "subtract(MRA,MRA)"); //$NON-NLS-1$
  608. return res;
  609. }
  610. /**
  611. * Print MultiRectArea object to output stream
  612. */
  613. public static void print(MultiRectArea mra, String msg)
  614. {
  615. if (mra == null)
  616. {
  617. java.lang.SystemJ.outJ.println(msg + "=null"); //$NON-NLS-1$
  618. }
  619. else
  620. {
  621. java.awt.Rectangle[] rects = mra.getRectangles();
  622. java.lang.SystemJ.outJ.println(msg + "(" + rects.Length + ")"); //$NON-NLS-1$ //$NON-NLS-2$
  623. foreach (java.awt.Rectangle element in rects)
  624. {
  625. java.lang.SystemJ.outJ.println(
  626. element.x + "," + //$NON-NLS-1$
  627. element.y + "," + //$NON-NLS-1$
  628. (element.x + element.width - 1) + "," + //$NON-NLS-1$
  629. (element.y + element.height - 1));
  630. }
  631. }
  632. }
  633. /**
  634. * Translate MultiRectArea object by (x, y)
  635. */
  636. public void translate(int x, int y)
  637. {
  638. for (int i = 1; i < rect[0]; )
  639. {
  640. rect[i++] += x;
  641. rect[i++] += y;
  642. rect[i++] += x;
  643. rect[i++] += y;
  644. }
  645. if (bounds != null && !bounds.isEmpty())
  646. {
  647. bounds.translate(x, y);
  648. }
  649. if (rectangles != null)
  650. {
  651. foreach (java.awt.Rectangle element in rectangles)
  652. {
  653. element.translate(x, y);
  654. }
  655. }
  656. }
  657. /**
  658. * Add rectangle to the buffer without any checking
  659. */
  660. public void addRect(int x1, int y1, int x2, int y2)
  661. {
  662. int i = rect[0];
  663. rect = MultiRectAreaOp.checkBufSize(rect, 4);
  664. rect[i++] = x1;
  665. rect[i++] = y1;
  666. rect[i++] = x2;
  667. rect[i++] = y2;
  668. }
  669. /**
  670. * Tests is MultiRectArea empty
  671. */
  672. public bool isEmpty()
  673. {
  674. return rect[0] == 1;
  675. }
  676. void invalidate()
  677. {
  678. bounds = null;
  679. rectangles = null;
  680. }
  681. /**
  682. * Returns bounds of MultiRectArea object
  683. */
  684. public java.awt.Rectangle getBounds()
  685. {
  686. if (bounds != null)
  687. {
  688. return bounds;
  689. }
  690. if (isEmpty())
  691. {
  692. return bounds = new java.awt.Rectangle();
  693. }
  694. int x1 = rect[1];
  695. int y1 = rect[2];
  696. int x2 = rect[3];
  697. int y2 = rect[4];
  698. for (int i = 5; i < rect[0]; i += 4)
  699. {
  700. int rx1 = rect[i + 0];
  701. int ry1 = rect[i + 1];
  702. int rx2 = rect[i + 2];
  703. int ry2 = rect[i + 3];
  704. if (rx1 < x1)
  705. {
  706. x1 = rx1;
  707. }
  708. if (rx2 > x2)
  709. {
  710. x2 = rx2;
  711. }
  712. if (ry1 < y1)
  713. {
  714. y1 = ry1;
  715. }
  716. if (ry2 > y2)
  717. {
  718. y2 = ry2;
  719. }
  720. }
  721. return bounds = new java.awt.Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
  722. }
  723. /**
  724. * Return rectangle count in the buffer
  725. */
  726. public int getRectCount()
  727. {
  728. return (rect[0] - 1) / 4;
  729. }
  730. /**
  731. * Returns Rectangle array
  732. */
  733. public java.awt.Rectangle[] getRectangles()
  734. {
  735. if (rectangles != null)
  736. {
  737. return rectangles;
  738. }
  739. rectangles = new java.awt.Rectangle[(rect[0] - 1) / 4];
  740. int j = 0;
  741. for (int i = 1; i < rect[0]; i += 4)
  742. {
  743. rectangles[j++] = new java.awt.Rectangle(
  744. rect[i],
  745. rect[i + 1],
  746. rect[i + 2] - rect[i] + 1,
  747. rect[i + 3] - rect[i + 1] + 1);
  748. }
  749. return rectangles;
  750. }
  751. /**
  752. * Returns Bounds2D
  753. */
  754. public java.awt.geom.Rectangle2D getBounds2D()
  755. {
  756. return getBounds();
  757. }
  758. /**
  759. * Tests does point lie inside MultiRectArea object
  760. */
  761. public bool contains(double x, double y)
  762. {
  763. for (int i = 1; i < rect[0]; i += 4)
  764. {
  765. if (rect[i] <= x && x <= rect[i + 2] && rect[i + 1] <= y && y <= rect[i + 3])
  766. {
  767. return true;
  768. }
  769. }
  770. return false;
  771. }
  772. /**
  773. * Tests does Point2D lie inside MultiRectArea object
  774. */
  775. public bool contains(java.awt.geom.Point2D p)
  776. {
  777. return contains(p.getX(), p.getY());
  778. }
  779. /**
  780. * Tests does rectangle lie inside MultiRectArea object
  781. */
  782. public bool contains(double x, double y, double w, double h)
  783. {
  784. throw new java.lang.RuntimeException("Not implemented"); //$NON-NLS-1$
  785. }
  786. /**
  787. * Tests does Rectangle2D lie inside MultiRectArea object
  788. */
  789. public bool contains(java.awt.geom.Rectangle2D r)
  790. {
  791. return this.contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); // Basties note: easy to implement...
  792. }
  793. /**
  794. * Tests does rectangle intersect MultiRectArea object
  795. */
  796. public bool intersects(double x, double y, double w, double h)
  797. {
  798. java.awt.Rectangle r = new java.awt.Rectangle();
  799. r.setRect(x, y, w, h);
  800. return intersects(r);
  801. }
  802. /**
  803. * Tests does Rectangle2D intersect MultiRectArea object
  804. */
  805. public bool intersects(java.awt.geom.Rectangle2D r)
  806. {
  807. if (r == null || r.isEmpty())
  808. {
  809. return false;
  810. }
  811. for (int i = 1; i < rect[0]; i += 4)
  812. {
  813. if (r.intersects(rect[i], rect[i + 1], rect[i + 2] - rect[i] + 1, rect[i + 3] - rect[i + 1] + 1))
  814. {
  815. return true;
  816. }
  817. }
  818. return false;
  819. }
  820. /**
  821. * Returns path iterator
  822. */
  823. public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t, double flatness)
  824. {
  825. return new Iterator(this, t);
  826. }
  827. /**
  828. * Returns path iterator
  829. */
  830. public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t)
  831. {
  832. return new Iterator(this, t);
  833. }
  834. /**
  835. * Returns MultiRectArea object converted to string
  836. */
  837. public override String ToString()
  838. {
  839. int cnt = getRectCount();
  840. java.lang.StringBuilder sb = new java.lang.StringBuilder((cnt << 5) + 128);
  841. sb.append(this.getClass().getName()).append(" ["); //$NON-NLS-1$
  842. for (int i = 1; i < rect[0]; i += 4)
  843. {
  844. sb.append(i > 1 ? ", [" : "[").append(rect[i]).append(", ").append(rect[i + 1]). //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  845. append(", ").append(rect[i + 2] - rect[i] + 1).append(", "). //$NON-NLS-1$ //$NON-NLS-2$
  846. append(rect[i + 3] - rect[i + 1] + 1).append("]"); //$NON-NLS-1$
  847. }
  848. return sb.append("]").toString(); //$NON-NLS-1$
  849. }
  850. }
  851. }