Tweaked Python, Rust, TypeScript code to rename the constructor `mask` parameter to `msk` for consistency with Java and C++ language ports (related to commit 67c62461d3), and to avoid potential confusion with the object field named `mask`.

pull/134/head
Project Nayuki 3 years ago
parent d6be9c5e44
commit f0945bc682

@ -161,7 +161,7 @@ class QrCode:
# ---- Constructor (low level) ----
def __init__(self, version: int, errcorlvl: QrCode.Ecc, datacodewords: Union[bytes,Sequence[int]], mask: int) -> None:
def __init__(self, version: int, errcorlvl: QrCode.Ecc, datacodewords: Union[bytes,Sequence[int]], msk: int) -> None:
"""Creates a new QR Code with the given version number,
error correction level, data codeword bytes, and mask number.
This is a low-level API that most users should not use directly.
@ -170,7 +170,7 @@ class QrCode:
# Check scalar arguments and set fields
if not (QrCode.MIN_VERSION <= version <= QrCode.MAX_VERSION):
raise ValueError("Version value out of range")
if not (-1 <= mask <= 7):
if not (-1 <= msk <= 7):
raise ValueError("Mask value out of range")
if not isinstance(errcorlvl, QrCode.Ecc):
raise TypeError("QrCode.Ecc expected")
@ -189,20 +189,20 @@ class QrCode:
self._draw_codewords(allcodewords)
# Do masking
if mask == -1: # Automatically choose best mask
if msk == -1: # Automatically choose best mask
minpenalty: int = 1 << 32
for i in range(8):
self._apply_mask(i)
self._draw_format_bits(i)
penalty = self._get_penalty_score()
if penalty < minpenalty:
mask = i
msk = i
minpenalty = penalty
self._apply_mask(i) # Undoes the mask due to XOR
assert 0 <= mask <= 7
self._mask = mask
self._apply_mask(mask) # Apply the final choice of mask
self._draw_format_bits(mask) # Overwrite old format bits
assert 0 <= msk <= 7
self._mask = msk
self._apply_mask(msk) # Apply the final choice of mask
self._draw_format_bits(msk) # Overwrite old format bits
del self._isfunction

@ -277,7 +277,7 @@ impl QrCode {
///
/// This is a low-level API that most users should not use directly.
/// A mid-level API is the `encode_segments()` function.
pub fn encode_codewords(ver: Version, ecl: QrCodeEcc, datacodewords: &[u8], mut mask: Option<Mask>) -> Self {
pub fn encode_codewords(ver: Version, ecl: QrCodeEcc, datacodewords: &[u8], mut msk: Option<Mask>) -> Self {
// Initialize fields
let size = usize::from(ver.value()) * 4 + 17;
let mut result = Self {
@ -295,7 +295,7 @@ impl QrCode {
result.draw_codewords(&allcodewords);
// Do masking
if mask.is_none() { // Automatically choose best mask
if msk.is_none() { // Automatically choose best mask
let mut minpenalty = std::i32::MAX;
for i in 0u8 .. 8 {
let newmask = Mask::new(i);
@ -303,16 +303,16 @@ impl QrCode {
result.draw_format_bits(newmask);
let penalty: i32 = result.get_penalty_score();
if penalty < minpenalty {
mask = Some(newmask);
msk = Some(newmask);
minpenalty = penalty;
}
result.apply_mask(newmask); // Undoes the mask due to XOR
}
}
let mask: Mask = mask.unwrap();
result.mask = mask;
result.apply_mask(mask); // Apply the final choice of mask
result.draw_format_bits(mask); // Overwrite old format bits
let msk: Mask = msk.unwrap();
result.mask = msk;
result.apply_mask(msk); // Apply the final choice of mask
result.draw_format_bits(msk); // Overwrite old format bits
result.isfunction.clear();
result.isfunction.shrink_to_fit();

@ -155,6 +155,11 @@ namespace qrcodegen {
// 21 and 177 (inclusive). This is equal to version * 4 + 17.
public readonly size: int;
// The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
// Even if a QR Code is created with automatic masking requested (mask = -1),
// the resulting object still has a mask value between 0 and 7.
public readonly mask: int;
// The modules of this QR Code (false = light, true = dark).
// Immutable after constructor finishes. Accessed through getModule().
private readonly modules : Array<Array<boolean>> = [];
@ -179,15 +184,12 @@ namespace qrcodegen {
dataCodewords: Readonly<Array<byte>>,
// The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
// Even if a QR Code is created with automatic masking requested (mask = -1),
// the resulting object still has a mask value between 0 and 7.
public readonly mask: int) {
msk: int) {
// Check scalar arguments
if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION)
throw "Version value out of range";
if (mask < -1 || mask > 7)
if (msk < -1 || msk > 7)
throw "Mask value out of range";
this.size = version * 4 + 17;
@ -206,24 +208,24 @@ namespace qrcodegen {
this.drawCodewords(allCodewords);
// Do masking
if (mask == -1) { // Automatically choose best mask
if (msk == -1) { // Automatically choose best mask
let minPenalty: int = 1000000000;
for (let i = 0; i < 8; i++) {
this.applyMask(i);
this.drawFormatBits(i);
const penalty: int = this.getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
msk = i;
minPenalty = penalty;
}
this.applyMask(i); // Undoes the mask due to XOR
}
}
if (mask < 0 || mask > 7)
if (msk < 0 || msk > 7)
throw "Assertion error";
this.mask = mask;
this.applyMask(mask); // Apply the final choice of mask
this.drawFormatBits(mask); // Overwrite old format bits
this.mask = msk;
this.applyMask(msk); // Apply the final choice of mask
this.drawFormatBits(msk); // Overwrite old format bits
this.isFunction = [];
}

Loading…
Cancel
Save