Mandelbrot Set C++ Code Design Review Report
マンデルブロ集合C++コード設計レビューレポート

Introduction / はじめに

This report provides a design review of the `p61.cpp` C++ program, which generates the Mandelbrot Set. The review focuses on aspects relevant to embedded system development, aiming to provide insights for beginners in this field. The original source code and test results are included for comprehensive analysis.

このレポートは、マンデルブロ集合を生成するC++プログラム `p61.cpp` の設計レビューを提供します。組み込みシステム開発に関連する側面に焦点を当て、この分野の初心者の方々に洞察を提供することを目的としています。包括的な分析のために、元のソースコードとテスト結果が含まれています。

Source Code / ソースコード

Below is the original C++ source code for the Mandelbrot Set generation.

以下は、マンデルブロ集合生成の元のC++ソースコードです。


#include<stdio.h>
#define LOOP 20
int mandel(double cr, double ci) {
	double zr = 0.0, zi = 0.0;
	double ar, ai;
	for (int i = 0; i < LOOP; i++) {
		double mag_sq = zr * zr + zi * zi;
		if (4 < mag_sq) return i * 256 / LOOP;
	//	ar+j ai = ( zr + j zi) * (zr + j zr)
		ar = zr * zr - zi * zi;
		ai = zr * zi + zi * zr;
    //  zr+j zi=  ( ar + j ar) + (cr +j ci)
		zr = ar + cr;
		zi = ai + ci;		
	}
	return 0;
}


int main() {
	int num = 0;
	num = mandel(0, 0);
	printf("mandel(0,0):%d\n", num);
	num = mandel(1, 1);
	printf("mandel(1,1):%d\n", num);
	num = mandel(2, 2);
	printf("mandel(2,2):%d\n", num);
	num = mandel(1, -1);
	printf("mandel(1,-1):%d\n", num);
	num = mandel(2, -2);
	printf("mandel(1,-1):%d\n", num);
	

	for (int y = 0; y < 200; y=y+10) {
		for (int x = 0; x < 400; x=x+10) {		
			double cr = -2.0 + (double)x * (4.0 / 400.0);
			double ci = -1.0 + (double)y * (2.0 / 200.0);
			int color = mandel(cr, ci);
			printf("%02x", color);
		} printf("\n");
	}
	return 0;
}
                

Test Results / テスト結果

The following are the results obtained from executing the provided C++ code.

以下は、提供されたC++コードを実行して得られた結果です。


mandel(0, 0) :0
mandel(1, 1) : 25
mandel(2, 2) : 12
mandel(1, -1) : 25
mandel(1, -1) : 12

0c0c0c191919262626262626262633333340597300333326261919191919191919191919190c0c
0c0c0c19262626262626262633333333404c73006640333326262619191919191919191919190c0c
0c0c19262626262626262633333333404c660000e64c40403326262619191919191919191919190c
0c0c192626262626262633333340596666800000a6734c4c4033262619191919191919191919190c
0c1926262626262626333340404c990000000000000099c0c0332626261919191919191919191919
0c19262626262633404040404c669900000000000000000059402626261919191919191919191919
0c2626262633405959595959598c0000000000000000000073403326262619191919191919191919
0c26333333404059cc99008c730000000000000000000000c04c3326262619191919191919191919
0c33333340404c66e6000000c0000000000000000000000000403326262619191919191919191919
0c33334c4c5999b30000000000000000000000000000000066403326262619191919191919191919
00000000000000000000000000000000000000000000009959403326262626191919191919191919
0c33334c4c5999b30000000000000000000000000000000066403326262619191919191919191919
0c33333340404c66e6000000c0000000000000000000000000403326262619191919191919191919
0c26333333404059cc99008c730000000000000000000000c04c3326262619191919191919191919
0c2626262633405959595959598c0000000000000000000073403326262619191919191919191919
0c19262626262633404040404c669900000000000000000059402626261919191919191919191919
0c1926262626262626333340404c990000000000000099c0c0332626261919191919191919191919
0c0c192626262626262633333340596666800000a6734c4c4033262619191919191919191919190c
0c0c19262626262626262633333333404c660000e64c40403326262619191919191919191919190c
0c0c0c19262626262626262633333333404c73006640333326262619191919191919191919190c0c
                

Design Review / 設計レビュー

Readability & Clarity / 可読性と明瞭性

Efficiency / 効率性

Maintainability / 保守性

Embedded Systems Considerations / 組み込みシステムに関する考慮事項

Potential Improvements / 改善点

Conclusion / まとめ

This C++ program provides a good basic implementation for understanding the Mandelbrot Set. For embedded beginners, it highlights important considerations regarding floating-point performance and output methods. By applying the suggested improvements, the code can be made more robust, maintainable, and suitable for various embedded environments.

このC++プログラムは、マンデルブロ集合を理解するための良い基本的な実装を提供します。組み込み初心者にとっては、浮動小数点演算のパフォーマンスと出力方法に関する重要な考慮事項を浮き彫りにします。提案された改善点を適用することで、コードはより堅牢で保守しやすくなり、様々な組み込み環境に適したものになります。