mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-20 06:05:23 +00:00
Fixed issues from last merge (#346)
This commit is contained in:
parent
a8c6bbec9d
commit
0a206ce024
|
@ -108,19 +108,14 @@ func AdjustWithRemainder(sourceValue, adjustment, targetvalue float64) (newValue
|
||||||
finalValue := sourceValue + adjustment
|
finalValue := sourceValue + adjustment
|
||||||
if !adjustNegative {
|
if !adjustNegative {
|
||||||
if finalValue > targetvalue {
|
if finalValue > targetvalue {
|
||||||
diff := finalValue - targetvalue // RoundToDecial(finalValue-targetvalue, 6)
|
diff := finalValue - targetvalue
|
||||||
return targetvalue, diff
|
return targetvalue, diff
|
||||||
}
|
}
|
||||||
return finalValue, 0
|
return finalValue, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if finalValue < targetvalue {
|
if finalValue < targetvalue {
|
||||||
return targetvalue, RoundToDecial(finalValue-targetvalue, 6)
|
return targetvalue, finalValue - targetvalue
|
||||||
}
|
}
|
||||||
return finalValue, 0
|
return finalValue, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func RoundToDecial(f float64, d int) float64 {
|
|
||||||
digits := float64(math.Pow10(d))
|
|
||||||
return math.Trunc(f*digits) / digits
|
|
||||||
}
|
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -75,9 +75,7 @@ func (m *mapEntity) Step(tickTime float64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
stepX, stepY := m.getStepLength(tickTime)
|
stepX, stepY := m.getStepLength(tickTime)
|
||||||
looped := false
|
|
||||||
for {
|
for {
|
||||||
looped = looped
|
|
||||||
if d2common.AlmostEqual(m.LocationX-m.TargetX, 0, 0.0001) {
|
if d2common.AlmostEqual(m.LocationX-m.TargetX, 0, 0.0001) {
|
||||||
stepX = 0
|
stepX = 0
|
||||||
}
|
}
|
||||||
|
@ -114,7 +112,6 @@ func (m *mapEntity) Step(tickTime float64) {
|
||||||
if stepX == 0 && stepY == 0 {
|
if stepX == 0 && stepY == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
looped = true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user