Repository: markus-wa/demoinfocs-golang
Pull request #295 (2021-06-04 19:36:50)

common: add Player.PositionEyes() func + fix Player.Position() docs
see #236 

codecov[bot]: # [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/295?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) Report
> Merging [#295](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/295?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (323e8a3) into [master](https://codecov.io/gh/markus-wa/demoinfocs-golang/commit/79c99eab84098d3275de7221be80209aaa3c6648?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (79c99ea) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head 323e8a3 differs from pull request most recent head e180d64. Consider uploading reports for the commit e180d64 to get more accurate results
[![Impacted file tree graph](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/295/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/295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)

```diff
@@            Coverage Diff             @@
##           master     #295      +/-   ##
==========================================
+ Coverage   92.12%   92.14%   +0.01%     
==========================================
  Files          29       29              
  Lines        2490     2495       +5     
==========================================
+ Hits         2294     2299       +5     
  Misses        144      144              
  Partials       52       52              
```


| [Impacted Files](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) | Coverage Δ | |
|---|---|---|
| [pkg/demoinfocs/common/player.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/295/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus#diff-cGtnL2RlbW9pbmZvY3MvY29tbW9uL3BsYXllci5nbw==) | `98.01% <100.00%> (+0.10%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/295?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/295?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Last update [79c99ea...e180d64](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/295?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/player.go b/pkg/demoinfocs/common/player.go
index 70ebc66..68e28ac 100644
--- a/pkg/demoinfocs/common/player.go
+++ b/pkg/demoinfocs/common/player.go
@@ -285,7 +285,8 @@ func (p *Player) ViewDirectionY() float32 {
 }
 
 // Position returns the in-game coordinates.
-// Like the ones you get from cl_showpos 1.
+// Note: the Z value is not on the player's eye height but instead at his feet.
+// See also PositionEyes().
 func (p *Player) Position() r3.Vector {
 	if p.Entity == nil {
 		return r3.Vector{}
@@ -294,6 +295,20 @@ func (p *Player) Position() r3.Vector {
 	return p.Entity.Position()
 }
 
+// PositionEyes returns the player's position with the Z value at eye height.
+// This is what you get from cl_showpos 1.
+// See lso Position().
+func (p *Player) PositionEyes() r3.Vector {
+	if p.Entity == nil {
+		return r3.Vector{}
+	}
+
+	pos := p.Position()
+	pos.Z += float64(p.Entity.PropertyValueMust("localdata.m_vecViewOffset[2]").FloatVal)
+
+	return pos
+}
+
 // Velocity returns the player's velocity.
 func (p *Player) Velocity() r3.Vector {
 	if p.Entity == nil {


Test patch:
diff --git a/pkg/demoinfocs/common/player_test.go b/pkg/demoinfocs/common/player_test.go
index f758789..57c55e8 100644
--- a/pkg/demoinfocs/common/player_test.go
+++ b/pkg/demoinfocs/common/player_test.go
@@ -353,6 +353,23 @@ func TestPlayer_Position_EntityNil(t *testing.T) {
 	assert.Empty(t, pl.Position())
 }
 
+func TestPlayer_PositionEyes(t *testing.T) {
+	entity := entityWithProperty("localdata.m_vecViewOffset[2]", st.PropertyValue{FloatVal: 2})
+	pos := r3.Vector{X: 1, Y: 2, Z: 3}
+
+	entity.On("Position").Return(pos)
+
+	pl := &Player{Entity: entity}
+
+	assert.Equal(t, r3.Vector{X: 1, Y: 2, Z: 5}, pl.PositionEyes())
+}
+
+func TestPlayer_PositionEyes_EntityNil(t *testing.T) {
+	pl := new(Player)
+
+	assert.Empty(t, pl.PositionEyes())
+}
+
 func TestPlayer_Velocity(t *testing.T) {
 	entity := new(stfake.Entity)
 	entity.On("PropertyValueMust", "localdata.m_vecVelocity[0]").Return(st.PropertyValue{FloatVal: 1})