1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-12 23:43:24 -05:00

Fixed issues from last merge (#346)

This commit is contained in:
Tim Sarbin 2020-06-20 01:06:42 -04:00 committed by GitHub
parent a8c6bbec9d
commit 0a206ce024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 35 deletions

View File

@ -108,19 +108,14 @@ func AdjustWithRemainder(sourceValue, adjustment, targetvalue float64) (newValue
finalValue := sourceValue + adjustment
if !adjustNegative {
if finalValue > targetvalue {
diff := finalValue - targetvalue // RoundToDecial(finalValue-targetvalue, 6)
diff := finalValue - targetvalue
return targetvalue, diff
}
return finalValue, 0
}
if finalValue < targetvalue {
return targetvalue, RoundToDecial(finalValue-targetvalue, 6)
return targetvalue, finalValue - targetvalue
}
return finalValue, 0
}
func RoundToDecial(f float64, d int) float64 {
digits := float64(math.Pow10(d))
return math.Trunc(f*digits) / digits
}

View File

@ -1,25 +0,0 @@
package d2common
import (
"testing"
)
type TestRecord struct {
source, adjust, max, expectedResult, expectedRemain float64
}
func TestSomething(t *testing.T) {
var testValues = []TestRecord{
{100, 10, 100.2, 100.2, 9.8},
}
for _, test := range testValues {
res, remain := AdjustWithRemainder(test.source, test.adjust, test.max)
if res != test.expectedResult {
t.Errorf("Expected result of %f but got %f", test.expectedResult, res)
}
if remain != test.expectedRemain {
t.Errorf("Expected result of %f but got %f", test.expectedRemain, remain)
}
}
}

View File

@ -75,9 +75,7 @@ func (m *mapEntity) Step(tickTime float64) {
}
stepX, stepY := m.getStepLength(tickTime)
looped := false
for {
looped = looped
if d2common.AlmostEqual(m.LocationX-m.TargetX, 0, 0.0001) {
stepX = 0
}
@ -114,7 +112,6 @@ func (m *mapEntity) Step(tickTime float64) {
if stepX == 0 && stepY == 0 {
break
}
looped = true
}
}