[jira] [Commented] (GEOMETRY-30) VectorBuilder?D Classes
[ https://issues.apache.org/jira/browse/GEOMETRY-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16938549#comment-16938549 ] Matt Juntunen commented on GEOMETRY-30: --- [Here|https://github.com/darkma773r/commons-geometry/blob/geometry-32-working/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/RegionBSPTree3D.java#L654] is an actual example from my geometry-32 working branch where I'm computing the region barycenter. I use separate doubles for each component to avoid unnecessary vector creation. This same type of construct is repeated in all of the other {{RegionBSPTreeXD}} classes. > VectorBuilder?D Classes > --- > > Key: GEOMETRY-30 > URL: https://issues.apache.org/jira/browse/GEOMETRY-30 > Project: Apache Commons Geometry > Issue Type: Wish >Reporter: Matt Juntunen >Priority: Major > > We should add a {{VectorBuilder?D}} class for each dimension. These classes > would have the same coordinate properties as their corresponding {{Vector}} > classes but would be mutable. They would be used to build {{Vector}} > instances from a number of input values without requiring a new instance to > be created for each step. The primary API should look something like this: > {code:java} > public class VectorBuilder2D { > double getX(); > VectorBuilder2D setX(double); > double getY(); > VectorBuilder2D setY(double); > VectorBuilder2D add(Vector2D); > VectorBuilder2D subtract(Vector2D); > VectorBuilder2D multiply(double); > Vector2D toVector(); > } > {code} > A good use case for this is computing a centroid: > {code:java} > VectorBuilder2D builder = new VectorBuilder2D(); > for (Vector2D pt : points) { > builder.add(pt); > } > builder.multiply(1.0 / points.size()); > Vector2D centroid = builder.toVector(); > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (GEOMETRY-30) VectorBuilder?D Classes
[ https://issues.apache.org/jira/browse/GEOMETRY-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16938578#comment-16938578 ] Gilles Sadowski commented on GEOMETRY-30: - bq. avoid unnecessary vector creation. At some point, it would be useful to create benchmarks (using [JMH|https://openjdk.java.net/projects/code-tools/jmh/]) so that we can assess when "unnecessary" equals "costly". bq. computing the region barycenter. Isn't that a case for a stream operation? > VectorBuilder?D Classes > --- > > Key: GEOMETRY-30 > URL: https://issues.apache.org/jira/browse/GEOMETRY-30 > Project: Apache Commons Geometry > Issue Type: Wish >Reporter: Matt Juntunen >Priority: Major > > We should add a {{VectorBuilder?D}} class for each dimension. These classes > would have the same coordinate properties as their corresponding {{Vector}} > classes but would be mutable. They would be used to build {{Vector}} > instances from a number of input values without requiring a new instance to > be created for each step. The primary API should look something like this: > {code:java} > public class VectorBuilder2D { > double getX(); > VectorBuilder2D setX(double); > double getY(); > VectorBuilder2D setY(double); > VectorBuilder2D add(Vector2D); > VectorBuilder2D subtract(Vector2D); > VectorBuilder2D multiply(double); > Vector2D toVector(); > } > {code} > A good use case for this is computing a centroid: > {code:java} > VectorBuilder2D builder = new VectorBuilder2D(); > for (Vector2D pt : points) { > builder.add(pt); > } > builder.multiply(1.0 / points.size()); > Vector2D centroid = builder.toVector(); > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (GEOMETRY-30) VectorBuilder?D Classes
[ https://issues.apache.org/jira/browse/GEOMETRY-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16938701#comment-16938701 ] Gilles Sadowski commented on GEOMETRY-30: - In order to figure what is actually necessary, perhaps start with a "minimal" implementation: {code} public class Vector2D { // ... public static class Builder { private double x; private double y; private Builder(double x, double y) { this.x = x; this.y = y; } public Builder create() { return new Builder(0, 0); } public Builder add(double x, double y) { this.x += x; this.y += y; } public Vector2D build(); } } {code} Then we should benchmark alternative implementations ("Builder" vs vector addition) in order to e.g. compute a barycenter. > VectorBuilder?D Classes > --- > > Key: GEOMETRY-30 > URL: https://issues.apache.org/jira/browse/GEOMETRY-30 > Project: Apache Commons Geometry > Issue Type: Wish >Reporter: Matt Juntunen >Priority: Major > > We should add a {{VectorBuilder?D}} class for each dimension. These classes > would have the same coordinate properties as their corresponding {{Vector}} > classes but would be mutable. They would be used to build {{Vector}} > instances from a number of input values without requiring a new instance to > be created for each step. The primary API should look something like this: > {code:java} > public class VectorBuilder2D { > double getX(); > VectorBuilder2D setX(double); > double getY(); > VectorBuilder2D setY(double); > VectorBuilder2D add(Vector2D); > VectorBuilder2D subtract(Vector2D); > VectorBuilder2D multiply(double); > Vector2D toVector(); > } > {code} > A good use case for this is computing a centroid: > {code:java} > VectorBuilder2D builder = new VectorBuilder2D(); > for (Vector2D pt : points) { > builder.add(pt); > } > builder.multiply(1.0 / points.size()); > Vector2D centroid = builder.toVector(); > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (GEOMETRY-30) VectorBuilder?D Classes
[ https://issues.apache.org/jira/browse/GEOMETRY-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17004631#comment-17004631 ] Matt Juntunen commented on GEOMETRY-30: --- I'm closing this issue since I no longer have a compelling use case for it. > VectorBuilder?D Classes > --- > > Key: GEOMETRY-30 > URL: https://issues.apache.org/jira/browse/GEOMETRY-30 > Project: Apache Commons Geometry > Issue Type: Wish >Reporter: Matt Juntunen >Priority: Major > > We should add a {{VectorBuilder?D}} class for each dimension. These classes > would have the same coordinate properties as their corresponding {{Vector}} > classes but would be mutable. They would be used to build {{Vector}} > instances from a number of input values without requiring a new instance to > be created for each step. The primary API should look something like this: > {code:java} > public class VectorBuilder2D { > double getX(); > VectorBuilder2D setX(double); > double getY(); > VectorBuilder2D setY(double); > VectorBuilder2D add(Vector2D); > VectorBuilder2D subtract(Vector2D); > VectorBuilder2D multiply(double); > Vector2D toVector(); > } > {code} > A good use case for this is computing a centroid: > {code:java} > VectorBuilder2D builder = new VectorBuilder2D(); > for (Vector2D pt : points) { > builder.add(pt); > } > builder.multiply(1.0 / points.size()); > Vector2D centroid = builder.toVector(); > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (GEOMETRY-30) VectorBuilder?D Classes
[ https://issues.apache.org/jira/browse/GEOMETRY-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16722436#comment-16722436 ] Gilles commented on GEOMETRY-30: I'm not convinced by the single centroid example method, where we'd spare 4 lines of code. IMO, it's not worth populating the API with mutable classes that will end up duplicating the immutable ones. > VectorBuilder?D Classes > --- > > Key: GEOMETRY-30 > URL: https://issues.apache.org/jira/browse/GEOMETRY-30 > Project: Apache Commons Geometry > Issue Type: Wish >Reporter: Matt Juntunen >Priority: Major > > We should add a {{VectorBuilder?D}} class for each dimension. These classes > would have the same coordinate properties as their corresponding {{Vector}} > classes but would be mutable. They would be used to build {{Vector}} > instances from a number of input values without requiring a new instance to > be created for each step. The primary API should look something like this: > {code:java} > public class VectorBuilder2D { > double getX(); > VectorBuilder2D setX(double); > double getY(); > VectorBuilder2D setY(double); > VectorBuilder2D add(Vector2D); > VectorBuilder2D subtract(Vector2D); > VectorBuilder2D multiply(double); > Vector2D toVector(); > } > {code} > A good use case for this is computing a centroid: > {code:java} > VectorBuilder2D builder = new VectorBuilder2D(); > for (Vector2D pt : points) { > builder.add(pt); > } > builder.multiply(1.0 / points.size()); > Vector2D centroid = builder.toVector(); > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)