Re: [math] AffineTransformMatrix2D

2021-03-22 Thread Matt Juntunen
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 
Sent: Monday, March 22, 2021 3:24 AM
To: user@commons.apache.org 
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 
> Sent: Sunday, March 21, 2021 8:40 AM
> To: user@commons.apache.org 
> 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 th

Re: [math] AffineTransformMatrix2D

2021-03-22 Thread Christoph Läubrich

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 
Sent: Sunday, March 21, 2021 8:40 AM
To: user@commons.apache.org 
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 
Sent: Saturday, March 20, 2021 4:30 AM
To: Commons Users List 
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 
:



Hello.

I agree that the docs are not really clear on the "natural