static applyMaskPenaltyRule1Internal(matrix, isHorizontal) {
			let penalty = 0;
			const iLimit = isHorizontal ? matrix.getHeight() : matrix.getWidth();
			const jLimit = isHorizontal ? matrix.getWidth() : matrix.getHeight();
			const array = matrix.getArray();
			for (let i = 0; i < iLimit; i++) {
				let numSameBitCells = 0;
				let prevBit = -1;
				for (let j = 0; j < jLimit; j++) {
					const bit = isHorizontal ? array[i][j] : array[j][i];
					if (bit === prevBit) {
						numSameBitCells++;
					}
					else {
						if (numSameBitCells >= 5) {
							penalty += MaskUtil.N1 + (numSameBitCells - 5);
						}
						numSameBitCells = 1; // Include the cell itself.
						prevBit = bit;
					}
				}
				if (numSameBitCells >= 5) {
					penalty += MaskUtil.N1 + (numSameBitCells - 5);
				}
			}
			return penalty;
		}
Helper function for applyMaskPenaltyRule1. We need this for doing this calculation in both
vertical and horizontal orders respectively.