From 0f5de2674207516b228f20b7ef8649315dce7a21 Mon Sep 17 00:00:00 2001 From: Fyustorm Date: Mon, 30 Mar 2026 18:40:34 +0200 Subject: [PATCH 1/2] fix: round float values to ceiling step --- .../buttplug4j/client/ButtplugClientDeviceFeature.java | 9 ++++++++- .../client/ButtplugClientDeviceFeatureTest.java | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java index 8d7ce10..9b99cd3 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java @@ -118,7 +118,14 @@ private int getStepFromFloat(final ButtplugOutput type, final float value) throw if (desc instanceof DeviceFeature.SteppedOutputDescriptor) { double steps = ((DeviceFeature.SteppedOutputDescriptor) desc).getValue()[1]; steps *= value; - return (int) Math.floor(steps); + + int result; + if (steps >= 0) { + result = (int) Math.ceil(steps); + } else { + result = (int) Math.floor(steps); + } + return result; } else { throw new ButtplugDeviceFeatureException(type); } diff --git a/buttplug4j/src/test/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeatureTest.java b/buttplug4j/src/test/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeatureTest.java index e835b7b..a84586e 100644 --- a/buttplug4j/src/test/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeatureTest.java +++ b/buttplug4j/src/test/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeatureTest.java @@ -276,7 +276,7 @@ void testSprayFloatWithValidValue() throws Exception { ArgumentCaptor captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class); verify(mockDevice).runOutput(eq(0), captor.capture()); assertInstanceOf(OutputCmd.Spray.class, captor.getValue()); - assertEquals(3, ((OutputCmd.Spray) captor.getValue()).getValue()); + assertEquals(4, ((OutputCmd.Spray) captor.getValue()).getValue()); } @Test @@ -304,7 +304,7 @@ void testPositionFloatWithValidValue() throws Exception { ArgumentCaptor captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class); verify(mockDevice).runOutput(eq(0), captor.capture()); assertInstanceOf(OutputCmd.Position.class, captor.getValue()); - assertEquals(20, ((OutputCmd.Position) captor.getValue()).getValue()); + assertEquals(21, ((OutputCmd.Position) captor.getValue()).getValue()); } @Test @@ -341,7 +341,7 @@ void testPositionWithDurationFloatWithValidValue() throws Exception { ArgumentCaptor captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class); verify(mockDevice).runOutput(eq(0), captor.capture()); assertInstanceOf(OutputCmd.HwPositionWithDuration.class, captor.getValue()); - assertEquals(20, ((OutputCmd.HwPositionWithDuration) captor.getValue()).getValue()); + assertEquals(21, ((OutputCmd.HwPositionWithDuration) captor.getValue()).getValue()); assertEquals(500, ((OutputCmd.HwPositionWithDuration) captor.getValue()).getDuration()); } @@ -370,7 +370,7 @@ void testLedFloatWithValidValue() throws Exception { ArgumentCaptor captor = ArgumentCaptor.forClass(OutputCmd.IOutputCommand.class); verify(mockDevice).runOutput(eq(0), captor.capture()); assertInstanceOf(OutputCmd.Led.class, captor.getValue()); - assertEquals(127, ((OutputCmd.Led) captor.getValue()).getValue()); + assertEquals(128, ((OutputCmd.Led) captor.getValue()).getValue()); } @Test From b5bb85c23478f9f268721dd00afb88f8f3870eae Mon Sep 17 00:00:00 2001 From: Fyustorm Date: Mon, 30 Mar 2026 18:55:07 +0200 Subject: [PATCH 2/2] fix: checkstyle --- .../buttplug4j/client/ButtplugClientDeviceFeature.java | 1 - 1 file changed, 1 deletion(-) diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java index 9b99cd3..a8a9d63 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDeviceFeature.java @@ -118,7 +118,6 @@ private int getStepFromFloat(final ButtplugOutput type, final float value) throw if (desc instanceof DeviceFeature.SteppedOutputDescriptor) { double steps = ((DeviceFeature.SteppedOutputDescriptor) desc).getValue()[1]; steps *= value; - int result; if (steps >= 0) { result = (int) Math.ceil(steps);