Last active
September 29, 2016 14:35
-
-
Save CaptainPRICE/927ee89a4a48025c14f64a7af8c0fd71 to your computer and use it in GitHub Desktop.
E2: average function with support for vectors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function vector average(Vector1:vector, Vector2:vector) | |
| { | |
| return (Vector1 + Vector2) * 0.5 | |
| } | |
| function vector average(Vector1:vector, Vector2:vector, Vector3:vector) | |
| { | |
| return (Vector1 + Vector2 + Vector3) / 3 | |
| } | |
| function vector array:averageVector() | |
| { | |
| local Result = vec() | |
| foreach (Index, Vector:vector = This) | |
| { | |
| Result += Vector | |
| } | |
| return Result / This:count() | |
| } | |
| local OpCounter = opcounter() | |
| average(vec(), vec(100)) | |
| print(opcounter() - OpCounter - 123) # 123: 1 = vec(), 2 = vec(100), 20 = function, 100 = print | |
| OpCounter = opcounter() | |
| array(vec(), vec(100)):averageVector() | |
| print(opcounter() - OpCounter - 123) # 123: 1 = vec(), 2 = vec(100), 1* = array(...), 20 = function, 100 = print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment