You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "orionlibs (via GitHub)" <gi...@apache.org> on 2023/07/15 17:10:50 UTC

[GitHub] [commons-geometry] orionlibs opened a new pull request, #217: GEOMETRY-150: implemented check for codirectional vectors

orionlibs opened a new pull request, #217:
URL: https://github.com/apache/commons-geometry/pull/217

   [GEOMETRY-150](https://issues.apache.org/jira/projects/GEOMETRY/issues/GEOMETRY-150) implemented a function that determines of a vector has the same direction as another.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-geometry] darkma773r commented on a diff in pull request #217: GEOMETRY-150: implemented check for codirectional vectors

Posted by "darkma773r (via GitHub)" <gi...@apache.org>.
darkma773r commented on code in PR #217:
URL: https://github.com/apache/commons-geometry/pull/217#discussion_r1273636413


##########
commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java:
##########
@@ -142,4 +144,24 @@ public interface Vector<V extends Vector<V>> extends Spatial {
      * @throws IllegalArgumentException if either vector has a zero, NaN, or infinite norm
      */
     double angle(V v);
+
+
+    /**
+     * Determines if this vector has teh same direction as the other vector.
+     * It normalizes both vectors and if the dot product of them is 1,
+     * then it returns {@code true}, otherwise {@code false}.
+     * @param other other vector
+     * @param precision precision object used for floating point comparisons
+     * @return {@code true} if this vector has the same direction as the otehr vector.
+     */
+    default boolean isCodirectionalWith(final V other, final Precision.DoubleEquivalence precision) {
+        final V thisNormalized = normalizeOrNull();
+        final V otherNormalized = other.normalizeOrNull();
+
+        if (thisNormalized != null && otherNormalized != null) {

Review Comment:
   We need unit tests for the following:
   - cases where one or both vectors cannot be normalized (i.e., they are zero, NaN, or infinite)
   - cases where the vectors are very close but not exactly pointing in the same direction (the given precision determines the result in these cases)
   
   Add these tests to `commons-geometry-core` (see `SizedTest` for a possible example of how to do this) and the corresponding `VectorXDTest` classses.



##########
commons-geometry-core/src/main/java/org/apache/commons/geometry/core/Vector.java:
##########
@@ -142,4 +144,24 @@ public interface Vector<V extends Vector<V>> extends Spatial {
      * @throws IllegalArgumentException if either vector has a zero, NaN, or infinite norm
      */
     double angle(V v);
+
+
+    /**
+     * Determines if this vector has teh same direction as the other vector.
+     * It normalizes both vectors and if the dot product of them is 1,
+     * then it returns {@code true}, otherwise {@code false}.
+     * @param other other vector
+     * @param precision precision object used for floating point comparisons
+     * @return {@code true} if this vector has the same direction as the otehr vector.

Review Comment:
   - typo `teh` -> `the`
   - Document the expected result when one or both of the vectors cannot be normalized



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-geometry] orionlibs closed pull request #217: GEOMETRY-150: implemented check for codirectional vectors

Posted by "orionlibs (via GitHub)" <gi...@apache.org>.
orionlibs closed pull request #217: GEOMETRY-150: implemented check for codirectional vectors
URL: https://github.com/apache/commons-geometry/pull/217


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org