google / s2-geometry-library-java

Automatically exported from code.google.com/p/s2-geometry-library-java
Apache License 2.0
533 stars 230 forks source link

Adding additional attribute to S2Polygon class for custom feature? #24

Closed animesh-sharama closed 3 years ago

animesh-sharama commented 4 years ago

Hi, I would like to add additional attribute to the S2Polygon class since its final I can't extend it. The only way I can think of it is by replicating the class and adding additional constructor.

Is there any better way of doing it or the recommendation for such use case?

Original issue - https://github.com/google/s2geometry/issues/116

datamacgyver commented 3 years ago

Depends what you are trying to accomplish, what about this:

public class MyPolygon{
   S2Polygon poly;
   String attribute;

  public MyPolygon(S2Polygon poly, String attirbute){
      this.poly = poly;
      this.attribyte = attribute;
  }
}

Add getters/setters as you see fit.

animesh-sharama commented 3 years ago

The custom class MyPolygon cannot be used inside the S2PointIndex I guess https://github.com/cpovirk/s2-geometry-library-java/blob/moesync/src/com/google/common/geometry/S2PointIndex.java

jmr commented 3 years ago

It looks like you're supposed to use the templated add(): https://github.com/cpovirk/s2-geometry-library-java/blob/moesync/src/com/google/common/geometry/S2PointIndex.java#L101

Here's the not very clear documentation pointer: https://github.com/cpovirk/s2-geometry-library-java/blob/moesync/src/com/google/common/geometry/S2PointIndex.java#L38

eengle commented 3 years ago

Yeah wrapping is usually better, although depends a bit on what you're doing. Feel free to reopen this if you have additional details to add to the conversation.