-1

So I wanna compute a covexhull but in the I want the right and left sets seperately. I cannot understand what Java is doint right here exactly. So I first call the hullset function for the right part and then put it in rightCov (at that point right set has 3 points). After that I can hullset for the left set . The problem is that even though I have "saved" the 3 points of the right set after the second call of the hullset,for the left set only,the variable rightCov takes all the 5 points of the covexhull without me using it again. The calls are below.

hullset(A, B, rightSet, covexHull);
ArrayList<Point> rightCov=covexHull;

hullset(A,B,leftSet, covexHull);
ChMil
  • 23
  • 5

1 Answers1

0

ArrayList<Point> rightCov=covexHull; assigns rightCov the same reference as covexHull so they both point to the same list in memory. You should use addAll methos to copy the elements from one array into another.

Andrew Sokolov
  • 277
  • 2
  • 12