mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 12:52:34 +00:00
Merge branch 'main' into pr/exception_helpers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::fmt;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
use super::{GenericGFPoly, GenericGFRef};
|
||||
@@ -131,7 +132,7 @@ impl GenericGF {
|
||||
/**
|
||||
* @return base 2 log of a in GF(size)
|
||||
*/
|
||||
pub fn log(&self, a: i32) -> Result<i32, Exceptions> {
|
||||
pub fn log(&self, a: i32) -> Result<i32> {
|
||||
if a == 0 {
|
||||
return Err(Exceptions::illegalArgument);
|
||||
}
|
||||
@@ -142,7 +143,7 @@ impl GenericGF {
|
||||
/**
|
||||
* @return multiplicative inverse of a
|
||||
*/
|
||||
pub fn inverse(&self, a: i32) -> Result<i32, Exceptions> {
|
||||
pub fn inverse(&self, a: i32) -> Result<i32> {
|
||||
if a == 0 {
|
||||
return Err(Exceptions::arithmetic);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
use super::{GenericGF, GenericGFRef};
|
||||
@@ -47,7 +48,7 @@ impl GenericGFPoly {
|
||||
* or if leading coefficient is 0 and this is not a
|
||||
* constant polynomial (that is, it is not the monomial "0")
|
||||
*/
|
||||
pub fn new(field: GenericGFRef, coefficients: &[i32]) -> Result<Self, Exceptions> {
|
||||
pub fn new(field: GenericGFRef, coefficients: &[i32]) -> Result<Self> {
|
||||
if coefficients.is_empty() {
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"coefficients cannot be empty",
|
||||
@@ -138,7 +139,7 @@ impl GenericGFPoly {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn addOrSubtract(&self, other: &GenericGFPoly) -> Result<GenericGFPoly, Exceptions> {
|
||||
pub fn addOrSubtract(&self, other: &GenericGFPoly) -> Result<GenericGFPoly> {
|
||||
if self.field != other.field {
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"GenericGFPolys do not have same GenericGF field",
|
||||
@@ -174,7 +175,7 @@ impl GenericGFPoly {
|
||||
GenericGFPoly::new(self.field, &sumDiff)
|
||||
}
|
||||
|
||||
pub fn multiply(&self, other: &GenericGFPoly) -> Result<GenericGFPoly, Exceptions> {
|
||||
pub fn multiply(&self, other: &GenericGFPoly) -> Result<GenericGFPoly> {
|
||||
if self.field != other.field {
|
||||
//if (!field.equals(other.field)) {
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
@@ -229,11 +230,7 @@ impl GenericGFPoly {
|
||||
GenericGFPoly::new(self.field, &[1]).unwrap()
|
||||
}
|
||||
|
||||
pub fn multiply_by_monomial(
|
||||
&self,
|
||||
degree: usize,
|
||||
coefficient: i32,
|
||||
) -> Result<GenericGFPoly, Exceptions> {
|
||||
pub fn multiply_by_monomial(&self, degree: usize, coefficient: i32) -> Result<GenericGFPoly> {
|
||||
if coefficient == 0 {
|
||||
return Ok(self.getZero());
|
||||
}
|
||||
@@ -247,10 +244,7 @@ impl GenericGFPoly {
|
||||
GenericGFPoly::new(self.field, &product)
|
||||
}
|
||||
|
||||
pub fn divide(
|
||||
&self,
|
||||
other: &GenericGFPoly,
|
||||
) -> Result<(GenericGFPoly, GenericGFPoly), Exceptions> {
|
||||
pub fn divide(&self, other: &GenericGFPoly) -> Result<(GenericGFPoly, GenericGFPoly)> {
|
||||
if self.field != other.field {
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
"GenericGFPolys do not have same GenericGF field",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
//package com.google.zxing.common.reedsolomon;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
use super::{GenericGF, GenericGFPoly, GenericGFRef};
|
||||
@@ -60,7 +61,7 @@ impl ReedSolomonDecoder {
|
||||
* @param twoS number of error-correction codewords available
|
||||
* @throws ReedSolomonException if decoding fails for any reason
|
||||
*/
|
||||
pub fn decode(&self, received: &mut Vec<i32>, twoS: i32) -> Result<usize, Exceptions> {
|
||||
pub fn decode(&self, received: &mut Vec<i32>, twoS: i32) -> Result<usize> {
|
||||
let poly = GenericGFPoly::new(self.field, received)?;
|
||||
let mut syndromeCoefficients = vec![0; twoS as usize];
|
||||
let mut noError = true;
|
||||
@@ -109,7 +110,7 @@ impl ReedSolomonDecoder {
|
||||
a: &GenericGFPoly,
|
||||
b: &GenericGFPoly,
|
||||
R: usize,
|
||||
) -> Result<Vec<GenericGFPoly>, Exceptions> {
|
||||
) -> Result<Vec<GenericGFPoly>> {
|
||||
// Assume a's degree is >= b's
|
||||
let mut a = a.clone();
|
||||
let mut b = b.clone();
|
||||
@@ -172,7 +173,7 @@ impl ReedSolomonDecoder {
|
||||
Ok(vec![sigma, omega])
|
||||
}
|
||||
|
||||
fn findErrorLocations(&self, errorLocator: &GenericGFPoly) -> Result<Vec<usize>, Exceptions> {
|
||||
fn findErrorLocations(&self, errorLocator: &GenericGFPoly) -> Result<Vec<usize>> {
|
||||
// This is a direct application of Chien's search
|
||||
let numErrors = errorLocator.getDegree();
|
||||
if numErrors == 1 {
|
||||
@@ -204,7 +205,7 @@ impl ReedSolomonDecoder {
|
||||
&self,
|
||||
errorEvaluator: &GenericGFPoly,
|
||||
errorLocations: &Vec<usize>,
|
||||
) -> Result<Vec<i32>, Exceptions> {
|
||||
) -> Result<Vec<i32>> {
|
||||
// This is directly applying Forney's Formula
|
||||
let s = errorLocations.len();
|
||||
let mut result = vec![0; s];
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
use super::{GenericGFPoly, GenericGFRef};
|
||||
@@ -35,7 +36,7 @@ pub struct ReedSolomonEncoder {
|
||||
}
|
||||
|
||||
impl ReedSolomonEncoder {
|
||||
pub fn new(field: GenericGFRef) -> Result<Self, Exceptions> {
|
||||
pub fn new(field: GenericGFRef) -> Result<Self> {
|
||||
let n = field;
|
||||
Ok(Self {
|
||||
cachedGenerators: vec![GenericGFPoly::new(n, &[1])?],
|
||||
@@ -71,7 +72,7 @@ impl ReedSolomonEncoder {
|
||||
Some(rv)
|
||||
}
|
||||
|
||||
pub fn encode(&mut self, to_encode: &mut Vec<i32>, ec_bytes: usize) -> Result<(), Exceptions> {
|
||||
pub fn encode(&mut self, to_encode: &mut Vec<i32>, ec_bytes: usize) -> Result<()> {
|
||||
if ec_bytes == 0 {
|
||||
return Err(Exceptions::illegalArgumentWith("No error correction bytes"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user