Repository: markus-wa/demoinfocs-golang
Pull request #286 (2021-05-14 11:45:33)

common: add GrenadeProjectile.Velocity() function
see #281 

codecov[bot]: # [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) Report
> Merging [#286](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (3e90f5a) into [master](https://codecov.io/gh/markus-wa/demoinfocs-golang/commit/9190856f2d2fd310465eebb4dd925ef0eda2ca74?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (9190856) will **decrease** coverage by `0.07%`.
> The diff coverage is `33.33%`.

[![Impacted file tree graph](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286/graphs/tree.svg?width=650&height=150&src=pr&token=20emCaZRHz&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)

```diff
@@            Coverage Diff             @@
##           master     #286      +/-   ##
==========================================
- Coverage   92.06%   91.99%   -0.08%     
==========================================
  Files          29       29              
  Lines        2470     2473       +3     
==========================================
+ Hits         2274     2275       +1     
- Misses        144      145       +1     
- Partials       52       53       +1     
```


| [Impacted Files](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) | Coverage Δ | |
|---|---|---|
| [pkg/demoinfocs/common/common.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus#diff-cGtnL2RlbW9pbmZvY3MvY29tbW9uL2NvbW1vbi5nbw==) | `87.23% <33.33%> (-3.68%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Last update [9190856...3e90f5a](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/286?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).


Patch:
diff --git a/pkg/demoinfocs/common/common.go b/pkg/demoinfocs/common/common.go
index ca3b970..9ef0e47 100644
--- a/pkg/demoinfocs/common/common.go
+++ b/pkg/demoinfocs/common/common.go
@@ -79,6 +79,11 @@ func (g *GrenadeProjectile) Position() r3.Vector {
 	return g.Entity.Position()
 }
 
+// Velocity returns the projectile's velocity.
+func (g *GrenadeProjectile) Velocity() r3.Vector {
+	return g.Entity.PropertyValueMust("m_vecVelocity").VectorVal
+}
+
 // UniqueID returns the unique id of the grenade.
 // The unique id is a random int generated internally by this library and can be used to differentiate
 // grenades from each other. This is needed because demo-files reuse entity ids.


Test patch:
diff --git a/pkg/demoinfocs/common/common_test.go b/pkg/demoinfocs/common/common_test.go
index e3e900b..e4ac78a 100644
--- a/pkg/demoinfocs/common/common_test.go
+++ b/pkg/demoinfocs/common/common_test.go
@@ -32,6 +32,20 @@ func TestGrenadeProjectileUniqueID(t *testing.T) {
 	assert.NotEqual(t, NewGrenadeProjectile().UniqueID(), NewGrenadeProjectile().UniqueID(), "UniqueIDs of different grenade projectiles should be different")
 }
 
+func TestGrenadeProjectile_Velocity(t *testing.T) {
+	expected := r3.Vector{
+		X: 1,
+		Y: 2,
+		Z: 3,
+	}
+
+	p := GrenadeProjectile{
+		Entity: entityWithProperty("m_vecVelocity", st.PropertyValue{VectorVal: expected}),
+	}
+
+	assert.Equal(t, expected, p.Velocity())
+}
+
 func TestDemoHeader(t *testing.T) {
 	header := DemoHeader{
 		PlaybackFrames: 256,