{"action":"created","issue":{"url":"https://api.github.com/repos/toji/gl-matrix/issues/259","repository_url":"https://api.github.com/repos/toji/gl-matrix","labels_url":"https://api.github.com/repos/toji/gl-matrix/issues/259/labels{/name}","comments_url":"https://api.github.com/repos/toji/gl-matrix/issues/259/comments","events_url":"https://api.github.com/repos/toji/gl-matrix/issues/259/events","html_url":"https://github.com/toji/gl-matrix/issues/259","id":250407584,"number":259,"title":"additional vec2 operations","user":{"login":"mreinstein","id":718067,"avatar_url":"https://avatars1.githubusercontent.com/u/718067?v=4","gravatar_id":"","url":"https://api.github.com/users/mreinstein","html_url":"https://github.com/mreinstein","followers_url":"https://api.github.com/users/mreinstein/followers","following_url":"https://api.github.com/users/mreinstein/following{/other_user}","gists_url":"https://api.github.com/users/mreinstein/gists{/gist_id}","starred_url":"https://api.github.com/users/mreinstein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mreinstein/subscriptions","organizations_url":"https://api.github.com/users/mreinstein/orgs","repos_url":"https://api.github.com/users/mreinstein/repos","events_url":"https://api.github.com/users/mreinstein/events{/privacy}","received_events_url":"https://api.github.com/users/mreinstein/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-08-15T19:06:29Z","updated_at":"2017-10-17T18:29:22Z","closed_at":null,"author_association":"NONE","body":"@toji  would you be open to a PR which adds these vec2 operations? I've found these are useful in several 2d projects:\r\n\r\n```javascript\r\n// returns angle of vec2 expressed in radians\r\nexport function getAngle(a) {\r\n  return Math.atan2(a[1], a[0])\r\n}\r\n\r\n// set a vec2 based on input angle in radians\r\nexport function setAngle(out, angle) {\r\n  const length = vec2.length(out)\r\n  out[0] = Math.cos(angle) * length\r\n  out[1] = Math.sin(angle) * length\r\n  return out\r\n}\r\n\r\nexport function setLength(out, length) {\r\n  const a = getAngle(vec2)\r\n  out[0] = Math.cos(a) * length\r\n  out[1] = Math.sin(a) * length\r\n  return out\r\n}\r\n\r\nexport function truncate(out, maxLength) {\r\n  if (vec2.length(out) > maxLength) {\r\n    setLength(out, maxLength)\r\n  }\r\n  return out\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/toji/gl-matrix/issues/comments/337324890","html_url":"https://github.com/toji/gl-matrix/issues/259#issuecomment-337324890","issue_url":"https://api.github.com/repos/toji/gl-matrix/issues/259","id":337324890,"user":{"login":"mreinstein","id":718067,"avatar_url":"https://avatars1.githubusercontent.com/u/718067?v=4","gravatar_id":"","url":"https://api.github.com/users/mreinstein","html_url":"https://github.com/mreinstein","followers_url":"https://api.github.com/users/mreinstein/followers","following_url":"https://api.github.com/users/mreinstein/following{/other_user}","gists_url":"https://api.github.com/users/mreinstein/gists{/gist_id}","starred_url":"https://api.github.com/users/mreinstein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mreinstein/subscriptions","organizations_url":"https://api.github.com/users/mreinstein/orgs","repos_url":"https://api.github.com/users/mreinstein/repos","events_url":"https://api.github.com/users/mreinstein/events{/privacy}","received_events_url":"https://api.github.com/users/mreinstein/received_events","type":"User","site_admin":false},"created_at":"2017-10-17T18:29:22Z","updated_at":"2017-10-17T18:29:22Z","author_association":"NONE","body":"> I meant setLength and scale\r\n\r\nAh ok. `setLength(out, 5)` is equivalent to:\r\n\r\n```javascript\r\nvec2.normalize(out, out)\r\nvec2.scale(out, out, 5) \r\n```\r\n\r\n> About the getAngle and setAngle..A vector itself doesn't have an angle.\r\n\r\nIt does have an angle if you are treating a vector as a unit vector, which expresses distance and direction from the origin. How about `getRotation` and `setRotation` ?\r\n\r\n"}}
{"actor":{"display_login":"mreinstein"}}