Changeset 44f41997


Ignore:
Timestamp:
Nov 11, 2019, 2:41:41 PM (5 years ago)
Author:
Dmitry Kobets <dkobets@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b545cad
Parents:
9a83ccd
git-author:
Dmitry Kobets <dkobets@…> (10/04/19 14:57:33)
git-committer:
Dmitry Kobets <dkobets@…> (11/11/19 14:41:41)
Message:

Add vector normalization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/vector.hfa

    r9a83ccd r44f41997  
    2929    return [u.x - v.x, u.y - v.y];
    3030}
     31vec2 ?*?(const vec2& v, float scalar) with (v) {
     32    return [x * scalar, y * scalar];
     33}
     34vec2 ?/?(const vec2& v, float scalar) with (v) {
     35    return [x / scalar, y / scalar];
     36}
    3137
    3238/* //---------------------- Geometric Functions ---------------------- */
     
    4046   return sqrt(dot(v, v));
    4147}
     48
     49// Returns the distance betwwen v1 and v2, i.e., length(p0 - p1).
     50static inline float distance(const vec2& v1, const vec2& v2) {
     51    return length(v1 - v2);
     52}
     53
     54static inline vec2 normalize(const vec2& v) {
     55    // TODO(dkobets) -- show them inversesqrt
     56    // https://github.com/g-truc/glm/blob/269ae641283426f7f84116f2fe333472b9c914c9/glm/detail/func_exponential.inl
     57    /* return v * inversesqrt(dot(v, v)); */
     58    return v / sqrt(dot(v, v));
     59}
Note: See TracChangeset for help on using the changeset viewer.