commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles (JIRA)" <>
Subject [jira] [Commented] (GEOMETRY-17) Euclidean Vector Method Follow-Up
Date Tue, 18 Sep 2018 13:08:01 GMT


Gilles commented on GEOMETRY-17:

bq. getRealNonZeroNorm()

Sorry to be a bit late, but I don't think it is a good idea to have this one in a public interface.
Rationale is that it is a strange combination of implementation detail (infinities caused
by limited range), check on user input (non-zero norm as precondition), and stopping NaN propagation,
with the side effect of throwing an exception.

How about this interface method instead:
/** @return true if the norm is finite, not zero (or equivalent within the expected accuracy
context) and not NaN, false otherwise. */
boolean isFinite();

A separate (syntactic sugar) method for raising an exception:
class Vectors {
    public static double checkedNorm(Vector<?> vector) {
        if (vector.isFinite()) {
            return vector.getNorm();
        throw new IllegalNormException();
to be used in places where validation is enforced. This would replace the current {{ensureFiniteNonZeroNorm}}
which is longish (and not clearer as to what is does to "ensure").

In some other places, validation could perhaps be bypassed (even if an error could be detected)
because, in case of valid usage, it would be redundant.  I think that the {{angle}} method
may be such a place where infinities or NaN could be propagated (as they probably result from
failing to validate earlier).

> Euclidean Vector Method Follow-Up
> ---------------------------------
>                 Key: GEOMETRY-17
>                 URL:
>             Project: Apache Commons Geometry
>          Issue Type: Improvement
>            Reporter: Matt Juntunen
>            Priority: Major
> This is a follow-up issue to GEOMETRY-9. The following tasks should be completed:
>  # Vector2D - needs an orthogonal() method like Vector3D
>  # Vector#getMagnitude() should be removed. I originally added this as part of GEOMETRY-9
as an alias for getNorm(), but after thinking about it more and working with it, I believe
it's more confusing than useful to have multiple names in the code base for the same idea.
>  # Vector#withMagnitude() should be renamed to Vector#withNorm() for the same reason
as above.
>  # Vector#getRealNonZeroNorm() - This is currently a private method in the Vector implementation
classes but I believe it is useful enough to be made public. The idea is that this would return
the vector norm but throw an IllegalNormException if the norm is zero, NaN, or infinite. I've
already come across some places in other classes (such as Rotation) where I want to use this.
> Pull request:

This message was sent by Atlassian JIRA

View raw message