You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gilles Sadowski (Jira)" <ji...@apache.org> on 2019/09/25 23:48:00 UTC
[jira] [Comment Edited] (GEOMETRY-46) Additional UnitVector methods
[ https://issues.apache.org/jira/browse/GEOMETRY-46?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16938138#comment-16938138 ]
Gilles Sadowski edited comment on GEOMETRY-46 at 9/25/19 11:47 PM:
-------------------------------------------------------------------
{quote}breaks ValJO specification
{quote}
How?
{quote}off [...] if Vector2D and Vector3D did things one way and Vector1D did it another.
{quote}
Of course, the same changes would be applied to those other classes as well.
{quote}What benefits does this design bring?
{quote}
# Robustness: Factory method "from" ensures normalization happens in the class that claims to produce normalized vectors (removes the need for a comment such as "Callers are responsible for ensuring that the given values represent a normalized vector"). Also, preconditions are checked within that same class.
# Explicit representation of a useful concept (cf. basis vectors). Could make some codes slightly leaner (one never needs to call "normalize" on a {{Unit}} instance). For example, method "directionTo(v)" should be declared to return a "Unit" vector. Ditto for method "normalize", of course. ;)
# Static method "normalize(double x)" (and equivalent in 2D and 3D) can be removed; and this is good IMO for several reasons:
** Mix between vector transformation and factory method (double -> vector).
** Unnecessary addition to the API.
** Asymmetric usage ("of" vs "normalize") in higher level API ("AffineTransformMatrix1D").
was (Author: erans):
{quote}breaks ValJO specification
{quote}
How?
{quote}off [...] if Vector2D and Vector3D did things one way and Vector1D did it another.
{quote}
Of course, the same changes would be applied to those other classes as well.
{quote}What benefits does this design bring?
{quote} # Robustness: Factory method "from" ensures normalization happens in the class that claims to produce normalized vectors (removes the need for a comment such as "Callers are responsible for ensuring that the given values represent a normalized vector"). Also, preconditions are checked within that same class.
# Explicit representation of a useful concept (cf. basis vectors). Could make some codes slightly leaner (one never needs to call "normalize" on a {{Unit}} instance). For example, method "directionTo(v)" should be declared to return a "Unit" vector. Ditto for method "normalize", of course. ;)
# Static method "normalize(double x)" (and equivalent in 2D and 3D) can be removed; and this is good IMO for several reasons:
** Mix between vector transformation and factory method (double -> vector).
** Unnecessary addition to the API.
** Asymmetric usage ("of" vs "normalize") in higher level API ("AffineTransformMatrix1D").
> Additional UnitVector methods
> -----------------------------
>
> Key: GEOMETRY-46
> URL: https://issues.apache.org/jira/browse/GEOMETRY-46
> Project: Apache Commons Geometry
> Issue Type: Improvement
> Reporter: Matt Juntunen
> Priority: Minor
> Labels: easyfix, pull-request-available, starter
> Attachments: GEOMETRY-46.patch
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The following methods should be overridden in theĀ {{UnitVector}} private subclasses of the {{Vector?D}} classes:
> * {{normSq}} -- should return {{1}} for consistency with {{norm}}
> * {{negate}} -- should be overridden to also return a {{UnitVector}} instance instead of a regular {{Vector?D}}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)