-
Notifications
You must be signed in to change notification settings - Fork 40
#702 Enhance branch layout for SHMetro 2020 style #775
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
Open
Unnamed2964
wants to merge
4
commits into
railmapgen:main
Choose a base branch
from
Unnamed2964:fix/shmetro-2020-branch-drawing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
edb5597
#702 Add branch layout fine-tuning controls for SHMetro 2020 style
Unnamed2964 19990cd
Fix branch turn offset direction for both train directions
Unnamed2964 d59dd4f
fix(shmetro): color parallel branch stations and fix terminal caps
Unnamed2964 7673099
feat(shmetro): add branch bend type and align endpoints options
Unnamed2964 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { drawLine, getStnState } from './share'; | ||
|
|
||
| // Diamond topology used in getStnState tests: | ||
| // | ||
| // C -- D | ||
| // / \ | ||
| // A -- B E -- F | ||
| // \ / | ||
| // G -- H | ||
| // | ||
| // routes[0]: linestart → A → B → C → D → E → F → lineend | ||
| // routes[1]: linestart → A → B → G → H → E → F → lineend | ||
|
|
||
| const TWO_BRANCH_ROUTES: string[][] = [ | ||
| ['linestart', 'A', 'B', 'C', 'D', 'E', 'F', 'lineend'], | ||
| ['linestart', 'A', 'B', 'G', 'H', 'E', 'F', 'lineend'], | ||
| ]; | ||
|
|
||
| // Dead-end topology: | ||
| // | ||
| // <-- a ---| | ||
| // c --- d ---- | ||
| // <-- b ---| | ||
|
|
||
| const DEAD_END_ROUTES: string[][] = [ | ||
| ['linestart', 'b', 'c', 'd', 'lineend'], | ||
| ['linestart', 'a', 'c', 'd', 'lineend'], | ||
| ]; | ||
|
|
||
| describe('getStnState', () => { | ||
| it('Can calculate states on simple line (direction r)', () => { | ||
| const routes = [['linestart', 'A', 'B', 'C', 'lineend']]; | ||
| const states = getStnState('B', routes, 'r'); | ||
| expect(states['A']).toBe(-1); | ||
| expect(states['B']).toBe(0); | ||
| expect(states['C']).toBe(1); | ||
| }); | ||
|
|
||
| it('Can calculate states on simple line (direction l)', () => { | ||
| const routes = [['linestart', 'A', 'B', 'C', 'lineend']]; | ||
| const states = getStnState('B', routes, 'l'); | ||
| expect(states['A']).toBe(1); | ||
| expect(states['B']).toBe(0); | ||
| expect(states['C']).toBe(-1); | ||
| }); | ||
|
|
||
| it('Can promote parallel branch when current is on sibling branch (direction r)', () => { | ||
| const states = getStnState('D', TWO_BRANCH_ROUTES, 'r'); | ||
| expect(states['B']).toBe(-1); | ||
| expect(states['C']).toBe(-1); | ||
| expect(states['D']).toBe(0); | ||
| expect(states['E']).toBe(1); | ||
| expect(states['G']).toBe(1); | ||
| expect(states['H']).toBe(1); | ||
| }); | ||
|
|
||
| it('Can promote parallel branch when current is on sibling branch (direction l)', () => { | ||
| const states = getStnState('D', TWO_BRANCH_ROUTES, 'l'); | ||
| expect(states['B']).toBe(1); | ||
| expect(states['C']).toBe(1); | ||
| expect(states['D']).toBe(0); | ||
| expect(states['E']).toBe(-1); | ||
| expect(states['G']).toBe(1); | ||
| expect(states['H']).toBe(1); | ||
| }); | ||
|
|
||
| it('Can calculate states at bifurcation point — both branches ahead', () => { | ||
| const states = getStnState('B', TWO_BRANCH_ROUTES, 'r'); | ||
| expect(states['A']).toBe(-1); | ||
| expect(states['B']).toBe(0); | ||
| expect(states['C']).toBe(1); | ||
| expect(states['D']).toBe(1); | ||
| expect(states['E']).toBe(1); | ||
| expect(states['F']).toBe(1); | ||
| expect(states['G']).toBe(1); | ||
| expect(states['H']).toBe(1); | ||
| }); | ||
|
|
||
| it('Can calculate states at merge point — both branches behind', () => { | ||
| const states = getStnState('E', TWO_BRANCH_ROUTES, 'r'); | ||
| expect(states['A']).toBe(-1); | ||
| expect(states['B']).toBe(-1); | ||
| expect(states['C']).toBe(-1); | ||
| expect(states['D']).toBe(-1); | ||
| expect(states['E']).toBe(0); | ||
| expect(states['F']).toBe(1); | ||
| expect(states['G']).toBe(-1); | ||
| expect(states['H']).toBe(-1); | ||
| }); | ||
|
|
||
| it('Does not promote dead-end parallel branch when junction is behind current', () => { | ||
| const states = getStnState('a', DEAD_END_ROUTES, 'l'); | ||
| expect(states['a']).toBe(0); | ||
| expect(states['c']).toBe(-1); | ||
| expect(states['d']).toBe(-1); | ||
| expect(states['b']).toBe(-1); | ||
| }); | ||
|
|
||
| it('Can promote dead-end parallel branch when junction is ahead of current', () => { | ||
| const states = getStnState('a', DEAD_END_ROUTES, 'r'); | ||
| expect(states['a']).toBe(0); | ||
| expect(states['c']).toBe(1); | ||
| expect(states['d']).toBe(1); | ||
| expect(states['b']).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('drawLine', () => { | ||
| it('Can color promoted parallel branch stations', () => { | ||
| const stnStates: { [k: string]: -1 | 0 | 1 } = { B: -1, G: 1, H: 1, E: 1 }; | ||
| const { main, pass } = drawLine(['linestart', 'B', 'G', 'H', 'E', 'lineend'], stnStates); | ||
| expect(main).toContain('G'); | ||
| expect(main).toContain('H'); | ||
| expect(main).toContain('E'); | ||
| expect(pass).toContain('B'); | ||
| }); | ||
|
|
||
| it('Does not generate gray stub when entire branch is state=1', () => { | ||
| const stnStates: { [k: string]: -1 | 0 | 1 } = { X: 1, Y: 1, Z: 1 }; | ||
| const { main, pass } = drawLine(['linestart', 'X', 'Y', 'Z', 'lineend'], stnStates); | ||
| expect(main).toEqual(['X', 'Y', 'Z']); | ||
| expect(pass).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('Current station (state=0) appears in both main and pass as overlap point', () => { | ||
| const stnStates: { [k: string]: -1 | 0 | 1 } = { B: -1, G: 0, H: 1, E: 1 }; | ||
| const { main, pass } = drawLine(['linestart', 'B', 'G', 'H', 'E', 'lineend'], stnStates); | ||
| expect(pass).toContain('B'); | ||
| expect(pass).toContain('G'); | ||
| expect(main).toContain('G'); | ||
| expect(main).toContain('H'); | ||
| expect(main).toContain('E'); | ||
| }); | ||
|
|
||
| it('Returns empty main and full pass when entire branch is state=-1', () => { | ||
| const stnStates: { [k: string]: -1 | 0 | 1 } = { B: -1, G: -1, H: -1, E: -1 }; | ||
| const { main, pass } = drawLine(['linestart', 'B', 'G', 'H', 'E', 'lineend'], stnStates); | ||
| expect(main).toHaveLength(0); | ||
| expect(pass).toEqual(['B', 'G', 'H', 'E']); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通常来说我们希望所有的属性都是通用的,虽然可能现在非2020及其他风格不会用到对应的数据,但正像我们在loop中实现的那样(比如bank),尽可能地通用这些属性值和名,以便后续使用
另外它也应该和branchSpacingPct一起被整合在branch键下