Advertisement
Guest User

fonction intersection

a guest
Dec 6th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. public void intersection(AbstractImage image1, AbstractImage image2) {
  2.  
  3. Iterator<NodeState> it1 = image1.iterator();
  4. Iterator<NodeState> it2 = image2.iterator();
  5. Iterator<NodeState> it3 = this.iterator();
  6.  
  7. it3.clear();
  8.  
  9. if (!it1.isEmpty() && !it2.isEmpty()){
  10. intersectionR(it1, it2, it3);
  11. }
  12.  
  13. }
  14.  
  15. private void intersectionR(Iterator<NodeState> it1, Iterator<NodeState> it2, Iterator<NodeState> itThis) {
  16. if (!it1.isEmpty() && !it2.isEmpty()){
  17. NodeState ns1 = it1.getValue();
  18. NodeState ns2 = it2.getValue();
  19.  
  20. if (ns1.equals(NodeState.valueOf(0)) || ns2.equals(NodeState.valueOf(0))) {
  21. itThis.addValue(NodeState.valueOf(0));
  22. }
  23. else if (ns1.equals(NodeState.valueOf(1)) && ns2.equals(NodeState.valueOf(1))) {
  24. itThis.addValue(NodeState.valueOf(1));
  25. }
  26. else if (ns1.equals(NodeState.valueOf(2)) && ns2.equals(NodeState.valueOf(2))) {
  27. itThis.addValue(NodeState.valueOf(2));
  28. }
  29. else {
  30. itThis.addValue(NodeState.valueOf(2));
  31. if (ns1.equals(NodeState.valueOf(1))) {
  32. it1.goLeft();
  33. it1.addValue(NodeState.valueOf(1));
  34. it1.goUp();
  35. it1.goRight();
  36. it1.addValue(NodeState.valueOf(1));
  37. it1.goUp();
  38. } else {
  39. it2.goLeft();
  40. it2.addValue(NodeState.valueOf(1));
  41. it2.goUp();
  42. it2.goRight();
  43. it2.addValue(NodeState.valueOf(1));
  44. it2.goUp();
  45. }
  46. }
  47.  
  48. it1.goLeft();
  49. it2.goLeft();
  50. itThis.goLeft();
  51. intersectionR(it1, it2, itThis);
  52. it1.goUp();
  53. it2.goUp();
  54. itThis.goUp();
  55. it1.goRight();
  56. it2.goRight();
  57. itThis.goRight();
  58. intersectionR(it1, it2, itThis);
  59. it1.goUp();
  60. it2.goUp();
  61. itThis.goUp();
  62.  
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement