diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index d7cf68b..19907c9 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -40,10 +40,10 @@ jobs: - name: Setup API markdown run: |- python -m pip install litedoc - python -m litedoc mbcp -o docs/zh/api -l zh-Hans -f editLink=false -cd class -fd def -md def -vd var -cs - python -m litedoc mbcp -o docs/en/api -l en -f editLink=false -cd class -fd def -md def -vd var -cs - python -m litedoc mbcp -o docs/ja/api -l ja -f editLink=false -cd class -fd def -md def -vd var -cs - python -m litedoc mbcp -o docs/zht/api -l zh-Hant -f editLink=false -cd class -fd def -md def -vd var -cs + litedoc mbcp -o docs/zh/api -l zh-Hans -f editLink=false -cd class -fd def -md def -vd var -cs + litedoc mbcp -o docs/en/api -l en -f editLink=false -cd class -fd def -md def -vd var -cs + litedoc mbcp -o docs/ja/api -l ja -f editLink=false -cd class -fd def -md def -vd var -cs + litedoc mbcp -o docs/zht/api -l zh-Hant -f editLink=false -cd class -fd def -md def -vd var -cs - name: 安装 pnpm uses: pnpm/action-setup@v2 diff --git a/docs/.vitepress/config/common.ts b/docs/.vitepress/config/common.ts index 29d898d..ddd209d 100644 --- a/docs/.vitepress/config/common.ts +++ b/docs/.vitepress/config/common.ts @@ -51,8 +51,11 @@ function generateSidebarConfig(): any[] { console.log(generateSidebarConfig()) export const common = defineConfig({ - title: "MBCP docs", - description: "MBCP library docs", + head: [ + [ + 'link', {rel: 'icon', type: 'image/svg+xml', href: '/mbcp-logo.svg'} + ] + ], markdown: { math: true }, @@ -60,6 +63,7 @@ export const common = defineConfig({ [`${defaultLocale}/:rest*`]: ":rest*", }, themeConfig: { + logo: '/mbcp-logo.svg', sidebar: generateSidebar( [ ...generateSidebarConfig() @@ -68,9 +72,6 @@ export const common = defineConfig({ socialLinks: [ {icon: 'github', link: 'https://github.com/snowykami/mbcp'} ], - editLink: { - pattern: 'https://github.com/snowykami/mbcp/tree/main/docs/:path' - }, outline: [2, 6] }, sitemap: { diff --git a/docs/.vitepress/config/en.ts b/docs/.vitepress/config/en.ts index 705cc88..95c0178 100644 --- a/docs/.vitepress/config/en.ts +++ b/docs/.vitepress/config/en.ts @@ -1,15 +1,24 @@ import {defineConfig} from 'vitepress' +import {ThemeConfig} from "./utils"; export const en = defineConfig({ lang: "en-US", - description: "A library made for Minecraft particle generation", + title: "MBCP docs", + description: "MBCP library docs", themeConfig: { nav: [ {text: 'Get Start', link: '/en/guide/'}, {text: 'Reference', link: '/en/refer'}, - {text: 'API Document', link: '/en/api/'}, + {text: 'API Reference', link: '/en/api/'}, {text: 'Demo', link: '/en/demo/'}, ], + docFooter: { + prev: 'Prev Page', + next: 'Next Page' + }, + editLink: ThemeConfig.getEditLink( + 'Edit this page on GitHub', + ), footer: { message: 'Documentation built with VitePress | API references generated by litedoc', copyright: 'Copyright (C) 2020-2024 SnowyKami. All Rights Reserved' diff --git a/docs/.vitepress/config/ja.ts b/docs/.vitepress/config/ja.ts index 1d802ea..47d00a2 100644 --- a/docs/.vitepress/config/ja.ts +++ b/docs/.vitepress/config/ja.ts @@ -1,15 +1,24 @@ import {defineConfig} from 'vitepress' +import {ThemeConfig} from "./utils"; export const ja = defineConfig({ lang: "ja-JP", - description: "Minecraftのパーティクル生成用のライブラリ", + title: "MBCP ドキュメント", + description: "MBCP ライブラリ ドキュメント", themeConfig: { nav: [ {text: 'スタート', link: '/ja/guide/'}, {text: 'リファレンス', link: '/ja/refer'}, - {text: 'APIドキュメント', link: '/ja/api/'}, + {text: 'APIリファレンス', link: '/ja/api/'}, {text: 'インスタンス', link: '/ja/demo/'}, ], + docFooter: { + prev: '前のページ', + next: '次のページ' + }, + editLink: ThemeConfig.getEditLink( + 'このページをGitHubで編集する', + ), footer: { message: 'VitePress で構築されたドキュメント | litedoc によって生成されたAPIリファレンス', copyright: 'Copyright (C) 2020-2024 SnowyKami. All Rights Reserved' diff --git a/docs/.vitepress/config/utils.ts b/docs/.vitepress/config/utils.ts new file mode 100644 index 0000000..8e65fd1 --- /dev/null +++ b/docs/.vitepress/config/utils.ts @@ -0,0 +1,23 @@ +/** + * GetEditLink Options + * @param text Edit link text + */ +export const ThemeConfig = { + getEditLink: (editPageText: string): { pattern: (params: { filePath: string; }) => string; text: string; } => { + return { + pattern: ({filePath}: { filePath: string; }): string => { + const regex = /^[^\/]+\/api/; + if (regex.test(filePath)) { + // remove {lang}/api prefix + filePath = filePath.replace(regex, '') + .replace('index.md', '__init__.py') + .replace('.md', '.py'); + return `https://github.com/snowykami/mbcp/tree/main/mbcp/${filePath}`; + } else { + return `https://github.com/snowykami/mbcp/tree/main/docs/${filePath}`; + } + }, + text: editPageText + }; + } +} \ No newline at end of file diff --git a/docs/.vitepress/config/zh.ts b/docs/.vitepress/config/zh.ts index 9554393..ff3ca89 100644 --- a/docs/.vitepress/config/zh.ts +++ b/docs/.vitepress/config/zh.ts @@ -1,15 +1,24 @@ import {defineConfig} from 'vitepress' +import {ThemeConfig} from "./utils"; export const zh = defineConfig({ lang: "zh-Hans", - description: "一个用于Minecraft粒子计算和生成的库", + title: "MBCP 文档", + description: "MBCP 粒子计算和生成库文档", themeConfig: { nav: [ {text: '快速开始', link: '/guide/'}, {text: '参考', link: '/refer'}, - {text: 'API文档', link: '/api/'}, + {text: 'API引用', link: '/api/'}, {text: '实例', link: '/demo/'}, ], + docFooter: { + prev: '上一页', + next: '下一页' + }, + editLink: ThemeConfig.getEditLink( + '在 GitHub 上编辑此页', + ), footer: { message: '文档由 VitePress 构建 | API引用由 litedoc 生成', copyright: 'Copyright (C) 2020-2024 SnowyKami. All Rights Reserved' diff --git a/docs/.vitepress/config/zht.ts b/docs/.vitepress/config/zht.ts index 84e879a..918d0d6 100644 --- a/docs/.vitepress/config/zht.ts +++ b/docs/.vitepress/config/zht.ts @@ -1,16 +1,24 @@ import {defineConfig} from 'vitepress' +import {ThemeConfig} from "./utils"; export const zht = defineConfig({ - lang: "zh-Hant", - description: "一個用於Minecraft粒子計算和生成的軟體庫", + title: "MBCP 文檔", + description: "MBCP 粒子計算和生成庫文檔", themeConfig: { nav: [ {text: '指引', link: '/zht/guide/'}, {text: '參考', link: '/zht/refer'}, - {text: 'API文檔', link: '/zht/api/'}, + {text: 'API引用', link: '/zht/api/'}, {text: '示範', link: '/zht/demo/'}, ], + docFooter: { + prev: '上一頁', + next: '下一頁' + }, + editLink: ThemeConfig.getEditLink( + '於 GitHub 上編輯這頁', + ), footer: { message: '文檔由 VitePress 構建 | API引用由 litedoc 生成', copyright: 'Copyright (C) 2020-2024 SnowyKami. All Rights Reserved' diff --git a/docs/en/index.md b/docs/en/index.md index 435bd93..e8b1c52 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -3,9 +3,9 @@ layout: home hero: - name: "MBCP docs" + name: "MBCP" text: "More basic change particle" - tagline: A Library for Python to create particle effects and geometric figures + tagline: A Library for Python to create Minecraft particle effects and geometric figures actions: - theme: brand text: Get Started @@ -13,6 +13,9 @@ hero: - theme: alt text: API Reference link: ./api/ + image: + src: /mbcp-logo.svg + alt: MBCP logo features: - title: Easy to use diff --git a/docs/ja/index.md b/docs/ja/index.md index bc8ec78..300bfdf 100644 --- a/docs/ja/index.md +++ b/docs/ja/index.md @@ -3,7 +3,7 @@ layout: home hero: - name: "MBCP docs" + name: "MBCP" text: "More basic change particle" tagline: ジオメトリ演算とパーティクル作成のためのライブラリ actions: @@ -13,6 +13,9 @@ hero: - theme: alt text: API リファレンス link: ./api/ + image: + src: /mbcp-logo.svg + alt: MBCP logo features: - title: 高可用性 diff --git a/docs/public/mbcp-logo.svg b/docs/public/mbcp-logo.svg new file mode 100644 index 0000000..41dc567 --- /dev/null +++ b/docs/public/mbcp-logo.svg @@ -0,0 +1,7 @@ + + + Layer 1 + + + + \ No newline at end of file diff --git a/docs/zh/index.md b/docs/zh/index.md index 140bd0a..7076605 100644 --- a/docs/zh/index.md +++ b/docs/zh/index.md @@ -3,9 +3,9 @@ layout: home hero: - name: "MBCP docs" - text: "More basic change particle" - tagline: 用于几何运算和粒子制作的库 + name: "MBCP" + text: "更多基础变换粒子" + tagline: 用于几何运算和Minecraft粒子制作的库 actions: - theme: brand text: 快速开始 @@ -13,6 +13,9 @@ hero: - theme: alt text: API文档 link: ./api/ + image: + src: /mbcp-logo.svg + alt: MBCP logo features: - title: 高可用性 diff --git a/docs/zht/index.md b/docs/zht/index.md index aa32e62..c699a85 100644 --- a/docs/zht/index.md +++ b/docs/zht/index.md @@ -3,9 +3,9 @@ layout: home hero: - name: "MBCP docs" - text: "More basic change particle" - tagline: 用於幾何運算和粒子製作的軟體庫 + name: "MBCP" + text: "更多基礎變化粒子" + tagline: 用於幾何運算和 當個創世神 粒子製作的軟體庫 actions: - theme: brand text: 跟隨引導 @@ -13,6 +13,9 @@ hero: - theme: alt text: API文檔 link: ./api/ + image: + src: /mbcp-logo.svg + alt: MBCP logo features: - title: 高度易用 @@ -22,3 +25,21 @@ features: - title: 內置預設 details: 提供了大量的預設,包括常見的幾何圖形、粒子效果等,便於快速生產 --- + \ No newline at end of file diff --git a/mbcp/mp_math/equation.py b/mbcp/mp_math/equation.py index e63797c..3313a66 100644 --- a/mbcp/mp_math/equation.py +++ b/mbcp/mp_math/equation.py @@ -85,18 +85,4 @@ def get_partial_derivative_func(func: MultiVarsFunc, var: int | tuple[int, ...], raise ValueError("Invalid var type") -def curry(func: MultiVarsFunc, *args: Var) -> OneVarFunc: - """ - 对多参数函数进行柯里化。 - > [!tip] - > 有关函数柯里化,可参考[函数式编程--柯理化(Currying)](https://zhuanlan.zhihu.com/p/355859667) - Args: - func: 函数 - *args: 参数 - Returns: - 柯里化后的函数 - """ - def curried_func(*args2: Var) -> Var: - """@litedoc-hide""" - return func(*args, *args2) - return curried_func + diff --git a/mbcp/mp_math/function.py b/mbcp/mp_math/function.py index 821db9a..c90f3a0 100644 --- a/mbcp/mp_math/function.py +++ b/mbcp/mp_math/function.py @@ -2,7 +2,7 @@ AAA """ -from .mp_math_typing import ThreeSingleVarsFunc +from .mp_math_typing import MultiVarsFunc, OneVarFunc, ThreeSingleVarsFunc, Var from .point import Point3 from .vector import Vector3 from .const import EPSILON @@ -25,3 +25,29 @@ def cal_gradient_3vf(func: ThreeSingleVarsFunc, p: Point3, epsilon: float = EPSI dy = (func(p.x, p.y + epsilon, p.z) - func(p.x, p.y - epsilon, p.z)) / (2 * epsilon) dz = (func(p.x, p.y, p.z + epsilon) - func(p.x, p.y, p.z - epsilon)) / (2 * epsilon) return Vector3(dx, dy, dz) + + +def curry(func: MultiVarsFunc, *args: Var) -> OneVarFunc: + r""" + 对多参数函数进行柯里化。 + > [!tip] + > 有关函数柯里化,可参考[函数式编程--柯理化(Currying)](https://zhuanlan.zhihu.com/p/355859667) + Args: + func: 函数 + *args: 参数 + Returns: + 柯里化后的函数 + Examples: + ```python + def add(a: int, b: int, c: int) -> int: + return a + b + c + add_curried = curry(add, 1, 2) + add_curried(3) # 6 + ``` + """ + + def curried_func(*args2: Var) -> Var: + """@litedoc-hide""" + return func(*args, *args2) + + return curried_func diff --git a/mkdoc.bat b/mkdoc.bat index 97c7646..01500c3 100644 --- a/mkdoc.bat +++ b/mkdoc.bat @@ -1,5 +1,5 @@ chcp 65001 -python -m litedoc mbcp -o docs/zh/api -l zh-Hans -f editLink=false -cd class -fd def -md def -vd var -cs -python -m litedoc mbcp -o docs/en/api -l en -f editLink=false -cd class -fd def -md def -vd var -cs -python -m litedoc mbcp -o docs/ja/api -l ja -f editLink=false -cd class -fd def -md def -vd var -cs -python -m litedoc mbcp -o docs/zht/api -l zh-Hant -f editLink=false -cd class -fd def -md def -vd var -cs \ No newline at end of file +litedoc mbcp -o docs/zh/api -l zh-Hans -cd class -fd def -md def -vd var -cs +litedoc mbcp -o docs/en/api -l en -cd class -fd def -md def -vd var -cs +litedoc mbcp -o docs/ja/api -l ja -cd class -fd def -md def -vd var -cs +litedoc mbcp -o docs/zht/api -l zh-Hant -cd class -fd def -md def -vd var -cs \ No newline at end of file