refactor: Explicit names when handling Ba-Gua

This commit is contained in:
minagawah
2022-07-20 21:46:07 +09:00
parent aa22f55c5e
commit a220d0f9f2
13 changed files with 466 additions and 293 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "mikaboshi" name = "mikaboshi"
version = "0.7.0" version = "0.8.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]

View File

@@ -5,15 +5,15 @@
## 1. About ## 1. About
__"mikaboshi"__ is a calculation library for Chinese astrology (written in Rust), __"mikaboshi"__ is a calculation library for Chinese astrology (written in Rust)
specifically, for _"Feng-Shui"_ (風水 or 风水). specifically for _Feng-Shui_ (風水 or 风水).
The name __"mikaboshi"__ derives from a Marvel character The name _"mikaboshi"_ derives from a Marvel character
["Amatsu-Mikaboshi"](https://marvel.fandom.com/wiki/Amatsu-Mikaboshi_(Earth-616)), ["Amatsu-Mikaboshi"](https://marvel.fandom.com/wiki/Amatsu-Mikaboshi_(Earth-616)),
or one of the goddesses in Shinto myth. or one of the goddesses in Shinto myth.
"Amatsu-Mikaboshi" (アマツミカボシ), _"Amatsu-Mikaboshi"_ (アマツミカボシ),
when literally translated, means _"the shinning star in the sky"_. when literally translated, means _"the shinning star in the sky"_.
Supported (Chinese astrological) concepts are: Supported (Chinese astrological) calculations are:
- [八卦 (Ba-Gua)](./docs/bagua.md) - [八卦 (Ba-Gua)](./docs/bagua.md)
- [干支 (Gan-Zhi)](./docs/ganzhi.md) - [干支 (Gan-Zhi)](./docs/ganzhi.md)
@@ -24,15 +24,15 @@ Supported (Chinese astrological) concepts are:
This library depends on This library depends on
["sowngwala"](https://github.com/minagawah/sowngwala/) ["sowngwala"](https://github.com/minagawah/sowngwala/)
for calculating sun's position. for calculating the sun's position.
For both "mikaboshi" and "sowngwala" use For both _"mikaboshi"_ and _"sowngwala"_ use
[chrono](https://crates.io/crates/chrono) [chrono](https://crates.io/crates/chrono)
for managing date & time. for managing date & time.
You may have noticed many examples found in You may have noticed many codes found in
[samples](./docs/examples/index.md) are that of WASM apps. [samples](./docs/examples/index.md) are that of WASM apps.
Yet, it does not mean you need WASM apps. Yet, it does not mean you need WASM apps.
It is just that I happen to have a WASM app using the library, It is just that I happen to have a WASM app using this library,
and was easy for me to share the codes... and was easy for me to share the codes...
__What Makes The Program Tricky?__ __What Makes The Program Tricky?__
@@ -89,14 +89,18 @@ Each page provides general descriptions about what they are,
and also provide some examples. and also provide some examples.
You can also explore the actual codes for they contain a lot of _doc tests_. You can also explore the actual codes for they contain a lot of _doc tests_.
### [八卦 (Bagua)](./docs/bagua.md) ### [八卦 (Ba-Gua)](./docs/bagua.md)
- [Bagua](./docs/bagua.md#baguabagua) - [Gua](./docs/bagua.md#baguagua)
- [BaguaRawData](./docs/bagua.md#baguabaguarawdata) - [GuaRaw](./docs/bagua.md#baguaguaraw)
- [BAGUA](./docs/bagua.md#baguabagua) - [BAGUA_LO_SHU_ORDER_WITH_CENTER](./docs/bagua.md#baguabagua_lo_shu_order_with_center)
- [BAGUA_START_NORTH_INDEXES](./docs/bagua.md#baguabagua_start_north_indexes) - [BAGUA_HE_TU_ORDER_INDEXES](./docs/bagua.md#baguabagua_he_tu_order_indexes)
- [BAGUA_START_NORTH](./docs/bagua.md#baguabagua_start_north) - [BAGUA_HE_TU_ORDER](./docs/bagua.md#baguabagua_he_tu_order)
- [get_bagua_start_north](./docs/bagua.md#baguaget_bagua_start_north) - [BAGUA_LO_SHU_ORDER_INDEXES](./docs/bagua.md#baguabagua_lo_shu_order_indexes)
- [BAGUA_LO_SHU_ORDER](./docs/bagua.md#baguabagua_lo_shu_order)
- [BAGUA_LO_SHU_COMPASS_ORDER_INDEXES](./docs/bagua.md#baguabagua_lo_shu_compass_order_indexes)
- [BAGUA_LO_SHU_COMPASS_ORDER](./docs/bagua.md#baguabagua_lo_shu_compass_order)
- [get_gua_compass_order](./docs/bagua.md#baguaget_gua_compass_order)
### [干支 (Gan-Zhi)](./docs/ganzhi.md) ### [干支 (Gan-Zhi)](./docs/ganzhi.md)

View File

@@ -1,19 +1,48 @@
# 八卦 (Bagua) # 八卦 (Ba-Gua)
Source: [src/bagua.rs](../src/bagua.rs) Source: [src/bagua.rs](../src/bagua.rs)
![sample_bagua](./sample_bagua.png) ![sample_bagua](./sample_bagua.png)
Although 八卦 (Ba-Gua) is a concept in 易経 (I-Ching), 八卦 (Ba-Gua) is a concept in 易経 (I-Ching) which is merely a concept
when used in Feng-Shui, it is often associated with 九星 (Jiu-Xing). in fortune telling, but also appears frequently in a variety of
While everthing in this world is (said to be) divided into either 陰 (Yin) Chinese philosophy. "Gua" (卦) is a conventional unit which characterizes
or 陽 (Yang), each could be further divided into lesser Yin and Yang. certain aspects/qualities in life. "Ba" simply means "8" in Chinese.
For Yang, some may be abundant in Yang. Or, some may slightly lean toward Yin. So, "Ba-Gua" (八卦) tells that it consists of 8 卦 (Gua). To the eyes of
This goes for Yin as well. Here, the initial Yin and Yang, ancient Chinese, everything in this world was of either 陰 (Yin) or 陽 (Yang).
now divided into 4, or becomes 4 patterns. Then, for each, Or, you could say, the world is divided into 2. However, if you observe
there are further divisions, and for this time, it now makes it 8 patterns. more carefully, you notice some in Yang may slightly lean toward Yin, and
Ancient Chinese had a specific term for these 8 patterns, some in Yin toward Yang. So, you could probably have another division there,
and it is called, 八卦 (Ba-Gua), or "8 Gua". for this time, divisions of 4. For greater Yang, you have lesser "Yin"
and "Yang", or you may call them, "Yang-Yang" and "Yang-Yin". Likewise,
for Yin, you will have "Yin-Yang" and "Yin-Yin". If you are brave enough,
you could repeat the process for the one last time. This time, you would
divide the world into 8. For ancient Chinese perceived the last division
of 8 being the basic building blocks for observing nature, and called
them, 八卦 (Ba-Gua)
Now, when we say 八卦 (Ba-Gua), we usually refer to 2 different systems.
For the division just described above is called "先天八卦" (or
_"The Primordial Heaven"_), and a diagram to represent this order
is called "河圖" (He-Tu) (or 伏羲八卦 (Fu-Xi Ba-Gua)). Another one
is called "後天八卦" (or _"The Manifested Heaven"_), and its diagram
is called "洛書" (Lo-Shu) (or 文王八卦 (King Wen Ba-Gua)).
For the former illustrates the world of the original heaven,
and the latter, the manifested world (for which elements in nature
play active roles to produce gross material plane of our reality).
Order of 河圖 (He-Tu) (for 先天八卦 _"The Primordial Heaven"_)
[0] 乾 (Qian)
[1] 兌 (Dui)
[2] 離 (Li)
[3] 震 (Zhen)
[4] 巽 (Xun)
[5] 坎 (Kan)
[6] 坤 (Kun)
[7] 艮 (Gen)
Order of 洛書 (Lo-Shu) (for 後天八卦 _"The Manifested Heaven"_)
[0] 坎 (Kan) [0] 坎 (Kan)
[1] 坤 (Kun) [1] 坤 (Kun)
@@ -24,104 +53,168 @@ and it is called, 八卦 (Ba-Gua), or "8 Gua".
[6] 艮 (Gen) [6] 艮 (Gen)
[7] 離 (Li) [7] 離 (Li)
So, when we talk about 八卦 (Ba-Gua), we need to be specific about
which world we referring to. As you can see, there are 3 sets
of vectors defined in this program, namely:
## bagua::Bagua - `BAGUA_HE_TU_ORDER`
- `BAGUA_LO_SHU_ORDER`
- `BAGUA_LO_SHU_ORDER_WITH_CENTER`
Notice that the first 2 consists of 8 items, but the third one
consists of 9. When using 八卦 (Ba-Gua) for Feng-Shui, we usually
refer to 洛書 (Lo-Shu) diagram (which is `BAGUA_LO_SHU_ORDER`).
However, we usually plot 洛書 (Lo-Shu) into 9 boxes because it is
often associated with 九星 (Jiu-Xing) which requires not only
8 compass directions, but with an extra box in the middle.
So, in addition to 八卦 (Ba-Gua), when managing 洛書 (Lo-Shu)
for Feng-Shui, we need CENTER (or "中" (Zhong) in Chinese),
and that is what we have for `BAGUA_LO_SHU_ORDER_WITH_CENTER`.
Also, notice of another vector defined in the program, namely,
`BAGUA_LO_SHU_COMPASS_ORDER`. This is a special vector for which
the order is _conceptually_ in "Lo-Shu" order, however, mapped
to 8 compass directions as each 卦 (Gua) plotted in clockwise manner.
This is specially useful when we have an app with a compass UI
because you can directly plot 卦 (Gua) out of this vector.
## bagua::Gua
A struct representing 卦 (Gua) and stores its attributes. A struct representing 卦 (Gua) and stores its attributes.
```rust ```rust
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bagua { pub struct Gua {
pub num: u8,
pub name: Language, pub name: Language,
pub jiuxing_num: u8,
pub direction: String, pub direction: String,
pub element: u8, pub element: u8,
} }
``` ```
## bagua::BaguaRawData ## bagua::GuaRaw
A temporary struct for loading JSON data when defining a static const `BAGUA`. A temporary struct for loading JSON data when defining
a various vectors for 八卦 (Ba-Gua).
```rust ```rust
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BaguaRawData { pub struct GuaRaw {
pub num: u8,
pub name: LanguageData, pub name: LanguageData,
pub jiuxing_num: u8,
pub direction: String, pub direction: String,
pub element: u8, pub element: u8,
} }
``` ```
## bagua::BAGUA ## bagua::BAGUA_LO_SHU_ORDER_WITH_CENTER
`Vec<Bagua>` `Vec<Gua>`
A static vector with 9 items, each represents 卦 (Gua) of 八卦 (Ba-Gua), This is a vector for 八卦 (Ba-Gua) with 9 items where the 5th item
or what known as "Eight Trigrams". Each stores associated attributes being "中" (Zhong). By having 9 items instead of 8, it can be
for the 卦 (Gua), and are in the order of Ba-Gua Numbers. For instance, directly mapped to 9 stars of 九星 (Jiu-Xing). Since 九星 (Jiu-Xing)
坎 (Kan) is the first in Ba-Gua, so it comes first in the vector. is mapped in "Lo-Shu" (洛書) order, so is this vector.
However, be careful when you refer to each 卦 (Gua) as the program Check out the attribute `jiuxing_num` for each data, and you will
refers 卦 (Gua) not by Ba-Gua Numbers, but by vector indexes. notice it corresponds to the Jiu-Xing number.
For 坎 (Kan), for instance, while it has the Ba-Gua Number of 1,
it is referred as 0 because that is the index is for 坎 (Kan). 八卦 (Ba-Gua) in "Lo-Shu" (洛書) order with 中 (Zhong) in the middle:
[0] 坎 (Kan) -> No. 1
[1] 坤 (Kun) -> No. 2
[2] 震 (Zhen) -> No. 3
[3] 巽 (Xun) -> No. 4
[4] 中 (Zhong) -> No. 5
[5] 乾 (Qian) -> No. 6
[6] 兌 (Dui) -> No. 7
[7] 艮 (Gen) -> No. 8
[8] 離 (Li) -> No. 9
[0] 坎 (1 = Kan)
[1] 坤 (2 = Kun)
[2] 震 (3 = Zhen)
[3] 巽 (4 = Xun)
[4] 中 (5 = Zhong)
[5] 乾 (6 = Qian)
[6] 兌 (7 = Dui)
[7] 艮 (8 = Gen)
[8] 離 (9 = Li)
For attributes details stored in the vector is found in JSON file: For attributes details stored in the vector is found in JSON file:
[json/bagua.json](../json/bagua.json) `src/json/bagua.json`
## bagua::BAGUA_START_NORTH_INDEXES ## bagua::BAGUA_HE_TU_ORDER_INDEXES
`Vec<u8>`
[INDEX] 八卦 (Ba-Gua) in "He-Tu" (河圖) order.
## bagua::BAGUA_HE_TU_ORDER
`Vec<Gua>`
[ACTUAL DATA] 八卦 (Ba-Gua) in "He-Tu" (河圖) order.
[0] 乾 (Qian)
[1] 兌 (Dui)
[2] 離 (Li)
[3] 震 (Zhen)
[4] 巽 (Xun)
[5] 坎 (Kan)
[6] 坤 (Kun)
[7] 艮 (Gen)
## bagua::BAGUA_LO_SHU_ORDER_INDEXES
`Vec<u8>` `Vec<u8>`
Another static vector for 八卦 (Ba-Gua) (and is `Vec<u8>`). [INDEX] 八卦 (Ba-Gua) in "Lo-Shu" (洛書) order.
However, this time, it has only 8 items because this is used
for compass rotation. When using a compass, only 8 directions matter,
and the middle does not mean anything. When 八卦 (Ba-Gua) are
placed in 洛書 (Lo-Shu) order, 中 (Zhong) comes in the middle.
So, 中 (Zhong) is missing for this vector. For 八卦 (Ba-Gua),
it begins with 坎 (Kan) which resides in the north
when they are placed in Lo-Shu order. Moving clockwise,
what you see next in the north-east, is 艮 (Gen).
Then, comes 震 (3 = Zhen) which is in the east, and, so on.
[0] 坎 (1 = Kan) ## bagua::BAGUA_LO_SHU_ORDER
[1] 艮 (8 = Gen)
[2] 震 (3 = Zhen)
[3] 巽 (4 = Xun)
[4] 離 (9 = Li)
[5] 坤 (2 = Kun)
[6] 兌 (7 = Dui)
[7] 乾 (6 = Qian)
## bagua::BAGUA_START_NORTH `Vec<Gua>`
[ACTUAL DATA] 八卦 (Ba-Gua) in "Lo-Shu" (洛書) order.
`Vec<Bagua>` [0] 坎 (Kan)
[1] 艮 (Gen)
[2] 震 (Zhen)
[3] 巽 (Xun)
[4] 離 (Li)
[5] 坤 (Kun)
[6] 兌 (Dui)
[7] 乾 (Qian)
While the order is the same as `BAGUA_START_NORTH_INDEXES`, ## bagua::BAGUA_LO_SHU_COMPASS_ORDER_INDEXES
for this time, it is `Vec<Bagua>` instead of `Vec<u8>`.
## bagua::get_bagua_start_north `Vec<u8>`
A getter for `BAGUA_START_NORTH`. [INDEX] 八卦 (Ba-Gua) in "Lo-Shu" order, however, mapped to 8 compass directions.
## bagua::BAGUA_LO_SHU_COMPASS_ORDER
`Vec<Gua>`
[ACTUAL DATA] 八卦 (Ba-Gua) in "Lo-Shu" order, however, mapped to 8 compass directions.
When "Lo-Shu" (洛書) order is mapped to 8 compass directions, it is convenient
to have a vector which starts with 卦 (Gua) for _"NORTH"_ which is "坎" (Kan).
Likewise, we want the second item being 卦 (Gua) for _"NORTH EAST"_ which is "艮" (Gen).
For the third item, likewise, for _"EAST"_ or "震" (Zhen).
八卦 (Ba-Gua) in "Lo-Shu" order mapped to 8 directions (starting NORTH):
[0] 坎 (Kan)-> N
[1] 艮 (Gen)-> NE
[2] 震 (Zhen)-> E
[3] 巽 (Xun)-> SE
[4] 離 (Li)-> S
[5] 坤 (Kun)-> SW
[6] 兌 (Dui)-> W
[7] 乾 (Qian)-> NW
## bagua::get_gua_compass_order
A getter for `BAGUA_LO_SHU_COMPASS_ORDER`.
Example: Example:
```rust ```rust
use mikaboshi::bagua::{get_bagua_start_north, Bagua}; use mikaboshi::bagua::{get_gua_compass_order, Gua};
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[wasm_bindgen] #[wasm_bindgen]
pub fn xx(index: usize) -> JsValue { pub fn xx(index: usize) -> JsValue {
let bagua: Option<&Bagua> = get_bagua_start_north(index); let gua: Option<&Gua> = get_gua_compass_order(index);
JsValue::from_serde(&bagua).unwrap() JsValue::from_serde(&gua).unwrap()
} }
``` ```

View File

@@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"]
chrono = "0.4.19" chrono = "0.4.19"
console_error_panic_hook = "^0.1.6" console_error_panic_hook = "^0.1.6"
js-sys = "0.3.52" js-sys = "0.3.52"
mikaboshi = { git = "https://github.com/minagawah/mikaboshi", version = "0.6.0" } mikaboshi = { git = "https://github.com/minagawah/mikaboshi", version = "0.8.0" }
serde = { version = "1.0.127", features = ["derive"] } serde = { version = "1.0.127", features = ["derive"] }
wasm-bindgen = { version = "0.2.70", features = ["serde-serialize"] } wasm-bindgen = { version = "0.2.70", features = ["serde-serialize"] }

View File

@@ -22,7 +22,7 @@ import React, {
import moment from 'moment'; import moment from 'moment';
import init, { import init, {
// 八卦 (Ba-Gua) // 八卦 (Ba-Gua)
get_bagua_start_north as wasm_get_bagua_start_north, get_gua_compass_order as wasm_get_gua_compass_order,
// 二十四山向 (Er-Shi Si-Shan Xiang) // 二十四山向 (Er-Shi Si-Shan Xiang)
get_twentyfour_direction_from_index as wasm_get_twentyfour_direction_from_index, get_twentyfour_direction_from_index as wasm_get_twentyfour_direction_from_index,
get_twentyfour_direction_from_degrees as wasm_get_twentyfour_direction_from_degrees, get_twentyfour_direction_from_degrees as wasm_get_twentyfour_direction_from_degrees,
@@ -53,8 +53,6 @@ const WASM_PATH =
? 'wasm/voi-feng-shui/voi-feng-shui_bg.wasm' ? 'wasm/voi-feng-shui/voi-feng-shui_bg.wasm'
: void 0; : void 0;
// console.log('[useFengShui] WASM_PATH: ', WASM_PATH);
const DATETIME_KEYS = Object.keys(DATETIME_FORMAT); const DATETIME_KEYS = Object.keys(DATETIME_FORMAT);
const DATE_KEYS = DATETIME_KEYS.filter( const DATE_KEYS = DATETIME_KEYS.filter(
key => key =>
@@ -81,7 +79,7 @@ export const has_valid_profile = (p = {}) =>
* @property {Object} shan_xing * @property {Object} shan_xing
* @property {Object} xiang_xing * @property {Object} xiang_xing
* @property {Function} update * @property {Function} update
* @property {FengShui.FengShuiContext.get_bagua_start_north} * @property {FengShui.FengShuiContext.get_gua_compass_order}
* @property {FengShui.FengShuiContext.get_direction_positions_in_chart} - NOT IN USE * @property {FengShui.FengShuiContext.get_direction_positions_in_chart} - NOT IN USE
* @property {FengShui.FengShuiContext.get_opposite_direction} - NOT IN USE * @property {FengShui.FengShuiContext.get_opposite_direction} - NOT IN USE
* @property {FengShui.FengShuiContext.get_twentyfour_direction_from_index} * @property {FengShui.FengShuiContext.get_twentyfour_direction_from_index}
@@ -107,7 +105,7 @@ const FengShuiContext = createContext({
update: noop, update: noop,
// 八卦 (Ba-Gua) // 八卦 (Ba-Gua)
get_bagua_start_north: noop, get_gua_compass_order: noop,
// 二十四山向 (Er-Shi Si-Shan Xiang) // 二十四山向 (Er-Shi Si-Shan Xiang)
get_twentyfour_direction_from_index: noop, get_twentyfour_direction_from_index: noop,
@@ -151,16 +149,16 @@ export const FengShuiProvider = props => {
/** /**
* A simple accessor for values stored in `BAGUA_START_NORTH`. * A simple accessor for values stored in `BAGUA_START_NORTH`.
* @typedef FengShui.FengShuiContext.get_bagua_start_north * @typedef FengShui.FengShuiContext.get_gua_compass_order
* @function * @function
*/ */
/** /**
* @type {FengShui.FengShuiContext.get_bagua_start_north} * @type {FengShui.FengShuiContext.get_gua_compass_order}
*/ */
const get_bagua_start_north = useCallback( const get_gua_compass_order = useCallback(
dir => { dir => {
return ready && wasm_get_bagua_start_north(dir); return ready && wasm_get_gua_compass_order(dir);
}, },
[ready] [ready]
); );
@@ -481,7 +479,7 @@ export const FengShuiProvider = props => {
shan_xing, shan_xing,
xiang_xing, xiang_xing,
update, update,
get_bagua_start_north, get_gua_compass_order,
get_twentyfour_direction_from_index, get_twentyfour_direction_from_index,
get_twentyfour_direction_from_degrees, get_twentyfour_direction_from_degrees,
get_twentyfour_data_from_index, get_twentyfour_data_from_index,
@@ -528,13 +526,9 @@ export const useFengShuiSync = () => {
if (p) { if (p) {
const t = p.localtime.format('YYYY-MM-DD'); const t = p.localtime.format('YYYY-MM-DD');
const dir = `${p.direction}${p.sector}`; const dir = `${p.direction}${p.sector}`;
// console.log(`[FengShuiContext] (useFengShuiSync) localtime: ${t}`);
// console.log(`[FengShuiContext] (useFengShuiSync) dir: ${dir}`);
setHasProfile(true); setHasProfile(true);
update(p); update(p);
} else { } else {
// console.log('[FengShuiContext] No valid profiles...');
setHasProfile(false); setHasProfile(false);
} }
}, [ready, profiles]); }, [ready, profiles]);

View File

@@ -31,7 +31,7 @@ const fix3 = fixed(3);
export const FengShuiBaguaInfo = () => { export const FengShuiBaguaInfo = () => {
const { worldInfo: world } = useWorld(); const { worldInfo: world } = useWorld();
const deviceOrientation = useDeviceOrientation(); const deviceOrientation = useDeviceOrientation();
const { ready, get_bagua_start_north } = useFengShui(); const { ready, get_gua_compass_order } = useFengShui();
const [boxes, setBoxes] = useState([]); const [boxes, setBoxes] = useState([]);
@@ -78,7 +78,7 @@ export const FengShuiBaguaInfo = () => {
if (ready) { if (ready) {
setBoxes( setBoxes(
[...new Array(8)].map((_, index) => { [...new Array(8)].map((_, index) => {
const bagua = get_bagua_start_north(index); const bagua = get_gua_compass_order(index);
const name = bagua?.name; const name = bagua?.name;
return name return name
? { ? {

View File

@@ -3,7 +3,7 @@ extern crate chrono;
use chrono::Datelike; use chrono::Datelike;
use chrono::naive::NaiveDate; use chrono::naive::NaiveDate;
use mikaboshi::bagua::{get_bagua_start_north as _bagua_start_north, Bagua}; use mikaboshi::bagua::{get_gua_compass_order as _gua_compass_order, Gua};
use mikaboshi::compass::{ use mikaboshi::compass::{
get_direction_positions_in_chart as _direction_positions_in_chart, get_direction_positions_in_chart as _direction_positions_in_chart,
get_opposite_direction as _opposite_direction, get_opposite_direction as _opposite_direction,
@@ -52,13 +52,13 @@ pub fn main() {
} }
// ================================================================ // ================================================================
// 八卦 (Bagua) // 八卦 (Gua)
// ================================================================ // ================================================================
#[wasm_bindgen] #[wasm_bindgen]
pub fn get_bagua_start_north(index: usize) -> JsValue { pub fn get_gua_compass_order(index: usize) -> JsValue {
let bagua: Option<&Bagua> = _bagua_start_north(index); let gua: Option<&Gua> = _gua_compass_order(index);
JsValue::from_serde(&bagua).unwrap() JsValue::from_serde(&gua).unwrap()
} }
// ================================================================ // ================================================================
@@ -97,7 +97,7 @@ pub fn get_twentyfour_direction_from_index(index: usize) -> JsValue {
pub fn get_twentyfour_data_from_index(index: usize) -> JsValue { pub fn get_twentyfour_data_from_index(index: usize) -> JsValue {
let t_type: TwentyFourType = _twentyfour_data_from_index(index); let t_type: TwentyFourType = _twentyfour_data_from_index(index);
match t_type { match t_type {
TwentyFourType::Bagua(bagua) => JsValue::from_serde(bagua).unwrap(), TwentyFourType::Gua(gua) => JsValue::from_serde(gua).unwrap(),
TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(), TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(),
TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(), TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(),
} }
@@ -113,7 +113,7 @@ pub fn get_twentyfour_direction_from_degrees(degrees: f32) -> JsValue {
pub fn get_twentyfour_data_from_direction(direction: &str, sector: usize) -> JsValue { pub fn get_twentyfour_data_from_direction(direction: &str, sector: usize) -> JsValue {
let t_type: TwentyFourType = _twentyfour_data_from_direction(direction, sector); let t_type: TwentyFourType = _twentyfour_data_from_direction(direction, sector);
match t_type { match t_type {
TwentyFourType::Bagua(bagua) => JsValue::from_serde(bagua).unwrap(), TwentyFourType::Gua(gua) => JsValue::from_serde(gua).unwrap(),
TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(), TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(),
TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(), TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(),
} }

View File

@@ -2,57 +2,53 @@
Source: [src/jiuxing.rs](../src/jiuxing.rs) Source: [src/jiuxing.rs](../src/jiuxing.rs)
At the beginning, the law governing the universe was simple. 九星 (Jiu-Xing) means "9 stars" in Chinese.
Yet, as man acquired the faculty of thought, was it no longer so. In 風水 (Feng-Shui), 9 boxes are drawn to represent
It was not the universe which changed, but was about how man began the spatial condition of the place in concern.
to see the universe differently. Thought, after all, is nothing The box in the middle represents where you are,
but reflections of the outer world. In another word, the outer and 8 boxes which surrounding the middle represent
world we perceive could only be understood via patterns 8 compass directions. For these 9 boxes, plotted
that are innate to man's thought. Just like "Malkuth" in _Kabbalha_ special symbols, each of which is called, a "Star" (星).
is about both the earthly kingdom and the man himself, When we say 九星 (Jiu-Xing) in Chinese, "Jiu" means "9",
as ancient Chinese attempted describing patterns in the universe, and "Xing" means a "Star". While 九星 (Jiu-Xing)
they introduced another artificial element "metal" has fixed positions (associated with 洛書 (Lo-Shu)),
(or "earth" when it is deployed in actual reality). they change positions over time, and this movement
For the ancient Chinese, the former is called is called 飞泊 (Fei-Po) or "flying" because of how it
先天八卦 ("the Primordial Heaven"), and the latter, appears to our eyes when they move.
後天八卦 ("the Manifested Heaven"). //!
To study the patterns peculiar to each universe, a conventional As explained in 八卦 (Ba-Gua) (see: `src/bagua.rs`),
board with 8 directions and 1 in the center has been in use, there are 2 worldly systems concerned, namely,
where "8 Gua" (八卦) are assigned for slots on the board. 先天八卦 (or "the Primordial Heaven") and
However, for many 風水 (Feng-Shui) systems, we are normally 後天八卦 (or "the Manifested Heaven"), and we deal
dealing with the latter, or 後天八卦 ("the Manifested Heaven"). with the latter system when we talk about 風水 (Feng-Shui).
For 後天八卦 ("the Manifested Heaven") has a specific name In 玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui), there is
in 玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui), and is called a special name given to the latter system, and is called,
地盤 (Di-Pan). However, there are 3 more boards in 地盤 (Di-Pan). "Di" means "earth", and "Pan" means "board".
玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui) So, it is basically a board which is drawn at the bottom
in addition to 地盤 (Di-Pan), namely: of any Feng-Shui charts. On 地盤 (Di-Pan), 九星 (Jiu-Xing)
are plotted for which the order is fundamentally that of
洛書 (Lo-Shu) order in 八卦 (Ba-Gua). However, they move
(or "fly") over 地盤 (Di-Pan) as time goes.
In 玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui), there are
3 other boards that are drawn on top of 地盤 (Di-Pan), namely:
(1) 運盤 (Un-Pan) (or 天盤 (Tien-Pan)) - 運盤 (Un-Pan) or 天盤 (Tien-Pan)
(2) 山星 (Shan-Xing) - 山星 (Shan-Xing)
(3) 向星 (Xiang-Xing) - 向星 (Xiang-Xing)
In practice, for all the above 3 boards, 九星 (Jiu-Xing) For 運盤 (Un-Pan), positions of 九星 (Jiu-Xing) are determined
or "the Nine Stars" are assigned. While "8 Gua" (八卦) by construction year for the building in concern which is
has fixed positions, 九星 (Jiu-Xing) changes calculated based on 三元九運 (Sang-Yuan Jiu-Yun),
over time for spatial constraints given.
When their positions change, the movement is called
飞泊 (Fei-Po) or "flying" because of how it appears
to our eyes when they move.
For the first board 運盤 (Un-Pan), positions of 九星 (Jiu-Xing)
are determined by building's construction year,
and calculated based on 三元九運 (Sang-Yuan Jiu-Yun)
or "9 Yearly Cycles". We could say that 運盤 (Un-Pan) or "9 Yearly Cycles". We could say that 運盤 (Un-Pan)
essentially describes of the temporal aspect of the building essentially describes the temporal aspect.
For 山星 (Shan-Xing) and 向星 (Xiang-Xing) are determined 山星 (Shan-Xing) and 向星 (Xiang-Xing) are determined
by spatial aspects of the building, though, temporal aspects by spatial aspects of the building (however, in actual
are also associated indirectly in calculations. calculations, some temporal aspects comes in).
When 運盤 (Un-Pan), 山星 (Shan-Xing), and 向星 (Xiang-Xing) When these 3 extra boards are placed on top of 地盤 (Di-Pan),
are added to 地盤 (Di-Pan) at the bottom, it is called the whole thing is called, 下卦図 (Xia-Gua-Tu), or simply
下卦図 (Xia-Gua-Tu), or simply referred as referred as 飞星図 (Fei-Xing-Tu), or "The Flying Star Chart".
飞星図 (Fei-Xing-Tu; "the Flying Star Chart").
Jiu-Xing (九星): Jiu-Xing (九星):

View File

@@ -1,6 +1,5 @@
[ [
{ {
"num": 1,
"name": { "name": {
"en": "kan", "en": "kan",
"zh_cn": ["坎", "kǎn"], "zh_cn": ["坎", "kǎn"],
@@ -8,11 +7,11 @@
"ja": ["かん", "kan"], "ja": ["かん", "kan"],
"vi": [] "vi": []
}, },
"jiuxing_num": 1,
"direction": "n", "direction": "n",
"element": 4 "element": 4
}, },
{ {
"num": 2,
"name": { "name": {
"en": "kun", "en": "kun",
"zh_cn": ["坤", "kūn"], "zh_cn": ["坤", "kūn"],
@@ -20,11 +19,11 @@
"ja": ["こん", "kon"], "ja": ["こん", "kon"],
"vi": [] "vi": []
}, },
"jiuxing_num": 2,
"direction": "sw", "direction": "sw",
"element": 2 "element": 2
}, },
{ {
"num": 3,
"name": { "name": {
"en": "zhen", "en": "zhen",
"zh_cn": ["震", "zhèn"], "zh_cn": ["震", "zhèn"],
@@ -32,11 +31,11 @@
"ja": ["しん", "shin"], "ja": ["しん", "shin"],
"vi": [] "vi": []
}, },
"jiuxing_num": 3,
"direction": "e", "direction": "e",
"element": 0 "element": 0
}, },
{ {
"num": 4,
"name": { "name": {
"en": "xun", "en": "xun",
"zh_cn": ["巽", "xùn"], "zh_cn": ["巽", "xùn"],
@@ -44,11 +43,11 @@
"ja": ["そん", "son"], "ja": ["そん", "son"],
"vi": [] "vi": []
}, },
"jiuxing_num": 4,
"direction": "se", "direction": "se",
"element": 0 "element": 0
}, },
{ {
"num": 5,
"name": { "name": {
"en": "zhong", "en": "zhong",
"zh_cn": ["中", "zhōng"], "zh_cn": ["中", "zhōng"],
@@ -56,11 +55,11 @@
"ja": ["中", "chu"], "ja": ["中", "chu"],
"vi": [] "vi": []
}, },
"jiuxing_num": 5,
"direction": "", "direction": "",
"element": 2 "element": 2
}, },
{ {
"num": 6,
"name": { "name": {
"en": "qian", "en": "qian",
"zh_cn": ["乾", "qián"], "zh_cn": ["乾", "qián"],
@@ -68,11 +67,11 @@
"ja": ["けん", "ken"], "ja": ["けん", "ken"],
"vi": [] "vi": []
}, },
"jiuxing_num": 6,
"direction": "nw", "direction": "nw",
"element": 3 "element": 3
}, },
{ {
"num": 7,
"name": { "name": {
"en": "dui", "en": "dui",
"zh_cn": ["兌", "duì"], "zh_cn": ["兌", "duì"],
@@ -80,11 +79,11 @@
"ja": ["だ", "da"], "ja": ["だ", "da"],
"vi": [] "vi": []
}, },
"jiuxing_num": 7,
"direction": "e", "direction": "e",
"element": 3 "element": 3
}, },
{ {
"num": 8,
"name": { "name": {
"en": "gen", "en": "gen",
"zh_cn": ["艮", "gèn"], "zh_cn": ["艮", "gèn"],
@@ -92,11 +91,11 @@
"ja": ["ごん", "gon"], "ja": ["ごん", "gon"],
"vi": [] "vi": []
}, },
"jiuxing_num": 8,
"direction": "ne", "direction": "ne",
"element": 2 "element": 2
}, },
{ {
"num": 9,
"name": { "name": {
"en": "li", "en": "li",
"zh_cn": ["離", "lí"], "zh_cn": ["離", "lí"],
@@ -104,6 +103,7 @@
"ja": ["り", "ri"], "ja": ["り", "ri"],
"vi": [] "vi": []
}, },
"jiuxing_num": 9,
"direction": "s", "direction": "s",
"element": 1 "element": 1
} }

View File

@@ -1,14 +1,43 @@
//! Although 八卦 (Ba-Gua) is a concept in 易経 (I-Ching), //! 八卦 (Ba-Gua) is a concept in 易経 (I-Ching) which is merely a concept
//! when used in Feng-Shui, it is often associated with 九星 (Jiu-Xing). //! in fortune telling, but also appears frequently in a variety of
//! While everthing in this world is (said to be) divided into either 陰 (Yin) //! Chinese philosophy. "Gua" (卦) is a conventional unit which characterizes
//! or 陽 (Yang), each could be further divided into lesser Yin and Yang. //! certain aspects/qualities in life. "Ba" simply means "8" in Chinese.
//! For Yang, some may be abundant in Yang. Or, some may slightly lean toward Yin. //! So, "Ba-Gua" (八卦) tells that it consists of 8 卦 (Gua). To the eyes of
//! This goes for Yin as well. Here, the initial Yin and Yang, //! ancient Chinese, everything in this world was of either 陰 (Yin) or 陽 (Yang).
//! now divided into 4, or becomes 4 patterns. Then, for each, //! Or, you could say, the world is divided into 2. However, if you observe
//! there are further divisions, and for this time, it now makes it 8 patterns. //! more carefully, you notice some in Yang may slightly lean toward Yin, and
//! Ancient Chinese had a specific term for these 8 patterns, //! some in Yin toward Yang. So, you could probably have another division there,
//! and it is called, 八卦 (Ba-Gua), or "8 Gua". //! for this time, divisions of 4. For greater Yang, you have lesser "Yin"
//! //! and "Yang", or you may call them, "Yang-Yang" and "Yang-Yin". Likewise,
//! for Yin, you will have "Yin-Yang" and "Yin-Yin". If you are brave enough,
//! you could repeat the process for the one last time. This time, you would
//! divide the world into 8. For ancient Chinese perceived the last division
//! of 8 being the basic building blocks for observing nature, and called
//! them, 八卦 (Ba-Gua)
//!
//! Now, when we say 八卦 (Ba-Gua), we usually refer to 2 different systems.
//! For the division just described above is called "先天八卦" (or
//! _"The Primordial Heaven"_), and a diagram to represent this order
//! is called "河圖" (He-Tu) (or 伏羲八卦 (Fu-Xi Ba-Gua)). Another one
//! is called "後天八卦" (or _"The Manifested Heaven"_), and its diagram
//! is called "洛書" (Lo-Shu) (or 文王八卦 (King Wen Ba-Gua)).
//! For the former illustrates the world of the original heaven,
//! and the latter, the manifested world (for which elements in nature
//! play active roles to produce gross material plane of our reality).
//!
//! Order of 河圖 (He-Tu) (for 先天八卦 _"The Primordial Heaven"_)
//!
//! [0] 乾 (Qian)
//! [1] 兌 (Dui)
//! [2] 離 (Li)
//! [3] 震 (Zhen)
//! [4] 巽 (Xun)
//! [5] 坎 (Kan)
//! [6] 坤 (Kun)
//! [7] 艮 (Gen)
//!
//! Order of 洛書 (Lo-Shu) (for 後天八卦 _"The Manifested Heaven"_)
//!
//! [0] 坎 (Kan) //! [0] 坎 (Kan)
//! [1] 坤 (Kun) //! [1] 坤 (Kun)
//! [2] 震 (Zhen) //! [2] 震 (Zhen)
@@ -17,6 +46,32 @@
//! [5] 兌 (Dui) //! [5] 兌 (Dui)
//! [6] 艮 (Gen) //! [6] 艮 (Gen)
//! [7] 離 (Li) //! [7] 離 (Li)
//!
//! So, when we talk about 八卦 (Ba-Gua), we need to be specific about
//! which world we referring to. As you can see, there are 3 sets
//! of vectors defined in this program, namely:
//!
//! - `BAGUA_HE_TU_ORDER`
//! - `BAGUA_LO_SHU_ORDER`
//! - `BAGUA_LO_SHU_ORDER_WITH_CENTER`
//!
//! Notice that the first 2 consists of 8 items, but the third one
//! consists of 9. When using 八卦 (Ba-Gua) for Feng-Shui, we usually
//! refer to 洛書 (Lo-Shu) diagram (which is `BAGUA_LO_SHU_ORDER`).
//! However, we usually plot 洛書 (Lo-Shu) into 9 boxes because it is
//! often associated with 九星 (Jiu-Xing) which requires not only
//! 8 compass directions, but with an extra box in the middle.
//! So, in addition to 八卦 (Ba-Gua), when managing 洛書 (Lo-Shu)
//! for Feng-Shui, we need CENTER (or "中" (Zhong) in Chinese),
//! and that is what we have for `BAGUA_LO_SHU_ORDER_WITH_CENTER`.
//!
//! Also, notice of another vector defined in the program, namely,
//! `BAGUA_LO_SHU_COMPASS_ORDER`. This is a special vector for which
//! the order is _conceptually_ in "Lo-Shu" order, however, mapped
//! to 8 compass directions as each 卦 (Gua) plotted in clockwise manner.
//! This is specially useful when we have an app with a compass UI
//! because you can directly plot 卦 (Gua) out of this vector.
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::language::{ use crate::language::{
@@ -33,117 +88,151 @@ use crate::utils::{
/// A struct representing 卦 (Gua) and stores its attributes. /// A struct representing 卦 (Gua) and stores its attributes.
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bagua { pub struct Gua {
pub num: u8,
pub name: Language, pub name: Language,
pub jiuxing_num: u8,
pub direction: String, pub direction: String,
pub element: u8, pub element: u8,
} }
/// A temporary struct for loading JSON data when defining a static const `BAGUA`. /// A temporary struct for loading JSON data when defining
/// a various vectors for 八卦 (Ba-Gua).
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BaguaRawData { pub struct GuaRaw {
pub num: u8,
pub name: LanguageData, pub name: LanguageData,
pub jiuxing_num: u8,
pub direction: String, pub direction: String,
pub element: u8, pub element: u8,
} }
impl LanguageTrait for Bagua { impl LanguageTrait for Gua {
fn name(&self) -> Box<Language> { fn name(&self) -> Box<Language> {
Box::new(self.name.clone()) Box::new(self.name.clone())
} }
} }
impl NameDataTrait for BaguaRawData { impl NameDataTrait for GuaRaw {
fn name(&self) -> Box<LanguageData> { fn name(&self) -> Box<LanguageData> {
Box::new(self.name.clone()) Box::new(self.name.clone())
} }
} }
lazy_static! { lazy_static! {
/// A static vector with 9 items, each represents 卦 (Gua) of 八卦 (Ba-Gua), /// This is a vector for 八卦 (Ba-Gua) with 9 items where the 5th item
/// or what known as "Eight Trigrams". Each stores associated attributes /// being "中" (Zhong). By having 9 items instead of 8, it can be
/// for the 卦 (Gua), and are in the order of Ba-Gua Numbers. For instance, /// directly mapped to 9 stars of 九星 (Jiu-Xing). Since 九星 (Jiu-Xing)
/// 坎 (Kan) is the first in Ba-Gua, so it comes first in the vector. /// is mapped in "Lo-Shu" (洛書) order, so is this vector.
/// However, be careful when you refer to each 卦 (Gua) as the program /// Check out the attribute `jiuxing_num` for each data, and you will
/// refers 卦 (Gua) not by Ba-Gua Numbers, but by vector indexes. /// notice it corresponds to the Jiu-Xing number.
/// For 坎 (Kan), for instance, while it has the Ba-Gua Number of 1,
/// it is referred as 0 because that is the index is for 坎 (Kan).
/// ///
/// [0] 坎 (1 = Kan) /// 八卦 (Ba-Gua) in "Lo-Shu" (洛書) order with 中 (Zhong) in the middle:
/// [1] 坤 (2 = Kun) ///
/// [2] (3 = Zhen) /// [0] (Kan) -> No. 1
/// [3] (4 = Xun) /// [1] (Kun) -> No. 2
/// [4] (5 = Zhong) /// [2] (Zhen) -> No. 3
/// [5] (6 = Qian) /// [3] (Xun) -> No. 4
/// [6] (7 = Dui) /// [4] (Zhong) -> No. 5
/// [7] (8 = Gen) /// [5] (Qian) -> No. 6
/// [8] (9 = Li) /// [6] (Dui) -> No. 7
/// [7] 艮 (Gen) -> No. 8
/// [8] 離 (Li) -> No. 9
/// ///
/// For attributes details stored in the vector is found in JSON file: /// For attributes details stored in the vector is found in JSON file:
/// `src/json/bagua.json` /// `src/json/bagua.json`
pub static ref BAGUA: Vec<Bagua> = { pub static ref BAGUA_LO_SHU_ORDER_WITH_CENTER: Vec<Gua> = {
let json = &include_str!("../json/bagua.json"); let json = &include_str!("../json/bagua.json");
let data: Vec<BaguaRawData> = get_json::<BaguaRawData>(json); let data: Vec<GuaRaw> = get_json::<GuaRaw>(json);
data.iter().map(|item| { data.iter().map(|item| {
let item = item.clone(); let item = item.clone();
Bagua { Gua {
num: item.num,
name: item.language_from_data(), name: item.language_from_data(),
direction: item.direction, direction: item.direction,
jiuxing_num: item.jiuxing_num,
element: item.element, element: item.element,
} }
}).collect() }).collect()
}; };
/// Another static vector for 八卦 (Ba-Gua) (and is `Vec<u8>`). /// [INDEX] 八卦 (Ba-Gua) in "He-Tu" (河圖) order.
/// However, this time, it has only 8 items because this is used pub static ref BAGUA_HE_TU_ORDER_INDEXES: Vec<u8> = vec![0, 1, 2, 3, 5, 6, 7, 8];
/// for compass rotation. When using a compass, only 8 directions matter,
/// and the middle does not mean anything. When 八卦 (Ba-Gua) are
/// placed in 洛書 (Lo-Shu) order, 中 (Zhong) comes in the middle.
/// So, 中 (Zhong) is missing for this vector. For 八卦 (Ba-Gua),
/// it begins with 坎 (Kan) which resides in the north
/// when they are placed in Lo-Shu order. Moving clockwise,
/// what you see next in the north-east, is 艮 (Gen).
/// Then, comes 震 (3 = Zhen) which is in the east, and, so on.
/// Note that it is `Vec<u8>`, and not `Vec<Bagua>`.
///
/// [0] 坎 (1 = Kan)
/// [1] 艮 (8 = Gen)
/// [2] 震 (3 = Zhen)
/// [3] 巽 (4 = Xun)
/// [4] 離 (9 = Li)
/// [5] 坤 (2 = Kun)
/// [6] 兌 (7 = Dui)
/// [7] 乾 (6 = Qian)
pub static ref BAGUA_START_NORTH_INDEXES: Vec<u8> = vec![0, 7, 2, 3, 8, 1, 6, 5];
/// The order is the same as `BAGUA_START_NORTH_INDEXES`, /// [ACTUAL DATA] 八卦 (Ba-Gua) in "He-Tu" (河圖) order.
/// however, it is not `Vec<u8>` but `Vec<Bagua>` for this time. ///
pub static ref BAGUA_START_NORTH: Vec<Bagua> = make_sort( /// [0] 乾 (Qian)
BAGUA_START_NORTH_INDEXES.to_vec() /// [1] 兌 (Dui)
/// [2] 離 (Li)
/// [3] 震 (Zhen)
/// [4] 巽 (Xun)
/// [5] 坎 (Kan)
/// [6] 坤 (Kun)
/// [7] 艮 (Gen)
pub static ref BAGUA_HE_TU_ORDER: Vec<Gua> = make_sort(
BAGUA_HE_TU_ORDER_INDEXES.to_vec() // order
)( )(
BAGUA.to_vec() BAGUA_LO_SHU_ORDER_WITH_CENTER.to_vec() // data source
);
/// [INDEX] 八卦 (Ba-Gua) in "Lo-Shu" (洛書) order.
pub static ref BAGUA_LO_SHU_ORDER_INDEXES: Vec<u8> = vec![0, 1, 2, 3, 5, 6, 7, 8];
/// [ACTUAL DATA] 八卦 (Ba-Gua) in "Lo-Shu" (洛書) order.
///
/// [0] 坎 (Kan)
/// [1] 艮 (Gen)
/// [2] 震 (Zhen)
/// [3] 巽 (Xun)
/// [4] 離 (Li)
/// [5] 坤 (Kun)
/// [6] 兌 (Dui)
/// [7] 乾 (Qian)
pub static ref BAGUA_LO_SHU_ORDER: Vec<Gua> = make_sort(
BAGUA_LO_SHU_ORDER_INDEXES.to_vec() // order
)(
BAGUA_LO_SHU_ORDER_WITH_CENTER.to_vec() // data source
);
/// [INDEX] 八卦 (Ba-Gua) in "Lo-Shu" order, however, mapped to 8 compass directions.
pub static ref BAGUA_LO_SHU_COMPASS_ORDER_INDEXES: Vec<u8> = vec![0, 7, 2, 3, 8, 1, 6, 5];
/// [ACTUAL DATA] 八卦 (Ba-Gua) in "Lo-Shu" order, however, mapped to 8 compass directions.
/// When "Lo-Shu" (洛書) order is mapped to 8 compass directions, it is convenient
/// to have a vector which starts with 卦 (Gua) for _"NORTH"_ which is "坎" (Kan).
/// Likewise, we want the second item being 卦 (Gua) for _"NORTH EAST"_ which is "艮" (Gen).
/// For the third item, likewise, for _"EAST"_ or "震" (Zhen).
///
/// 八卦 (Ba-Gua) in "Lo-Shu" order mapped to 8 directions (starting NORTH):
///
/// [0] 坎 (Kan)
/// [1] 艮 (Gen)
/// [2] 震 (Zhen)
/// [3] 巽 (Xun)
/// [4] 離 (Li)
/// [5] 坤 (Kun)
/// [6] 兌 (Dui)
/// [7] 乾 (Qian)
pub static ref BAGUA_LO_SHU_COMPASS_ORDER: Vec<Gua> = make_sort(
BAGUA_LO_SHU_COMPASS_ORDER_INDEXES.to_vec() // order
)(
BAGUA_LO_SHU_ORDER_WITH_CENTER.to_vec() // data source
); );
} }
/// A getter for `BAGUA_START_NORTH`. /// A getter for `BAGUA_LO_SHU_COMPASS_ORDER`.
/// ///
/// Example: /// Example:
/// ```rust /// ```rust
/// use mikaboshi::bagua::{get_bagua_start_north, Bagua}; /// use mikaboshi::bagua::{get_gua_compass_order, Gua};
/// use wasm_bindgen::prelude::*; /// use wasm_bindgen::prelude::*;
/// ///
/// #[wasm_bindgen] /// #[wasm_bindgen]
/// pub fn xx(index: usize) -> JsValue { /// pub fn xx(index: usize) -> JsValue {
/// let bagua: Option<&Bagua> = get_bagua_start_north(index); /// let gua: Option<&Gua> = get_gua_compass_order(index);
/// JsValue::from_serde(&bagua).unwrap() /// JsValue::from_serde(&gua).unwrap()
/// } /// }
/// ``` /// ```
pub fn get_bagua_start_north(index: usize) -> Option<&'static Bagua> { pub fn get_gua_compass_order(index: usize) -> Option<&'static Gua> {
match BAGUA_START_NORTH.get(index) { match BAGUA_LO_SHU_COMPASS_ORDER.get(index) {
Some(bagua) => Some(bagua), Some(gua) => Some(gua),
None => None, None => None,
} }
} }
@@ -153,11 +242,11 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_constant_bagua() { fn test_constant_bagua_list_full() {
assert_eq!(BAGUA[0].num, 1); assert_eq!(BAGUA_LO_SHU_ORDER_WITH_CENTER[0].jiuxing_num, 1);
} }
// TODO: BAGUA_START_NORTH_INDEXES // TODO: BAGUA_LO_SHU_COMPASS_ORDER_INDEXES
// TODO: BAGUA_START_NORTH // TODO: BAGUA_LO_SHU_COMPASS_ORDER
// TODO: get_get_bagua_start_north // TODO: gua_for_start_north
} }

View File

@@ -7,7 +7,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use crate::bagua::{Bagua, BAGUA}; use crate::bagua::{Gua, BAGUA_LO_SHU_ORDER_WITH_CENTER};
use crate::ganzhi::{ use crate::ganzhi::{
Branch, Branch,
Stem, Stem,
@@ -18,7 +18,7 @@ use crate::ganzhi::{
/// 二十四山向 (Er-Shi-Si Shan-Xiang) can be /// 二十四山向 (Er-Shi-Si Shan-Xiang) can be
/// either 卦 (Gua), 干 (Gan), or 支 (Zhi). /// either 卦 (Gua), 干 (Gan), or 支 (Zhi).
pub enum TwentyFourType<'a> { pub enum TwentyFourType<'a> {
Bagua(&'a Bagua), Gua(&'a Gua),
Stem(&'a Stem), Stem(&'a Stem),
Branch(&'a Branch), Branch(&'a Branch),
} }
@@ -287,7 +287,7 @@ pub const TWENTYFOUR_ORDER_START_NORTH: [(usize, usize); 24] = [
/// pub fn xx(index: usize) -> JsValue { /// pub fn xx(index: usize) -> JsValue {
/// let t_type: TwentyFourType = get_twentyfour_data_from_index(index); /// let t_type: TwentyFourType = get_twentyfour_data_from_index(index);
/// match t_type { /// match t_type {
/// TwentyFourType::Bagua(bagua) => JsValue::from_serde(bagua).unwrap(), /// TwentyFourType::Gua(gua) => JsValue::from_serde(gua).unwrap(),
/// TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(), /// TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(),
/// TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(), /// TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(),
/// } /// }
@@ -296,7 +296,7 @@ pub const TWENTYFOUR_ORDER_START_NORTH: [(usize, usize); 24] = [
pub fn get_twentyfour_data_from_index(index: usize) -> TwentyFourType<'static> { pub fn get_twentyfour_data_from_index(index: usize) -> TwentyFourType<'static> {
let (t_type, t_index) = TWENTYFOUR_ORDER_START_NORTH[index]; let (t_type, t_index) = TWENTYFOUR_ORDER_START_NORTH[index];
match t_type { match t_type {
0 => TwentyFourType::Bagua(&BAGUA[t_index]), 0 => TwentyFourType::Gua(&BAGUA_LO_SHU_ORDER_WITH_CENTER[t_index]),
1 => TwentyFourType::Stem(&STEMS[t_index]), 1 => TwentyFourType::Stem(&STEMS[t_index]),
2 => TwentyFourType::Branch(&BRANCHES[t_index]), 2 => TwentyFourType::Branch(&BRANCHES[t_index]),
_ => panic!("Unknown type: {}", t_type), _ => panic!("Unknown type: {}", t_type),
@@ -397,7 +397,7 @@ pub fn get_twentyfour_index_from_direction(direction: &str, sector: usize) -> us
/// pub fn xx(direction: &str, sector: usize) -> JsValue { /// pub fn xx(direction: &str, sector: usize) -> JsValue {
/// let t_type: TwentyFourType = get_twentyfour_data_from_direction(direction, sector); /// let t_type: TwentyFourType = get_twentyfour_data_from_direction(direction, sector);
/// match t_type { /// match t_type {
/// TwentyFourType::Bagua(bagua) => JsValue::from_serde(bagua).unwrap(), /// TwentyFourType::Gua(gua) => JsValue::from_serde(gua).unwrap(),
/// TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(), /// TwentyFourType::Stem(stem) => JsValue::from_serde(stem).unwrap(),
/// TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(), /// TwentyFourType::Branch(branch) => JsValue::from_serde(branch).unwrap(),
/// } /// }

View File

@@ -1,54 +1,50 @@
//! At the beginning, the law governing the universe was simple. //! 九星 (Jiu-Xing) means "9 stars" in Chinese.
//! Yet, as man acquired the faculty of thought, was it no longer so. //! In 風水 (Feng-Shui), 9 boxes are drawn to represent
//! It was not the universe which changed, but was about how man began //! the spatial condition of the place in concern.
//! to see the universe differently. Thought, after all, is nothing //! The box in the middle represents where you are,
//! but reflections of the outer world. In another word, the outer //! and 8 boxes which surrounding the middle represent
//! world we perceive could only be understood via patterns //! 8 compass directions. For these 9 boxes, plotted
//! that are innate to man's thought. Just like "Malkuth" in _Kabbalha_ //! special symbols, each of which is called, a "Star" (星).
//! is about both the earthly kingdom and the man himself, //! When we say 九星 (Jiu-Xing) in Chinese, "Jiu" means "9",
//! as ancient Chinese attempted describing patterns in the universe, //! and "Xing" means a "Star". While 九星 (Jiu-Xing)
//! they introduced another artificial element "metal" //! has fixed positions (associated with 洛書 (Lo-Shu)),
//! (or "earth" when it is deployed in actual reality). //! they change positions over time, and this movement
//! For the ancient Chinese, the former is called //! is called 飞泊 (Fei-Po) or "flying" because of how it
//! 先天八卦 ("the Primordial Heaven"), and the latter, //! appears to our eyes when they move.
//! 後天八卦 ("the Manifested Heaven").
//! To study the patterns peculiar to each universe, a conventional
//! board with 8 directions and 1 in the center has been in use,
//! where "8 Gua" (八卦) are assigned for slots on the board.
//! However, for many 風水 (Feng-Shui) systems, we are normally
//! dealing with the latter, or 後天八卦 ("the Manifested Heaven").
//! //!
//! For 後天八卦 ("the Manifested Heaven") has a specific name //! As explained in 八卦 (Ba-Gua) (see: `src/bagua.rs`),
//! in 玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui), and is called //! there are 2 worldly systems concerned, namely,
//! 地盤 (Di-Pan). However, there are 3 more boards in //! 先天八卦 (or "the Primordial Heaven") and
//! 玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui) //! 後天八卦 (or "the Manifested Heaven"), and we deal
//! in addition to 地盤 (Di-Pan), namely: //! with the latter system when we talk about 風水 (Feng-Shui).
//! //!
//! (1) 運盤 (Un-Pan) (or 天盤 (Tien-Pan)) //! In 玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui), there is
//! (2) 山星 (Shan-Xing) //! a special name given to the latter system, and is called,
//! (3) 向星 (Xiang-Xing) //! 地盤 (Di-Pan). "Di" means "earth", and "Pan" means "board".
//! So, it is basically a board which is drawn at the bottom
//! of any Feng-Shui charts. On 地盤 (Di-Pan), 九星 (Jiu-Xing)
//! are plotted for which the order is fundamentally that of
//! 洛書 (Lo-Shu) order in 八卦 (Ba-Gua). However, they move
//! (or "fly") over 地盤 (Di-Pan) as time goes.
//! In 玄空飞星風水 (Xuan-Kong Fei-Xing Feng-Shui), there are
//! 3 other boards that are drawn on top of 地盤 (Di-Pan), namely:
//!
//! - 運盤 (Un-Pan) or 天盤 (Tien-Pan)
//! - 山星 (Shan-Xing)
//! - 向星 (Xiang-Xing)
//! //!
//! In practice, for all the above 3 boards, 九星 (Jiu-Xing) //! For 運盤 (Un-Pan), positions of 九星 (Jiu-Xing) are determined
//! or "the Nine Stars" are assigned. While "8 Gua" (八卦) //! by construction year for the building in concern which is
//! has fixed positions, 九星 (Jiu-Xing) changes //! calculated based on 三元九運 (Sang-Yuan Jiu-Yun),
//! over time for spatial constraints given.
//! When their positions change, the movement is called
//! 飞泊 (Fei-Po) or "flying" because of how it appears
//! to our eyes when they move.
//!
//! For the first board 運盤 (Un-Pan), positions of 九星 (Jiu-Xing)
//! are determined by building's construction year,
//! and calculated based on 三元九運 (Sang-Yuan Jiu-Yun)
//! or "9 Yearly Cycles". We could say that 運盤 (Un-Pan) //! or "9 Yearly Cycles". We could say that 運盤 (Un-Pan)
//! essentially describes of the temporal aspect of the building //! essentially describes the temporal aspect.
//! For 山星 (Shan-Xing) and 向星 (Xiang-Xing) are determined //! 山星 (Shan-Xing) and 向星 (Xiang-Xing) are determined
//! by spatial aspects of the building, though, temporal aspects //! by spatial aspects of the building (however, in actual
//! are also associated indirectly in calculations. //! calculations, some temporal aspects comes in).
//! //!
//! When 運盤 (Un-Pan), 山星 (Shan-Xing), and 向星 (Xiang-Xing) //! When these 3 extra boards are placed on top of 地盤 (Di-Pan),
//! are added to 地盤 (Di-Pan) at the bottom, it is called //! the whole thing is called, 下卦図 (Xia-Gua-Tu), or simply
//! 下卦図 (Xia-Gua-Tu), or simply referred as //! referred as 飞星図 (Fei-Xing-Tu), or "The Flying Star Chart".
//! 飞星図 (Fei-Xing-Tu; "the Flying Star Chart").
//! //!
//! Jiu-Xing (九星): //! Jiu-Xing (九星):
//! //!

View File

@@ -1,5 +1,6 @@
//! A module for "二十四节气" (Er-Shi-Si Jie-Qi). //! A module for 二十四节气 (Er-Shi-Si Jie-Qi).
//! Or, for calculating "立春" (Li-Chun). //! Or, for calculating 立春 (Li-Chun).
use chrono::Datelike; use chrono::Datelike;
use chrono::naive::NaiveDate; use chrono::naive::NaiveDate;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};