-
Notifications
You must be signed in to change notification settings - Fork 66
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
kekee000
committed
Jul 19, 2015
1 parent
7b04e1c
commit 2f8338e
Showing
6 changed files
with
390 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
define( | ||
function (require) { | ||
|
||
var computeBoundingBox = require('graphics/computeBoundingBox'); | ||
|
||
var p0 = { | ||
x: 50, | ||
y: 50, | ||
onCurve: true | ||
}; | ||
|
||
var c0 = { | ||
x: 80, | ||
y: 60 | ||
}; | ||
|
||
var c1 = { | ||
x: 200, | ||
y: 200 | ||
}; | ||
|
||
var p1 = { | ||
x: 100, | ||
y: 100, | ||
onCurve: true | ||
}; | ||
|
||
describe('计算包围盒', function () { | ||
|
||
|
||
|
||
it('test computeBounding', function () { | ||
|
||
var result = computeBoundingBox.computeBounding([]); | ||
expect(result).toBe(false); | ||
|
||
var result = computeBoundingBox.computeBounding([p0]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 0, | ||
height: 0 | ||
}); | ||
|
||
var result = computeBoundingBox.computeBounding([p0, p1]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 50, | ||
height: 50 | ||
}); | ||
|
||
|
||
var result = computeBoundingBox.computeBounding([p0, c1, p1]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 150, | ||
height: 150 | ||
}); | ||
}); | ||
|
||
|
||
it('test quadraticBezier', function () { | ||
|
||
var result = computeBoundingBox.quadraticBezier(p0, p0, p0); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 0, | ||
height: 0 | ||
}); | ||
|
||
var result = computeBoundingBox.quadraticBezier(p0, p0, p1); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 50, | ||
height: 50 | ||
}); | ||
|
||
var result = computeBoundingBox.quadraticBezier(p0, c0, p1); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 50, | ||
height: 50 | ||
}); | ||
|
||
var result = computeBoundingBox.quadraticBezier(p0, c1, p1); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 90, | ||
height: 90 | ||
}); | ||
}); | ||
|
||
it('test computePath', function () { | ||
var result = computeBoundingBox.computePath([p0]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 0, | ||
height: 0 | ||
}); | ||
|
||
var result = computeBoundingBox.computePath([p0, p1]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 50, | ||
height: 50 | ||
}); | ||
|
||
|
||
var result = computeBoundingBox.computePath([p0, c1, p1]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 90, | ||
height: 90 | ||
}); | ||
}); | ||
|
||
|
||
it('test computePathBox', function () { | ||
|
||
var result = computeBoundingBox.computePathBox([]); | ||
expect(result).toBe(false); | ||
|
||
var result = computeBoundingBox.computePathBox([p0]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 0, | ||
height: 0 | ||
}); | ||
|
||
var result = computeBoundingBox.computePathBox([p0, p1]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 50, | ||
height: 50 | ||
}); | ||
|
||
|
||
var result = computeBoundingBox.computePathBox([p0, c1, p1]); | ||
expect(result).toEqual({ | ||
x: 50, | ||
y: 50, | ||
width: 150, | ||
height: 150 | ||
}); | ||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
} | ||
); |
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,128 @@ | ||
define( | ||
function (require) { | ||
var lang = require('common/lang'); | ||
var pathAdjust = require('graphics/pathAdjust'); | ||
|
||
var path = [ | ||
{ | ||
x: 50, | ||
y: 50 | ||
}, | ||
{ | ||
x: 100, | ||
y: 100 | ||
} | ||
]; | ||
|
||
describe('调整路径', function () { | ||
|
||
it('test default', function () { | ||
|
||
var result = pathAdjust(lang.clone(path)); | ||
expect(result).toEqual([ | ||
{ | ||
x: 50, | ||
y: 50 | ||
}, | ||
{ | ||
x: 100, | ||
y: 100 | ||
} | ||
]); | ||
|
||
var result = pathAdjust(lang.clone(path), 1, 1); | ||
expect(result).toEqual([ | ||
{ | ||
x: 50, | ||
y: 50 | ||
}, | ||
{ | ||
x: 100, | ||
y: 100 | ||
} | ||
]); | ||
|
||
var result = pathAdjust(lang.clone(path), 1, 1, 0, 0); | ||
expect(result).toEqual([ | ||
{ | ||
x: 50, | ||
y: 50 | ||
}, | ||
{ | ||
x: 100, | ||
y: 100 | ||
} | ||
]); | ||
}); | ||
|
||
it('test scale', function () { | ||
|
||
var result = pathAdjust(lang.clone(path), 2, 2); | ||
expect(result).toEqual([ | ||
{ | ||
x: 100, | ||
y: 100 | ||
}, | ||
{ | ||
x: 200, | ||
y: 200 | ||
} | ||
]); | ||
|
||
var result = pathAdjust(lang.clone(path), 0.5, 1); | ||
expect(result).toEqual([ | ||
{ | ||
x: 25, | ||
y: 50 | ||
}, | ||
{ | ||
x: 50, | ||
y: 100 | ||
} | ||
]); | ||
|
||
var result = pathAdjust(lang.clone(path), 1, 2, 0, 0); | ||
expect(result).toEqual([ | ||
{ | ||
x: 50, | ||
y: 100 | ||
}, | ||
{ | ||
x: 100, | ||
y: 200 | ||
} | ||
]); | ||
}); | ||
|
||
|
||
it('test offset', function () { | ||
|
||
var result = pathAdjust(lang.clone(path), 1, 1, 10, 10); | ||
expect(result).toEqual([ | ||
{ | ||
x: 60, | ||
y: 60 | ||
}, | ||
{ | ||
x: 110, | ||
y: 110 | ||
} | ||
]); | ||
|
||
var result = pathAdjust(lang.clone(path), 2, 2, 10, 10); | ||
expect(result).toEqual([ | ||
{ | ||
x: 120, | ||
y: 120 | ||
}, | ||
{ | ||
x: 220, | ||
y: 220 | ||
} | ||
]); | ||
}); | ||
|
||
}); | ||
|
||
} | ||
); |
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
Oops, something went wrong.