ImmutablePart::getEndPoint doesn’t return the last point

762
3
Jump to solution
02-16-2017 04:10 AM
HenrikPierrou
New Contributor II

Hi,

The last point when iterating over the points in an ImmutablePart is not the point returned in getEndPoint() on that same ImmutablePart. See my example below. Why is that? I'm on ArcGIS Runtime for Android 100.0.0.

private void partTest(ImmutablePart part) {
   for (int i = 0; i < part.getPointCount(); i++) {
      Point p = part.getPoint(i);
      System.out.println(i + " - " + p.getX() + ", " + p.getY());
   }

   Point startPoint = part.getStartPoint();
   System.out.println("Start point - " + startPoint.getX() + ", " + startPoint.getY());

   Point endPoint = part.getEndPoint();
   System.out.println("End point - " + endPoint.getX() + ", " + endPoint.getY());
}

Printouts when running the above with a ImmutablePart over Stockholm:

I/System.out: 0 - 2000955.7131845958, 8217577.284820005
I/System.out: 1 - 1989299.2266646507, 8248738.619869451
I/System.out: 2 - 2011153.6917361675, 8252952.245694454
I/System.out: Start point - 2000955.7131845958, 8217577.284820005
I/System.out: End point - 1989299.2266646507, 8248738.619869451

Regards

Henrik

0 Kudos
1 Solution

Accepted Solutions
ShellyGill1
Esri Contributor

Hi Henrik - I'm assuming you have got your ImmutablePart from a Polyline? I can repro that bug as you described. If you get the ImmutablePart from a Polygon, then you should find that the ImmutablePart.getEndPoint is the same as the last Point from ImmutablePart.getPoint(i). (I just double-checked the Segments and in both cases I find Segment.StartPoint and SegmentEndPoint are returning the expected Points.)

Thanks for finding and reporting this, I will enter this as an issue for us to address.

Regards,

Shelly

View solution in original post

3 Replies
HenrikPierrou
New Contributor II

I think I found the problem. In the current version of the runtime the index of the last point in an ImmutablePart is calculated based on the number of segments instead of the number of points. In the decompiled ImmutablePart, the getEndPoint method looks like this

public Point getEndPoint() {
   if(this.mEndPoint == null && !this.isEmpty()) {
      this.mEndPoint = Point.createFromInternal(this.mCoreImmutablePart.b((long)(this.size() - 1)));
   }

   return this.mEndPoint;
}

Instead of “this.size() - 1”, I guess it should be “this.getPointCount() - 1”

0 Kudos
ShellyGill1
Esri Contributor

Hi Henrik - I'm assuming you have got your ImmutablePart from a Polyline? I can repro that bug as you described. If you get the ImmutablePart from a Polygon, then you should find that the ImmutablePart.getEndPoint is the same as the last Point from ImmutablePart.getPoint(i). (I just double-checked the Segments and in both cases I find Segment.StartPoint and SegmentEndPoint are returning the expected Points.)

Thanks for finding and reporting this, I will enter this as an issue for us to address.

Regards,

Shelly

HenrikPierrou
New Contributor II

Great, thank you Shelly!

Regards

Henrik

0 Kudos