mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Uncommented ellipse test cases.
This commit is contained in:
parent
781e1da93e
commit
933fb6866c
2 changed files with 102 additions and 101 deletions
|
@ -3,97 +3,98 @@ describe 'Ellipse', ->
|
||||||
Rectangle = require 'lib/world/rectangle'
|
Rectangle = require 'lib/world/rectangle'
|
||||||
Vector = require 'lib/world/vector'
|
Vector = require 'lib/world/vector'
|
||||||
|
|
||||||
#it 'contains its own center', ->
|
it 'contains its own center', ->
|
||||||
# ellipse = new Ellipse 0, 0, 10, 10
|
ellipse = new Ellipse 0, 0, 10, 10
|
||||||
# expect(ellipse.containsPoint(new Vector 0, 0)).toBe true
|
expect(ellipse.containsPoint(new Vector 0, 0)).toBe true
|
||||||
#
|
|
||||||
#it 'contains a point when rotated', ->
|
it 'contains a point when rotated', ->
|
||||||
# ellipse = new Ellipse 0, -20, 40, 40, 3 * Math.PI / 4
|
ellipse = new Ellipse 0, -20, 40, 40, 3 * Math.PI / 4
|
||||||
# p = new Vector 0, 2
|
expect(ellipse.containsPoint new Vector(0, 0)).toBe true
|
||||||
# expect(ellipse.containsPoint(p, true)).toBe true
|
expect(ellipse.containsPoint new Vector(0, 2)).toBe false
|
||||||
#
|
|
||||||
#it 'contains more points properly', ->
|
it 'contains more points properly', ->
|
||||||
# # ellipse with y major axis, off-origin center, and 45 degree rotation
|
# ellipse with y major axis, off-origin center, and 45 degree rotation
|
||||||
# ellipse = new Ellipse 1, 2, 4, 6, Math.PI / 4
|
ellipse = new Ellipse 1, 2, 4, 6, Math.PI / 4
|
||||||
# expect(ellipse.contains new Vector(1, 2)).toBe true
|
expect(ellipse.containsPoint new Vector(1, 2)).toBe true
|
||||||
# expect(ellipse.contains new Vector(-1, 3)).toBe true
|
expect(ellipse.containsPoint new Vector(-1, 3)).toBe true
|
||||||
# expect(ellipse.contains new Vector(0, 4)).toBe true
|
expect(ellipse.containsPoint new Vector(0, 4)).toBe true
|
||||||
# expect(ellipse.contains new Vector(1, 4)).toBe true
|
expect(ellipse.containsPoint new Vector(1, 4)).toBe true
|
||||||
# expect(ellipse.contains new Vector(3, 0)).toBe true
|
expect(ellipse.containsPoint new Vector(3, 0)).toBe true
|
||||||
# expect(ellipse.contains new Vector(1, 0)).toBe true
|
expect(ellipse.containsPoint new Vector(1, 0)).toBe true
|
||||||
# expect(ellipse.contains new Vector(0, 1)).toBe true
|
expect(ellipse.containsPoint new Vector(0, 1)).toBe true
|
||||||
# expect(ellipse.contains new Vector(-1, 2)).toBe true
|
expect(ellipse.containsPoint new Vector(-1, 2)).toBe true
|
||||||
# expect(ellipse.contains new Vector(2, 2)).toBe true
|
expect(ellipse.containsPoint new Vector(2, 2)).toBe true
|
||||||
# expect(ellipse.contains new Vector(0, 0)).toBe false
|
expect(ellipse.containsPoint new Vector(0, 0)).toBe false
|
||||||
# expect(ellipse.contains new Vector(0, 5)).toBe false
|
expect(ellipse.containsPoint new Vector(0, 5)).toBe false
|
||||||
# expect(ellipse.contains new Vector(3, 4)).toBe false
|
expect(ellipse.containsPoint new Vector(3, 4)).toBe false
|
||||||
# expect(ellipse.contains new Vector(4, 0)).toBe false
|
expect(ellipse.containsPoint new Vector(4, 0)).toBe false
|
||||||
# expect(ellipse.contains new Vector(2, -1)).toBe false
|
expect(ellipse.containsPoint new Vector(2, -1)).toBe false
|
||||||
# expect(ellipse.contains new Vector(0, -3)).toBe false
|
expect(ellipse.containsPoint new Vector(0, -3)).toBe false
|
||||||
# expect(ellipse.contains new Vector(-2, -2)).toBe false
|
expect(ellipse.containsPoint new Vector(-2, -2)).toBe false
|
||||||
# expect(ellipse.contains new Vector(-2, 0)).toBe false
|
expect(ellipse.containsPoint new Vector(-2, 0)).toBe false
|
||||||
# expect(ellipse.contains new Vector(-2, 4)).toBe false
|
expect(ellipse.containsPoint new Vector(-2, 4)).toBe false
|
||||||
#
|
|
||||||
#it 'correctly calculates distance to a faraway point', ->
|
xit 'correctly calculates distance to a faraway point', ->
|
||||||
# ellipse = new Ellipse 100, 50, 20, 40
|
# TODO: this is the correct distance if the ellipse were a rectangle, but need to update for actual ellipse expected distances.
|
||||||
# p = new Vector 200, 300
|
ellipse = new Ellipse 100, 50, 20, 40
|
||||||
# d = 10 * Math.sqrt(610)
|
p = new Vector 200, 300
|
||||||
# expect(ellipse.distanceToPoint(p)).toBeCloseTo d
|
d = 10 * Math.sqrt(610)
|
||||||
# ellipse.rotation = Math.PI / 2
|
expect(ellipse.distanceToPoint(p)).toBeCloseTo d
|
||||||
# d = 80 * Math.sqrt(10)
|
ellipse.rotation = Math.PI / 2
|
||||||
# expect(ellipse.distanceToPoint(p)).toBeCloseTo d
|
d = 80 * Math.sqrt(10)
|
||||||
#
|
expect(ellipse.distanceToPoint(p)).toBeCloseTo d
|
||||||
#it 'does not modify itself or target Vector when calculating distance', ->
|
|
||||||
# ellipse = new Ellipse -100, -200, 1, 100
|
it 'does not modify itself or target Vector when calculating distance', ->
|
||||||
# ellipse2 = ellipse.copy()
|
ellipse = new Ellipse -100, -200, 1, 100
|
||||||
# p = new Vector -100.25, -101
|
ellipse2 = ellipse.copy()
|
||||||
# p2 = p.copy()
|
p = new Vector -100.25, -101
|
||||||
# ellipse.distanceToPoint(p)
|
p2 = p.copy()
|
||||||
# expect(p.x).toEqual p2.x
|
ellipse.distanceToPoint(p)
|
||||||
# expect(p.y).toEqual p2.y
|
expect(p.x).toEqual p2.x
|
||||||
# expect(ellipse.x).toEqual ellipse2.x
|
expect(p.y).toEqual p2.y
|
||||||
# expect(ellipse.y).toEqual ellipse2.y
|
expect(ellipse.x).toEqual ellipse2.x
|
||||||
# expect(ellipse.width).toEqual ellipse2.width
|
expect(ellipse.y).toEqual ellipse2.y
|
||||||
# expect(ellipse.height).toEqual ellipse2.height
|
expect(ellipse.width).toEqual ellipse2.width
|
||||||
# expect(ellipse.rotation).toEqual ellipse2.rotation
|
expect(ellipse.height).toEqual ellipse2.height
|
||||||
#
|
expect(ellipse.rotation).toEqual ellipse2.rotation
|
||||||
#it 'correctly calculates distance to contained point', ->
|
|
||||||
# ellipse = new Ellipse -100, -200, 1, 100
|
it 'correctly calculates distance to contained point', ->
|
||||||
# ellipse2 = ellipse.copy()
|
ellipse = new Ellipse -100, -200, 1, 100
|
||||||
# p = new Vector -100.25, -160
|
ellipse2 = ellipse.copy()
|
||||||
# p2 = p.copy()
|
p = new Vector -100.25, -160
|
||||||
# expect(ellipse.distanceToPoint(p)).toBe 0
|
p2 = p.copy()
|
||||||
# ellipse.rotation = 0.00000001 * Math.PI
|
expect(ellipse.distanceToPoint(p)).toBe 0
|
||||||
# expect(ellipse.distanceToPoint(p)).toBe 0
|
ellipse.rotation = 0.00000001 * Math.PI
|
||||||
#
|
expect(ellipse.distanceToPoint(p)).toBe 0
|
||||||
#it 'AABB works when not rotated', ->
|
|
||||||
# ellipse = new Ellipse 10, 20, 30, 40
|
it 'AABB works when not rotated', ->
|
||||||
# rect = new Rectangle 10, 20, 30, 40
|
ellipse = new Ellipse 10, 20, 30, 40
|
||||||
# aabb1 = ellipse.axisAlignedBoundingBox()
|
rect = new Rectangle 10, 20, 30, 40
|
||||||
# aabb2 = ellipse.axisAlignedBoundingBox()
|
aabb1 = ellipse.axisAlignedBoundingBox()
|
||||||
# for prop in ['x', 'y', 'width', 'height']
|
aabb2 = ellipse.axisAlignedBoundingBox()
|
||||||
# expect(aabb1[prop]).toBe aabb2[prop]
|
for prop in ['x', 'y', 'width', 'height']
|
||||||
#
|
expect(aabb1[prop]).toBe aabb2[prop]
|
||||||
#it 'AABB works when rotated', ->
|
|
||||||
# ellipse = new Ellipse 10, 20, 30, 40, Math.PI / 3
|
it 'AABB works when rotated', ->
|
||||||
# rect = new Rectangle 10, 20, 30, 40, Math.PI / 3
|
ellipse = new Ellipse 10, 20, 30, 40, Math.PI / 3
|
||||||
# aabb1 = ellipse.axisAlignedBoundingBox()
|
rect = new Rectangle 10, 20, 30, 40, Math.PI / 3
|
||||||
# aabb2 = ellipse.axisAlignedBoundingBox()
|
aabb1 = ellipse.axisAlignedBoundingBox()
|
||||||
# for prop in ['x', 'y', 'width', 'height']
|
aabb2 = ellipse.axisAlignedBoundingBox()
|
||||||
# expect(aabb1[prop]).toBe aabb2[prop]
|
for prop in ['x', 'y', 'width', 'height']
|
||||||
#
|
expect(aabb1[prop]).toBe aabb2[prop]
|
||||||
#it 'calculates ellipse intersections properly', ->
|
|
||||||
# # ellipse with y major axis, off-origin center, and 45 degree rotation
|
it 'calculates ellipse intersections properly', ->
|
||||||
# ellipse = new Ellipse 1, 2, 4, 6, Math.PI / 4
|
# ellipse with y major axis, off-origin center, and 45 degree rotation
|
||||||
# expect(ellipse.intersectsShape new Rectangle(0, 0, 2, 2, 0)).toBe true
|
ellipse = new Ellipse 1, 2, 4, 6, Math.PI / 4
|
||||||
# expect(ellipse.intersectsShape new Rectangle(0, -1, 2, 3, 0)).toBe true
|
expect(ellipse.intersectsShape new Rectangle(0, 0, 2, 2, 0)).toBe true
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-1, -0.5, 2 * Math.SQRT2, 2 * Math.SQRT2, Math.PI / 4)).toBe true
|
expect(ellipse.intersectsShape new Rectangle(0, -1, 2, 3, 0)).toBe true
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-1, -0.5, 2 * Math.SQRT2, 2 * Math.SQRT2, 0)).toBe true
|
expect(ellipse.intersectsShape new Rectangle(-1, -0.5, 2 * Math.SQRT2, 2 * Math.SQRT2, Math.PI / 4)).toBe true
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-1, -1, 2 * Math.SQRT2, 2 * Math.SQRT2, 0)).toBe true
|
expect(ellipse.intersectsShape new Rectangle(-1, -0.5, 2 * Math.SQRT2, 2 * Math.SQRT2, 0)).toBe true
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-1, -1, 2 * Math.SQRT2, 2 * Math.SQRT2, Math.PI / 4)).toBe false
|
expect(ellipse.intersectsShape new Rectangle(-1, -1, 2 * Math.SQRT2, 2 * Math.SQRT2, 0)).toBe true
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-2, -2, 2, 2, 0)).toBe false
|
expect(ellipse.intersectsShape new Rectangle(-1, -1, 2 * Math.SQRT2, 2 * Math.SQRT2, Math.PI / 4)).toBe false
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-Math.SQRT2 / 2, -Math.SQRT2 / 2, Math.SQRT2, Math.SQRT2, 0)).toBe false
|
expect(ellipse.intersectsShape new Rectangle(-2, -2, 2, 2, 0)).toBe false
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-Math.SQRT2 / 2, -Math.SQRT2 / 2, Math.SQRT2, Math.SQRT2, Math.PI / 4)).toBe false
|
expect(ellipse.intersectsShape new Rectangle(-Math.SQRT2 / 2, -Math.SQRT2 / 2, Math.SQRT2, Math.SQRT2, 0)).toBe false
|
||||||
# expect(ellipse.intersectsShape new Rectangle(-2, 0, 2, 2, 0)).toBe false
|
expect(ellipse.intersectsShape new Rectangle(-Math.SQRT2 / 2, -Math.SQRT2 / 2, Math.SQRT2, Math.SQRT2, Math.PI / 4)).toBe false
|
||||||
# expect(ellipse.intersectsShape new Rectangle(0, -2, 2, 2, 0)).toBe false
|
expect(ellipse.intersectsShape new Rectangle(-2, 0, 2, 2, 0)).toBe false
|
||||||
# expect(ellipse.intersectsShape new Rectangle(1, 2, 1, 1, 0)).toBe true
|
expect(ellipse.intersectsShape new Rectangle(0, -2, 2, 2, 0)).toBe false
|
||||||
|
expect(ellipse.intersectsShape new Rectangle(1, 2, 1, 1, 0)).toBe true
|
||||||
|
|
|
@ -28,13 +28,13 @@ describe 'LineSegment', ->
|
||||||
it 'can tell when a point is on a line or segment', ->
|
it 'can tell when a point is on a line or segment', ->
|
||||||
lineSegment = new LineSegment v00, v11
|
lineSegment = new LineSegment v00, v11
|
||||||
expect(lineSegment.pointOnLine v22, false).toBe true
|
expect(lineSegment.pointOnLine v22, false).toBe true
|
||||||
#expect(lineSegment.pointOnLine v22, true).toBe false
|
expect(lineSegment.pointOnLine v22, true).toBe false
|
||||||
#expect(lineSegment.pointOnLine v00, false).toBe true
|
expect(lineSegment.pointOnLine v00, false).toBe true
|
||||||
#expect(lineSegment.pointOnLine v00, true).toBe true
|
expect(lineSegment.pointOnLine v00, true).toBe true
|
||||||
#expect(lineSegment.pointOnLine v11, true).toBe true
|
expect(lineSegment.pointOnLine v11, true).toBe true
|
||||||
#expect(lineSegment.pointOnLine v11, false).toBe true
|
expect(lineSegment.pointOnLine v11, false).toBe true
|
||||||
#expect(lineSegment.pointOnLine v34, false).toBe false
|
expect(lineSegment.pointOnLine v34, false).toBe false
|
||||||
#expect(lineSegment.pointOnLine v34, true).toBe false
|
expect(lineSegment.pointOnLine v34, true).toBe false
|
||||||
|
|
||||||
it 'correctly calculates distance to points', ->
|
it 'correctly calculates distance to points', ->
|
||||||
lineSegment = new LineSegment v00, v11
|
lineSegment = new LineSegment v00, v11
|
||||||
|
|
Loading…
Reference in a new issue