Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reversing an array should preserve cyclic flag #16

Closed
charlesstaats opened this issue Feb 15, 2016 · 2 comments
Closed

reversing an array should preserve cyclic flag #16

charlesstaats opened this issue Feb 15, 2016 · 2 comments

Comments

@charlesstaats
Copy link
Contributor

Current situation:

> int[] a = {1,2};
> a.cyclic = true;
> a   
0:  1
1:  2
> a.cyclic
true 
> reverse(a).cyclic
false 

It seems more consistent that if a is cyclic, then reverse(a) ought to be cyclic as well.

@charlesstaats
Copy link
Contributor Author

Additional note: It appears that the reverse function for arrays is an undocumented convenience implemented for certain types in plain.asy, not a general function like sequence or map as I had assumed. So this is not a high priority.

@charlesstaats
Copy link
Contributor Author

I'd even go further and observe that if you want to make reverse work the same way as it works for paths, you'd have to change the order of the elements. If you take a cyclic path with vertices a,b,c,d,e in that order and reverse it, you get a cyclic path starting in the same place with vertices a,e,d,c,b; whereas reversing an array would give you e,d,c,b,a. Changing the behavior this drastically for cyclic arrays could break things for very limited gain (given the limited nature of the reverse functions), so I'm going to close this as not feasible.

That having been said, if you want to write your own reverse function for a arrays of a given type and have it imitate the behavior of reversing a path, it could be written like this:

T[] reverse(T[] array) {
  if (array.cyclic) {
    T[] toreturn = array[-sequence(array.length)];
    toreturn.cyclic = true;
    return toreturn;
  } else {
    return array[reverse(array.length)];
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant