-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48daefe
commit 6780155
Showing
21 changed files
with
1,769 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,24 +1,24 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', {targets: {node: 'current'}} | ||
], | ||
['@babel/preset-env', { targets: { node: 'current' } }], | ||
'@babel/preset-typescript', | ||
], | ||
"plugins": [ | ||
plugins: [ | ||
[ | ||
"@babel/plugin-transform-react-jsx", | ||
'@babel/plugin-transform-react-jsx', | ||
{ | ||
"pragma": "h" | ||
} | ||
], | ||
[ | ||
"@babel/plugin-proposal-decorators", | ||
{ "legacy": true } | ||
pragma: 'h', | ||
}, | ||
], | ||
[ | ||
"@babel/plugin-proposal-class-properties", | ||
'babel-plugin-jsx-pragmatic', | ||
{ | ||
module: 'preact', | ||
import: 'h', | ||
export: 'h', | ||
}, | ||
], | ||
] | ||
} | ||
|
||
['@babel/plugin-proposal-decorators', { legacy: true }], | ||
['@babel/plugin-proposal-class-properties'], | ||
], | ||
}; |
This file contains 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 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 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,118 @@ | ||
import { getCrossPointOfLine, isInSegment } from '../../src/algorithm/edge'; | ||
|
||
describe('algorithm/edge', () => { | ||
// one intersection | ||
test('one intersection', () => { | ||
const line1 = [ | ||
{ | ||
x: 0, | ||
y: 0, | ||
}, | ||
{ | ||
x: 10, | ||
y: 10, | ||
}, | ||
]; | ||
const line2 = [ | ||
{ | ||
x: 10, | ||
y: 0, | ||
}, | ||
{ | ||
x: 0, | ||
y: 10, | ||
}, | ||
]; | ||
expect( | ||
getCrossPointOfLine(line1[0], line1[1], line2[0], line2[1]), | ||
).toBeTruthy(); | ||
}); | ||
// multiple intersection | ||
test('multiple intersection', () => { | ||
const line1 = [ | ||
{ | ||
x: 0, | ||
y: 0, | ||
}, | ||
{ | ||
x: 10, | ||
y: 10, | ||
}, | ||
]; | ||
const line2 = [ | ||
{ | ||
x: 0, | ||
y: 0, | ||
}, | ||
{ | ||
x: 10, | ||
y: 10, | ||
}, | ||
]; | ||
expect( | ||
getCrossPointOfLine(line1[0], line1[1], line2[0], line2[1]), | ||
).toBeFalsy(); | ||
}); | ||
// no intersection | ||
test('intersection', () => { | ||
const line1 = [ | ||
{ | ||
x: 0, | ||
y: 0, | ||
}, | ||
{ | ||
x: 10, | ||
y: 10, | ||
}, | ||
]; | ||
const line2 = [ | ||
{ | ||
x: 10, | ||
y: 0, | ||
}, | ||
{ | ||
x: 20, | ||
y: 10, | ||
}, | ||
]; | ||
expect( | ||
getCrossPointOfLine(line1[0], line1[1], line2[0], line2[1]), | ||
).toBeFalsy(); | ||
}); | ||
|
||
test('in segment', () => { | ||
const point = { | ||
x: 0, | ||
y: 0, | ||
}; | ||
const line = [ | ||
{ | ||
x: -10, | ||
y: -10, | ||
}, | ||
{ | ||
x: 10, | ||
y: 10, | ||
}, | ||
]; | ||
expect(isInSegment(point, line[0], line[1])).toBeTruthy(); | ||
}); | ||
// not in segment | ||
test('not in segment', () => { | ||
const point = { | ||
x: 10, | ||
y: 0, | ||
}; | ||
const line = [ | ||
{ | ||
x: -10, | ||
y: -10, | ||
}, | ||
{ | ||
x: 10, | ||
y: 10, | ||
}, | ||
]; | ||
expect(isInSegment(point, line[0], line[1])).toBeFalsy(); | ||
}); | ||
}); |
This file contains 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,69 @@ | ||
import { getVerticalPointOfLine } from '../../src/algorithm'; | ||
|
||
describe('algorithm/index', () => { | ||
test('getVerticalPointOfLine', () => { | ||
const config1 = { | ||
start: { | ||
x: 0, | ||
y: 0, | ||
}, | ||
end: { | ||
x: 0, | ||
y: 10, | ||
}, | ||
offset: 3, | ||
verticalLength: 3, | ||
type: 'start', | ||
}; | ||
const config2 = { | ||
start: { | ||
x: 0, | ||
y: 0, | ||
}, | ||
end: { | ||
x: 10, | ||
y: 0, | ||
}, | ||
offset: 3, | ||
verticalLength: 3, | ||
type: 'end', | ||
}; | ||
const config3 = { | ||
start: { | ||
x: 10, | ||
y: 10, | ||
}, | ||
end: { | ||
x: 0, | ||
y: 0, | ||
}, | ||
offset: 3, | ||
verticalLength: 3, | ||
type: 'start', | ||
}; | ||
const config4 = { | ||
start: { | ||
x: 10, | ||
y: 10, | ||
}, | ||
end: { | ||
x: 0, | ||
y: 0, | ||
}, | ||
offset: 3, | ||
verticalLength: 3, | ||
type: 'end', | ||
}; | ||
const res1 = getVerticalPointOfLine(config1); | ||
expect(Math.abs(res1.leftX) - 5 < Number.EPSILON).toBeTruthy(); | ||
expect(Math.abs(res1.leftY) - 3 < Number.EPSILON).toBeTruthy(); | ||
expect(Math.abs(res1.rightX) - 5 < Number.EPSILON).toBeTruthy(); | ||
expect(Math.abs(res1.rightY) - 3 < Number.EPSILON).toBeTruthy(); | ||
|
||
const res2 = getVerticalPointOfLine(config2); | ||
expect(Math.abs(res2.leftX) - 7 < Number.EPSILON).toBeTruthy(); | ||
expect(Math.abs(res2.leftY) - 3 < Number.EPSILON).toBeTruthy(); | ||
expect(Math.abs(res2.rightX) - 7 < Number.EPSILON).toBeTruthy(); | ||
expect(Math.abs(res2.rightY) - 3 < Number.EPSILON).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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,43 @@ | ||
import { getEdgeOutline } from '../../src/algorithm/outline'; | ||
|
||
describe('algorithm/outline', () => { | ||
test('get edge outline', () => { | ||
const edge1 = { | ||
modelType: 'line-edge', | ||
startPoint: { | ||
x: 0, | ||
y: 0, | ||
}, | ||
endPoint: { | ||
x: 10, | ||
y: 10, | ||
}, | ||
}; | ||
expect(getEdgeOutline(edge1)).toEqual({ | ||
x: -5, | ||
y: -5, | ||
x1: 15, | ||
y1: 15, | ||
}); | ||
const edge2 = { | ||
modelType: 'polyline-edge', | ||
points: '0,0 10,10', | ||
}; | ||
expect(getEdgeOutline(edge2)).toEqual({ | ||
x: -4, | ||
y: -4, | ||
x1: 14, | ||
y1: 14, | ||
}); | ||
const edge3 = { | ||
modelType: 'bezier-edge', | ||
path: 'M 270 195C 370 195,305 290,405 290', | ||
}; | ||
expect(getEdgeOutline(edge3)).toEqual({ | ||
x: 266, | ||
y: 191, | ||
x1: 409, | ||
y1: 294, | ||
}); | ||
}); | ||
}); |
This file contains 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,22 @@ | ||
import EventEmitter from '../../src/event/eventEmitter'; | ||
|
||
describe('event/eventEmitter', () => { | ||
const em = new EventEmitter(); | ||
test('event emitter', () => { | ||
const fn = jest.fn(); | ||
em.on('test', fn); | ||
em.emit('test', { a: 1 }); | ||
expect(fn).toBeCalledWith({ a: 1 }); | ||
em.off('test', fn); | ||
em.emit('test', { a: 1 }); | ||
expect(fn).toBeCalledTimes(1); | ||
|
||
em.once('test1', fn); | ||
em.emit('test1', { a: 1 }); | ||
expect(fn).toBeCalledTimes(2); | ||
em.once('test1', fn); | ||
em.emit('test1', { a: 1 }); | ||
const test1Events = em.getEvents().test1; | ||
expect(test1Events).toBeUndefined(); | ||
}); | ||
}); |
This file contains 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,28 @@ | ||
import History from '../../src/history/History'; | ||
import EventEmitter from '../../src/event/eventEmitter'; | ||
|
||
describe('history', () => { | ||
const event = new EventEmitter(); | ||
const history = new History(event); | ||
expect(history).toBeDefined(); | ||
test('add', () => { | ||
history.add(1); | ||
expect(history.undos).toEqual([1]); | ||
expect(history.redos).toEqual([]); | ||
}); | ||
test('undo', () => { | ||
history.add(1); | ||
history.add(2); | ||
history.undo(); | ||
expect(history.undos).toEqual([]); | ||
expect(history.redos).toEqual([2]); | ||
}); | ||
test('redo', () => { | ||
history.add(1); | ||
history.add(2); | ||
history.undo(); | ||
history.redo(); | ||
expect(history.undos).toEqual([]); | ||
expect(history.redos).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.