-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from White-Dews/master
🚀v1.3.0 增加范围数字/直线路径/打组方法/IP地址验证
- Loading branch information
Showing
12 changed files
with
160 additions
and
9 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
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
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
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,41 @@ | ||
import { Vector2 } from '../lib/vertor2.js' | ||
/** | ||
* 生成 | ||
*/ | ||
export class Generate { | ||
/** 生成范围数字 例如 1 - 7) [1,2,3,4,5,6] or [7,6,5,4,3,2] | ||
* @param start | ||
* @param end | ||
* @param step | ||
*/ | ||
static rangeNumber(start: number, end: number, step = 1) { | ||
const nums = [] | ||
if (end > start) { | ||
for (let i = start; i < end; i += step) { | ||
nums.push(i) | ||
} | ||
} else { | ||
for (let i = start; i > end; i -= step) { | ||
nums.push(i) | ||
} | ||
} | ||
return nums | ||
} | ||
/** 通过一些坐标点生成直线路径 [start,...,end] | ||
*/ | ||
static straightLinePath(...points: Array<Vector2>) { | ||
let path: Vector2[] = [] | ||
for (let i = 1; i < points.length; i++) { | ||
const start = points[i - 1] | ||
const end = points[i] | ||
if (start.x === end.x) { | ||
path = path.concat(Generate.rangeNumber(start.y, end.y).map(n => Object({ x: start.x, y: n }))) | ||
} | ||
if (start.y === end.y) { | ||
path = path.concat(Generate.rangeNumber(start.x, end.x).map(n => Object({ x: n, y: start.y }))) | ||
} | ||
} | ||
path.push(points[points.length - 1]) | ||
return path | ||
} | ||
} |
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,30 @@ | ||
import { Generate, v2 } from "../index.js"; | ||
|
||
let description = function () { | ||
return ['#### Generate 生成模块', '包含一些生成的方法.', '', '以下是相关示例:'] | ||
} | ||
|
||
let run = function () { | ||
console.log('范围数字', Generate.rangeNumber(1, 7)); // [ 1, 2, 3, 4, 5, 6 ] | ||
console.log('直线路径', Generate.straightLinePath(v2(0, 0), v2(0, 2), v2(2, 2))); // [{ x: 0, y: 0 },{ x: 0, y: 1 },{ x: 0, y: 2 },{ x: 1, y: 2 },{ x: 2, y: 2 }] | ||
} | ||
try { | ||
describe('生成模块', function () { | ||
it('范围数字', function () { | ||
expect(Generate.rangeNumber(1, 7)).toEqual([1, 2, 3, 4, 5, 6]) | ||
expect(Generate.rangeNumber(7, 1)).toEqual([7, 6, 5, 4, 3, 2]) | ||
}) | ||
it('直线路径', function () { | ||
expect(Generate.straightLinePath(v2(0, 0), v2(0, 2), v2(2, 2))).toEqual([{ x: 0, y: 0 }, { x: 0, y: 1 }, { x: 0, y: 2 }, { x: 1, y: 2 }, { x: 2, y: 2 }]) | ||
}) | ||
}) | ||
} catch (error) { | ||
// describe is not defined 无需理会 调用方式不一致 | ||
} | ||
|
||
|
||
|
||
export { | ||
run, | ||
description | ||
} |
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