From 9f72478dc8f257c03e0669b1caa85a6c94ff880b Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sat, 20 Aug 2022 12:09:33 -0500 Subject: [PATCH] start convert file by file --- .../detector/{MathUtils.java => MathUtils.rs} | 38 ++++++++----------- ...or.java => MonochromeRectangleDetector.rs} | 7 ++-- 2 files changed, 19 insertions(+), 26 deletions(-) rename src/common/detector/{MathUtils.java => MathUtils.rs} (71%) rename src/common/detector/{MonochromeRectangleDetector.java => MonochromeRectangleDetector.rs} (98%) diff --git a/src/common/detector/MathUtils.java b/src/common/detector/MathUtils.rs similarity index 71% rename from src/common/detector/MathUtils.java rename to src/common/detector/MathUtils.rs index bd5931b..8118837 100644 --- a/src/common/detector/MathUtils.java +++ b/src/common/detector/MathUtils.rs @@ -14,17 +14,13 @@ * limitations under the License. */ -package com.google.zxing.common.detector; +//package com.google.zxing.common.detector; /** * General math-related and numeric utility functions. */ -public final class MathUtils { - private MathUtils() { - } - - /** + /** * Ends up being a bit faster than {@link Math#round(float)}. This merely rounds its * argument to the nearest int, where x.5 rounds up to x+1. Semantics of this shortcut * differ slightly from {@link Math#round(float)} in that half rounds down for negative @@ -33,8 +29,8 @@ public final class MathUtils { * @param d real value to round * @return nearest {@code int} */ - public static int round(float d) { - return (int) (d + (d < 0.0f ? -0.5f : 0.5f)); + pub fn round(d:f32) -> i32 { + return (d + (if d < 0.0f { -0.5f } else { 0.5f})); } /** @@ -44,10 +40,10 @@ public final class MathUtils { * @param bY point B y coordinate * @return Euclidean distance between points A and B */ - public static float distance(float aX, float aY, float bX, float bY) { - double xDiff = aX - bX; - double yDiff = aY - bY; - return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff); + pub fn distance( aX:f32, aY:f32, bX: f32, bY:f32) -> f32 { + let xDiff:f64 = aX - bX; + let yDiff:f64 = aY - bY; + return Math.sqrt(xDiff * xDiff + yDiff * yDiff); } /** @@ -57,22 +53,20 @@ public final class MathUtils { * @param bY point B y coordinate * @return Euclidean distance between points A and B */ - public static float distance(int aX, int aY, int bX, int bY) { - double xDiff = aX - bX; - double yDiff = aY - bY; - return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff); + pub fn distance( aX : i32, aY: i32, bX: i32, bY: i32) -> f32 { + let xDiff : f64 = aX - bX; + let yDiff :f64 = aY - bY; + return Math.sqrt(xDiff * xDiff + yDiff * yDiff); } /** * @param array values to sum * @return sum of values in array */ - public static int sum(int[] array) { - int count = 0; - for (int a : array) { + pub fn sum( array : &[i32]) -> i32 { + let count = 0; + for a in array { count += a; } return count; - } - -} + } \ No newline at end of file diff --git a/src/common/detector/MonochromeRectangleDetector.java b/src/common/detector/MonochromeRectangleDetector.rs similarity index 98% rename from src/common/detector/MonochromeRectangleDetector.java rename to src/common/detector/MonochromeRectangleDetector.rs index e87fa55..e3503ee 100644 --- a/src/common/detector/MonochromeRectangleDetector.java +++ b/src/common/detector/MonochromeRectangleDetector.rs @@ -14,11 +14,10 @@ * limitations under the License. */ -package com.google.zxing.common.detector; +//package com.google.zxing.common.detector; +use crate::{NotFoundException,ResultPoint}; +use crate::common::BitMatrix; -import com.google.zxing.NotFoundException; -import com.google.zxing.ResultPoint; -import com.google.zxing.common.BitMatrix; /** *

A somewhat generic detector that looks for a barcode-like rectangular region within an image.