Skip to content

Commit 277ea1f

Browse files
Fyustormblackspherefollower
authored andcommitted
fix: round float values to ceiling step
1 parent baaf180 commit 277ea1f

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ private int getStepFromFloat(final ButtplugOutput type, final float value) throw
118118
if (desc instanceof DeviceFeature.SteppedOutputDescriptor) {
119119
double steps = ((DeviceFeature.SteppedOutputDescriptor) desc).getValue()[1];
120120
steps *= value;
121-
return (int) Math.floor(steps);
121+
122+
int result;
123+
if (steps >= 0) {
124+
result = (int) Math.ceil(steps);
125+
} else {
126+
result = (int) Math.floor(steps);
127+
}
128+
return result;
122129
} else {
123130
throw new ButtplugDeviceFeatureException(type);
124131
}

buttplug4j/src/test/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeatureTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void testSprayFloatWithValidValue() throws Exception {
276276
ArgumentCaptor<OutputCmd.IOutputCommand> captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class);
277277
verify(mockDevice).runOutput(eq(0), captor.capture());
278278
assertInstanceOf(OutputCmd.Spray.class, captor.getValue());
279-
assertEquals(3, ((OutputCmd.Spray) captor.getValue()).getValue());
279+
assertEquals(4, ((OutputCmd.Spray) captor.getValue()).getValue());
280280
}
281281

282282
@Test
@@ -304,7 +304,7 @@ void testPositionFloatWithValidValue() throws Exception {
304304
ArgumentCaptor<OutputCmd.IOutputCommand> captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class);
305305
verify(mockDevice).runOutput(eq(0), captor.capture());
306306
assertInstanceOf(OutputCmd.Position.class, captor.getValue());
307-
assertEquals(20, ((OutputCmd.Position) captor.getValue()).getValue());
307+
assertEquals(21, ((OutputCmd.Position) captor.getValue()).getValue());
308308
}
309309

310310
@Test
@@ -341,7 +341,7 @@ void testPositionWithDurationFloatWithValidValue() throws Exception {
341341
ArgumentCaptor<OutputCmd.IOutputCommand> captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class);
342342
verify(mockDevice).runOutput(eq(0), captor.capture());
343343
assertInstanceOf(OutputCmd.HwPositionWithDuration.class, captor.getValue());
344-
assertEquals(20, ((OutputCmd.HwPositionWithDuration) captor.getValue()).getValue());
344+
assertEquals(21, ((OutputCmd.HwPositionWithDuration) captor.getValue()).getValue());
345345
assertEquals(500, ((OutputCmd.HwPositionWithDuration) captor.getValue()).getDuration());
346346
}
347347

@@ -370,7 +370,7 @@ void testLedFloatWithValidValue() throws Exception {
370370
ArgumentCaptor<OutputCmd.IOutputCommand> captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class);
371371
verify(mockDevice).runOutput(eq(0), captor.capture());
372372
assertInstanceOf(OutputCmd.Led.class, captor.getValue());
373-
assertEquals(127, ((OutputCmd.Led) captor.getValue()).getValue());
373+
assertEquals(128, ((OutputCmd.Led) captor.getValue()).getValue());
374374
}
375375

376376
@Test

0 commit comments

Comments
 (0)