Hello, > its a bit bad to code against internal representations.
I would not consider the utility method above as a use of an internal representation. The toArray() method is a part of the public API and was created for use cases such as this. > What do you think about two methods, transformX and transformY that take a > single double and return the transformed value? That's an interesting idea. Create a new JIRA issue for it and we can go from there. > I also noticed that there is no dedicated "shear" method, if I open a PR > could it be in-cooperated? You bet. That is definitely something lacking in the API. Same as above, create a JIRA issue for it and we can talk about it there. Note that if you plan on submitting PRs, make sure you've gone through the documentation in the CONTRIBUTING.md file in the repo. Specifically, you'll need a signed Contributor License Agreement on file with the ASF. Regards, Matt ________________________________ From: Christoph Läubrich <[email protected]> Sent: Monday, March 22, 2021 3:24 AM To: [email protected] <[email protected]> Subject: Re: [math] AffineTransformMatrix2D Hi Matt, thanks for the feedback, I have commented on the bug. Regarding the "direct" method you are most probably right. I have arrays that are easily can extend 10k or even 100k points that means in extreme cases 200k Objects created and instantly destroyed as well as the corresponding method calls. Even if this is not noticeable in some scenarios it adds an unnecessary penalty. I have already thought about the util method (and actually using it currently) but its a bit bad to code against internal representations. In the end of course I do not need to use the Affine transform at all and can work on transform-matrix itself but thats not really the goal :-) What do you think about two methods, transformX and transformY that take a single double and return the transformed value? public double transformX(final double x, double y) { return LinearCombination.value(m00, x, m01, y) + m02; } public double transformY(final double x, double y) { return LinearCombination.value(m10, x, m11, y) + m12; } I also noticed that there is no dedicated "shear" method, if I open a PR could it be in-cooperated? Am 21.03.21 um 19:07 schrieb Matt Juntunen: > Hello, > > It's entirely possible that the OSGi headers are incorrect. I've created a > new issue (GEOMETRY-116 [1]) for it. We can continue that part of this > discussion there. > > The "internal" package in commons-geometry-core is intended to be internal > from the standpoint of the library. Classes under this package (and > "internal" packages in other modules) are not considered part of the public > API and are not guaranteed to be binary compatible with previous releases. > From a practical standpoint, however, these packages do need to be exported > and available for use by the other modules in the library. > > In regard to the new method you mentioned, I am hesitant to add that to the > API. The main reason is that there are a large number of possible ways to > represent 2D vectors as arrays. For example, the xy components could be in > two parallel arrays (as in your example), a single array with interleaved xy > components (eg, [x1,y1,x2,y2,...]), a multidimensional array (eg, > [[x1,y1],[x2,y2]...]), etc. Adding this method could open up a can of worms > as to which formats are accepted by the API. It would keep the API cleaner by > leaving this functionality to consuming applications. You could, for example, > use AffineTransformMatrix2D as-is for matrix creation and manipulation and > create a utility method in your application that performs the required > transformations using the target format. > > public static void applyTransform(AffineTransformMatrix2D m, double[] x, > double[] y) { > // input checking, etc > double[] mArr = m.toArray(); > for (int i = 0; i < x.length; ++i { > x[i] = LinearCombination.value(mArr[0], x[i], mArr[1], y[i]) + > mArr[2]; > y[i] = LinearCombination.value(mArr[3], x[i], mArr[4], y[i]) + > mArr[5]; > } > } > > I would also be interested in seeing if there is an actual performance > improvement when skipping the Vector2D instantiations. In my experience, > optimizations such as this sometimes don't really make a difference. > > Regards, > Matt J > > [1] https://issues.apache.org/jira/projects/GEOMETRY/issues/GEOMETRY-116 > ________________________________ > From: Christoph Läubrich <[email protected]> > Sent: Sunday, March 21, 2021 8:40 AM > To: [email protected] <[email protected]> > Subject: Re: [math] 2D Line getOffset and natural orientation > > Hi Matt, > > just some feedback on the AffineTransformMatrix2D in general I think it > would be good to have methods that accept a plain array. for example I > have an array of x and y values and like to transform them. > > Currently I need to first construct a Vector of each x/y pair, then > apply the transform (what create another Vector), and copy the data back > to the array. > > so a method apply [double[] x, double[] y) that simply performs the > transform in-place would prevent a lot of instantiation overhead. > > > Am 20.03.21 um 13:25 schrieb Matt Juntunen: >> It's available on maven central [1]. You can find the code on the Apache git >> repo [2] or on Github [3]. The user guide [4] gives an overview of the >> library along with code examples so you can get a feel for how it works. >> Don't hesitate to ask if you have any questions. >> >> -Matt >> >> >> [1] >> https://mvnrepository.com/artifact/org.apache.commons/commons-geometry-euclidean >> [2] https://gitbox.apache.org/repos/asf?p=commons-geometry.git >> [3] https://github.com/apache/commons-geometry >> [4] https://commons.apache.org/proper/commons-geometry/userguide/index.html >> >> >> ________________________________ >> From: Patrik Karlström <[email protected]> >> Sent: Saturday, March 20, 2021 4:30 AM >> To: Commons Users List <[email protected]> >> Subject: Re: [math] 2D Line getOffset and natural orientation >> >> Thanks for the clarification, I would be happy to try out beta1 of >> commons-geometry, is there a staging repo for it? >> >> /Patrik >> >> Den fre 19 mars 2021 kl 00:29 skrev Matt Juntunen <[email protected] >>> : >> >>> Hello. >>> >>> I agree that the docs are not really clear on the "natural orientation" >>> part there. Basically, the possible results are as follows: >>> >>> * positive - The argument lies on the right side of the calling line, >>> with the "right side" defined as the side on the right when looking along >>> the calling line in its defined direction. (This is what I believe is meant >>> by "natural orientation".) >>> * negative - The argument lies on the left side of the calling line. >>> * zero - The lines have points in common, meaning they intersect or >>> are coincident. >>> >>> On a side note, if you're writing geometric code, I would suggest trying >>> out the new(-ish) commons-geometry library [1]. It is a rewrite and >>> extension of the commons-math geometry code and, IMHO, the API is more >>> user-friendly. (Disclaimer: I wrote the majority of it so I am completely >>> biased 🙂 >>> >>> Regards, >>> Matt J >>> >>> [1] https://commons.apache.org/proper/commons-geometry/ >>> [https://avatars.githubusercontent.com/u/47359?s=400&v=4]< >>> https://github.com/apache/commons-geometry/blob/master/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Line.java#L370 >>>> >>> apache/commons-geometry< >>> https://github.com/apache/commons-geometry/blob/master/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/Line.java#L370 >>>> >>> Apache Commons Geometry. Contribute to apache/commons-geometry development >>> by creating an account on GitHub. >>> github.com >>> >>> >>> ________________________________ >>> From: Patrik Karlström <[email protected]> >>> Sent: Thursday, March 18, 2021 3:42 AM >>> To: [email protected] <[email protected]> >>> Subject: Re: [math] 2D Line getOffset and natural orientation >>> >>> Oh, scratch that! >>> >>> I had three parallel lines and picked the wrong pair (and the correct >>> values came from another calculation). >>> >>> Still interested in "natural orientation" though. >>> >>> Den tors 18 mars 2021 kl 07:19 skrev Patrik Karlström <[email protected]>: >>>> >>>> Sometimes (50/50?) I'm getting an unexpected signum from >>>> org.apache.commons.math3.geometry.euclidean.twod.Line.getOffset(Line >>>> line). >>>> The absolute value itself is correct. >>>> >>>> From the javadoc: >>>> "The offset is 0 if both lines are the same, it is positive if the >>>> line is on the right side of the instance and negative if it is on the >>>> left side, according to its natural orientation." >>>> >>>> I suspect my problem relates to "according to its natural orientation." >>>> What is a natural orientation and what can I do to adapt to it, when >>>> to reverse my lines? If that's the case. >>>> >>>> >>> https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/org/apache/commons/math3/geometry/euclidean/twod/Line.html#getOffset(org.apache.commons.math3.geometry.euclidean.twod.Line) >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [email protected] >>> For additional commands, e-mail: [email protected] >>> >>> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
