Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

塗りつぶしのアルゴリズムを変更 #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SSlime-s
Copy link
Member

@SSlime-s SSlime-s commented May 20, 2024

差分を見やすくするために canvas 追加のやつに向けてます

ref: https://en.wikipedia.org/wiki/Flood_fill

区間ベースで持つことで見るピクセル数を減少させるように

アルゴリズムが正当か は見なくていいです (コメントちゃんと書いたから見てもいいけど)

https://sslime-change-fill-algorithm.nascalay-v2-preview.pages.dev/tmp2 で試せます

@SSlime-s SSlime-s force-pushed the SSlime/change-fill-algorithm branch from 002bbb7 to 93ecde7 Compare May 20, 2024 22:46
Copy link

cloudflare-workers-and-pages bot commented May 20, 2024

Deploying nascalay-v2-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: e923999
Status: ✅  Deploy successful!
Preview URL: https://3fb87a71.nascalay-v2-preview.pages.dev
Branch Preview URL: https://sslime-change-fill-algorithm.nascalay-v2-preview.pages.dev

View logs

Copy link
Member

@ras0q ras0q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

みました

Comment on lines 62 to 72
interface Operations {
/**
* キャンバス内の有効な座標かつ targetColor と等しいかどうかを返す
*/
inside: (x: number, y: number) => boolean;
/**
* キャンバスの座標 (x, y) を塗りつぶす色で塗る
*/
set: (x: number, y: number) => void;
pushSeed: (seed: Seed) => void;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これもっと上の方にあると助かる

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bucketFill に近接させたかったけどまぁあんま変わんないから一番上にしました

/**
* キャンバスの座標 (x, y) を塗りつぶす色で塗る
*/
set: (x: number, y: number) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set: (x: number, y: number) => void;
draw: (x: number, y: number) => void;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

命名 wiki からだからあんま変えたくない (wiki 読んだ人がそのまま読めるようにしてるので)

/**
* キャンバス内の有効な座標かつ targetColor と等しいかどうかを返す
*/
inside: (x: number, y: number) => boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

色判定までするなら

Suggested change
inside: (x: number, y: number) => boolean;
canDraw: (x: number, y: number) => boolean;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

命名 wiki からだからあんま変えたくない (wiki 読んだ人がそのまま読めるようにしてるので)

y < yRange[1] &&
likeEqualColor(data[y][x], targetColor);
}
function createSet(data: Color[][], color: Color): Operations["set"] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createInsideもややだけど使うのoperationsの初期化のときだけだしラップするまででもなさそう
好みで

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

しないとしたら bucketFill の関数内にそのまま書くってこと?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そう、pushSeedがそうだからここだけ切り出してるのが気になった

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

処理が長めだったから切ったような記憶がある

Copy link

Deploying nascalay-v2-storybook with  Cloudflare Pages  Cloudflare Pages

Latest commit: e923999
Status:🚫  Build failed.

View logs

Base automatically changed from SSlime/add-canvas to main May 31, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants