[ 
https://issues.apache.org/jira/browse/GEOMETRY-160?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17743374#comment-17743374
 ] 

Gilles Sadowski commented on GEOMETRY-160:
------------------------------------------

General remark: When you want to submit several changes that share some obvious 
common characteristics, it is more efficient for everyone to create *one JIRA 
report* whose description could contain a {*}list of the proposed changes{*}. 
That way, it is easy to make comments that apply to several proposals (thus 
avoiding the repetition in every opened ticket).
Afterwards, a JIRA "sub-task" for a particular change can always be create if 
necessary (e.g. where we'd need to further discuss specifics for that change).
Even before raising a ticket with such a list, it would be useful to post on 
the "dev" ML (again: *one post* for a list of changes that are somehow 
"similar").

Also please refer to the comment by Alex in GEOMETRY-150.

You propose to implement
 * {{getIndicesOfOccurenceOfElement(Vector x, double element)}}

What about
 * {{getIndicesOfOccurenceOfElementSmallerThan(Vector x, double element)}}
 * {{getIndicesOfOccurenceOfElementLargerThan(Vector x, double element)}}
 * {{getIndicesOfOccurenceOfElementSmallerThanTheSquareRootOf(Vector x, double 
element)}}
 * {{getIndicesOfOccurenceOfElementSmallerThanItsNeighbour(Vector x)}}
 * 
{{getIndicesOfOccurenceOfElementSmallerThanOrEqualToThreeTimesTheLastElement(Vector
 x)}}
 * ...

?

Where do we draw the line (to stop adding to the API)?
What's the purpose of such checks when the context is 1D, 2D or 3D geometry?
We cannot simply add a method because it computes something; there must be some 
rationale (either a "reference" that explains the concept, or a use-case).

Taking a different view on this proposal (and others that look similar), isn't 
the common idea to perform some check on a list of numbers?
Then, with an (untested) implementation like:
{code:java}
public List<Integer> index(List<T> list,
                           BiPredicate<T, List<T>> check) {
    final List<Integer> idx = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        if (check.test(e.get(i), list)) {
            idx.add(i);
        }
    }
    return idx;
}
{code}
I could define (untested)
{code:java}
public List<Integer> 
getIndicesOfOccurenceOfElementSmallerThanOrEqualToThreeTimesTheLastElement(List<Double>
 list) {
    return index(list, (e, eL) -> e <= 3 * eL.get(eL.size() - 1));
}
{code}
Would you clutter an API with that method when you could instead "inline" its 
body where sporadic usage would be called for?

> Implement getIndicesOfOccurenceOfElement(Vector x, double element)
> ------------------------------------------------------------------
>
>                 Key: GEOMETRY-160
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-160
>             Project: Commons Geometry
>          Issue Type: New Feature
>          Components: euclidean1D, euclidean2D, euclidean3D
>            Reporter: Dimitrios Efthymiou
>            Priority: Minor
>              Labels: features
>   Original Estimate: 5h
>  Remaining Estimate: 5h
>
> If we have a vector u = (2, 1, 3, 1, 7) and a number, say, 1 then it returns 
> a list of the indices 1 and 3



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to