HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
If the stylesheet you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
#output
#output
font-family: monospace
# https://github.com/hornairs/blog/blob/master/assets/coffeescripts/flocking/vector.coffee
class Vector
# Class methods for nondestructively operating
for name in ['add', 'subtract', 'multiply', 'divide']
do (name) ->
Vector[name] = (a, b, useZ) ->
a.copy()[name](b, useZ)
isVector: true
constructor: (@x=0, @y=0, @z=0) ->
copy: ->
new Vector(@x, @y, @z)
magnitude: (useZ) ->
sum = @x * @x + @y * @y
sum += @z * @z if useZ
Math.sqrt sum
magnitudeSquared: (useZ) ->
sum = @x * @x + @y * @y
sum += @z * @z if useZ
sum
normalize: (useZ) ->
m = @magnitude useZ
@divide m, useZ if m > 0
@
limit: (max) ->
if @magnitude() > max
@normalize()
return @multiply(max)
else
@
heading: ->
-1 * Math.atan2(-1 * @y, @x)
distance: (other, useZ) ->
dx = @x - other.x
dy = @y - other.y
sum = dx * dx + dy * dy
if useZ
dz = @z - other.z
sum += dz * dz
Math.sqrt sum
distanceSquared: (other, useZ) ->
dx = @x - other.x
dy = @y - other.y
sum = dx * dx + dy * dy
if useZ
dz = @z - other.z
sum += dz * dz
sum
subtract: (other, useZ) ->
@x -= other.x
@y -= other.y
@z -= other.z if useZ
@
add: (other, useZ) ->
@x += other.x
@y += other.y
@z += other.z if useZ
@
divide: (n, useZ) ->
[@x, @y] = [@x / n, @y / n]
@z = @z / n if useZ
@
multiply: (n, useZ) ->
[@x, @y] = [@x * n, @y * n]
@z = @z * n if useZ
@
dot: (other, useZ) ->
sum = @x * other.x + @y * other.y
sum += @z + other.z if useZ
sum
# Not the strict projection, the other isn't converted to a unit vector first.
projectOnto: (other, useZ) ->
other.copy().multiply(@dot(other, useZ), useZ)
isZero: (useZ) ->
result = @x is 0 and @y is 0
result = result and @z is 0 if useZ
result
equals: (other, useZ) ->
result = other and @x is other.x and @y is other.y
result = result and @z is other.z if useZ
result
# Rotate it around the origin
# If we ever want to make this also use z: https://en.wikipedia.org/wiki/Axes_conventions
rotate: (theta) ->
return @ unless theta
[@x, @y] = [Math.cos(theta) * @x - Math.sin(theta) * @y, Math.sin(theta) * @x + Math.cos(theta) * @y]
@
invalid: () ->
return (@x is Infinity) || isNaN(@x) || @y is Infinity || isNaN(@y) || @z is Infinity || isNaN(@z)
toString: (useZ) ->
useZ = true
return "{x: #{@x.toFixed(0)}, y: #{@y.toFixed(0)}, z: #{@z.toFixed(0)}}" if useZ
return "{x: #{@x.toFixed(0)}, y: #{@y.toFixed(0)}}"
class Line
EPS = 1e-9
constructFromParams: (@a, @b, @c) ->
@
constructFromPoints: (x1, y1, x2, y2) ->
@.b = x1 - x2
@.a = y2 - y1
@.c = -@.a * x1 - @.b * y1
@
_det: (a, b, c, d) ->
a * d - b * c
intersect: (other) ->
zn = @._det(@.a, @.b, other.a, other.b)
if (Math.abs(zn) < EPS)
return false;
new Vector(- @._det(@.c, @.b, other.c, other.b) / zn, - @._det(@.a, @.c, other.a, other.c) / zn)
parallel: (other) ->
Math.abs(det(@.a, @.b, other.a, other.b)) < EPS
class Segment
EPS = 1e-9
constructor: (@startPoint, @endPoint) ->
distanceToPoint: (point) ->
res = Math.min(point.distance(@.startPoint), point.distance(@.endPoint))
Line line = new Line().constructFromPoints(@startPoint.x, @startPoint.y, @endPoint.x, @endPoint.y)
a = -line.b
b = line.a
c = -a * point.x - b * point.y
Line normal = new Line().constructFromParams(a, b, c)
intersect = normal.intersect(line)
if Math.abs(@startPoint.distance(@endPoint) - @startPoint.distance(intersect) - @endPoint.distance(intersect)) < EPS
res = Math.min(res, point.distance(intersect))
res
class Rectangle
@className: "Rectangle"
# Class methods for nondestructively operating
for name in ['add', 'subtract', 'multiply', 'divide']
do (name) ->
Rectangle[name] = (a, b) ->
a.copy()[name](b)
constructor: (@x=0, @y=0, @width=0, @height=0, @rotation=0) ->
copy: ->
new Rectangle(@x, @y, @width, @height, @rotation)
getPos: ->
new Vector(@x, @y)
vertices: ->
# Counter-clockwise, starting from bottom left (when unrotated)
[w2, h2, cos, sin] = [@width / 2, @height / 2, Math.cos(@rotation), Math.sin(-@rotation)]
[
new Vector @x - (w2 * cos - h2 * sin), @y - (w2 * sin + h2 * cos)
new Vector @x - (w2 * cos + h2 * sin), @y - (w2 * sin - h2 * cos)
new Vector @x + (w2 * cos - h2 * sin), @y + (w2 * sin + h2 * cos)
new Vector @x + (w2 * cos + h2 * sin), @y + (w2 * sin - h2 * cos)
]
touchesRect: (other) ->
# Whether this rect shares part of any edge with other rect, for non-rotated, non-overlapping rectangles.
# I think it says kitty-corner rects touch, but I don't think I want that.
# Float instability might get me, too.
[bl1, tl1, tr1, br1] = @vertices()
[bl2, tl2, tr2, br2] = other.vertices()
return false if tl1.x > tr2.x or tl2.x > tr1.x
return false if bl1.y > tl2.y or bl2.y > tl1.y
return true if tl1.x is tr2.x or tl2.x is tr1.x
return true if tl1.y is bl2.y or tl2.y is bl1.y
false
touchesPoint: (p) ->
# Whether this rect has point p exactly on one of its edges, assuming no rotation.
[bl, tl, tr, br] = @vertices()
return false unless p.y >= bl.y and p.y <= tl.y
return false unless p.x >= bl.x and p.x <= br.x
return true if p.x is bl.x or p.x is br.x
return true if p.y is bl.y or p.y is tl.y
false
axisAlignedBoundingBox: (rounded=true) ->
box = @copy()
return box unless @rotation
box.rotation = 0
[left, top] = [9001, 9001]
for vertex in @vertices()
[left, top] = [Math.min(left, vertex.x), Math.min(top, vertex.y)]
if rounded
[left, top] = [Math.round(left), Math.round(top)]
[box.width, box.height] = [2 * (@x - left), 2 * (@y - top)]
box
distanceToPoint: (p) ->
# Get p in rect's coordinate space, then operate in one quadrant
p = Vector.subtract(p, @getPos()).rotate(-@rotation)
dx = Math.max(Math.abs(p.x) - @width / 2, 0)
dy = Math.max(Math.abs(p.y) - @height / 2, 0)
Math.sqrt dx * dx + dy * dy
distanceSquaredToPoint: (p) ->
# Doesn't handle rotation; just supposed to be faster than distanceToPoint
dx = Math.max(Math.abs(p.x) - @width / 2, 0)
dy = Math.max(Math.abs(p.y) - @height / 2, 0)
dx * dx + dy * dy
distanceToRectangle: (other) ->
[firstVertices, secondVertices] = [@.vertices(), other.vertices()]
[firstEdges, secondEdges] = [[], []]
for i in [0..3]
firstEdges.push new Segment(firstVertices[i], firstVertices[(i + 1) % 4])
secondEdges.push new Segment(secondVertices[i], secondVertices[(i + 1) % 4])
ans = Infinity
for i in [0..3]
for j in [0..firstEdges.length - 1]
ans = Math.min(ans, firstEdges[j].distanceToPoint(secondVertices[i]))
for j in [0..secondEdges.length - 1]
ans = Math.min(ans, secondEdges[j].distanceToPoint(firstVertices[i]))
ans
containsPoint: (p, withRotation=true) ->
if withRotation and @rotation
not @distanceToPoint(p)
else
@x - @width / 2 < p.x < @x + @width / 2 and @y - @height / 2 < p.y < @y + @height / 2
subtract: (point) ->
@x -= point.x
@y -= point.y
@pos.subtract point
@
add: (point) ->
@x += point.x
@y += point.y
@pos.add point
@
divide: (n) ->
[@width, @height] = [@width / n, @height / n]
@
multiply: (n) ->
[@width, @height] = [@width * n, @height * n]
@
isEmpty: () ->
@width == 0 and @height == 0
invalid: () ->
return (@x == Infinity) || isNaN(@x) || @y == Infinity || isNaN(@y) || @width == Infinity || isNaN(@width) || @height == Infinity || isNaN(@height) || @rotation == Infinity || isNaN(@rotation)
toString: ->
return "{x: #{@x.toFixed(0)}, y: #{@y.toFixed(0)}, w: #{@width.toFixed(0)}, h: #{@height.toFixed(0)}, rot: #{@rotation.toFixed(3)}}"
class Ellipse
@className: "Ellipse"
constructor: (@x=0, @y=0, @width=0, @height=0, @rotation=0) ->
containsPoint: (p, withRotation=true) ->
[a, b] = [@width / 2, @height / 2]
[h, k] = [@x, @y]
[x, y] = [p.x, p.y]
x2 = Math.pow(x, 2)
a2 = Math.pow(a, 2)
a4 = Math.pow(a, 4)
b2 = Math.pow(b, 2)
b4 = Math.pow(b, 4)
h2 = Math.pow(h, 2)
k2 = Math.pow(k, 2)
if withRotation and @rotation
sint = Math.sin(@rotation)
sin2t = Math.sin(2 * @rotation)
cost = Math.cos(@rotation)
cos2t = Math.cos(2 * @rotation)
numeratorLeft = (-a2 * h * sin2t) + (a2 * k * cos2t) + (a2 * k) + (a2 * x * sin2t)
numeratorMiddle = Math.SQRT2 * Math.sqrt((a4 * b2 * cos2t) + (a4 * b2) - (a2 * b4 * cos2t) + (a2 * b4) - (2 * a2 * b2 * h2) + (4 * a2 * b2 * h * x) - (2 * a2 * b2 * x2))
numeratorRight = (b2 * h * sin2t) - (b2 * k * cos2t) + (b2 * k) - (b2 * x * sin2t)
denominator = (a2 * cos2t) + a2 - (b2 * cos2t) + b2
solution1 = (numeratorLeft - numeratorMiddle + numeratorRight) / denominator
solution2 = (numeratorLeft + numeratorMiddle + numeratorRight) / denominator
if (not isNaN solution1) and (not isNaN solution2)
[bigSolution, littleSolution] = if solution1 > solution2 then [solution1, solution2] else [solution2, solution1]
if y > littleSolution and y < bigSolution
return true
else
return false
else
return false
else
numeratorLeft = a2 * k
numeratorRight = Math.sqrt((a4 * b2) - (a2 * b2 * h2) + (2 * a2 * b2 * h * x) - (a2 * b2 * x2))
denominator = a2
solution1 = (numeratorLeft + numeratorRight) / denominator
solution2 = (numeratorLeft - numeratorRight) / denominator
if (not isNaN solution1) and (not isNaN solution2)
[bigSolution, littleSolution] = if solution1 > solution2 then [solution1, solution2] else [solution2, solution1]
if y > littleSolution and y < bigSolution
return true
else
return false
else
return false
false
intersectsLineSegment: (p1, p2) ->
[px1, py1, px2, py2] = [p1.x, p1.y, p2.x, p2.y]
m = (py1 - py2) / (px1 - px2)
m2 = Math.pow(m, 2)
c = py1 - (m * px1)
c2 = Math.pow(c, 2)
[a, b] = [@width / 2, @height / 2]
[h, k] = [@x, @y]
a2 = Math.pow(a, 2)
a4 = Math.pow(a, 2)
b2 = Math.pow(b, 2)
b4 = Math.pow(b, 4)
h2 = Math.pow(h, 2)
k2 = Math.pow(k, 2)
sint = Math.sin(@rotation)
sin2t = Math.sin(2 * @rotation)
cost = Math.cos(@rotation)
cos2t = Math.cos(2 * @rotation)
if (not isNaN m) and m != Infinity and m != -Infinity
numeratorLeft = (-a2 * c * m * cos2t) - (a2 * c * m) + (a2 * c * sin2t) - (a2 * h * m * sin2t) - (a2 * h * cos2t) + (a2 * h) + (a2 * k * m * cos2t) + (a2 * k * m) - (a2 * k * sin2t)
numeratorMiddle = Math.SQRT2 * Math.sqrt((a4 * b2 * m2 * cos2t) + (a4 * b2 * m2) - (2 * a4 * b2 * m * sin2t) - (a4 * b2 * cos2t) + (a4 * b2) - (a2 * b4 * m2 * cos2t) + (a2 * b4 * m2) + (2 * a2 * b4 * m * sin2t) + (a2 * b4 * cos2t) + (a2 * b4) - (2 * a2 * b2 * c2) - (4 * a2 * b2 * c * h * m) + (4 * a2 * b2 * c * k) - (2 * a2 * b2 * h2 * m2) + (4 * a2 * b2 * h * k * m) - (2 * a2 * b2 * k2))
numeratorRight = (b2 * c * m * cos2t) - (b2 * c * m) - (b2 * c * sin2t) + (b2 * h * m * sin2t) + (b2 * h * cos2t) + (b2 * h) - (b2 * k * m * cos2t) + (b2 * k * m) + (b2 * k * sin2t)
denominator = (a2 * m2 * cos2t) + (a2 * m2) - (2 * a2 * m * sin2t) - (a2 * cos2t) + a2 - (b2 * m2 * cos2t) + (b2 * m2) + (2 * b2 * m * sin2t) + (b2 * cos2t) + b2
solution1 = (-numeratorLeft - numeratorMiddle + numeratorRight) / denominator
solution2 = (-numeratorLeft + numeratorMiddle + numeratorRight) / denominator
if (not isNaN solution1) and (not isNaN solution2)
[littleX, bigX] = if px1 < px2 then [px1, px2] else [px2, px1]
if (littleX <= solution1 and bigX >= solution1) or (littleX <= solution2 and bigX >= solution2)
return true
if (not isNaN solution1) or (not isNaN solution2)
solution = if not isNaN solution1 then solution1 else solution2
[littleX, bigX] = if px1 < px2 then [px1, px2] else [px2, px1]
if littleX <= solution and bigX >= solution
return true
else
return false
else
x = px1
x2 = Math.pow(x, 2)
numeratorLeft = (-a2 * h * sin2t) + (a2 * k * cos2t) + (a2 * k) + (a2 * x * sin2t)
numeratorMiddle = Math.SQRT2 * Math.sqrt((a4 * b2 * cos2t) + (a4 * b2) - (a2 * b4 * cos2t) + (a2 * b4) - (2 * a2 * b2 * h2) + (4 * a2 * b2 * h * x) - (2 * a2 * b2 * x2))
numeratorRight = (b2 * h * sin2t) - (b2 * k * cos2t) + (b2 * k) - (b2 * x * sin2t)
denominator = (a2 * cos2t) + a2 - (b2 * cos2t) + b2
solution1 = (numeratorLeft - numeratorMiddle + numeratorRight) / denominator
solution2 = (numeratorLeft + numeratorMiddle + numeratorRight) / denominator
if (not isNaN solution1) or (not isNaN solution2)
solution = if not isNaN solution1 then solution1 else solution2
[littleY, bigY] = if py1 < py2 then [py1, py2] else [py2, py1]
if littleY <= solution and bigY >= solution
return true
else
return false
false
toString: ->
return "{x: #{@x.toFixed(0)}, y: #{@y.toFixed(0)}, w: #{@width.toFixed(0)}, h: #{@height.toFixed(0)}, rot: #{@rotation.toFixed(3)}}"
class Thang
constructor: (@pos, @width=1, @height=1, @depth=1, @shape="box", @rotation=0) ->
@pos = new Vector(@pos?.x or 0, @pos?.y or 0, @pos?.z or @depth / 2) unless @pos?.isVector
ellipse: ->
new Ellipse @pos.x, @pos.y, @width, @height, @rotation
rectangle: ->
new Rectangle @pos.x, @pos.y, @width, @height, @rotation
isGrounded: ->
@pos.z <= @depth / 2
isAirborne: ->
@pos.z > @depth / 2
contains: (thang) ->
# Determines whether thang's center is within our bounds.
if @shape in ["ellipsoid", "disc"]
@ellipse().containsPoint thang.pos
else # box, rectangle
@rectangle().containsPoint thang.pos
distance: (thang) ->
# Determines the distance between the closest edges of @ and thang (0 if touching)
# TODO: make this aware of the shapes involved
# TODO: do it at all
# http://uclue.com/?xq=4737
# http://stackoverflow.com/questions/401847/circle-rectangle-collision-detection-intersection
# http://www.gamasutra.com/view/feature/131598/advanced_collision_detection_.php?print=1
if thang.isVector
return @pos.distance thang
[elliptical, rectangular] = [["ellipsoid", "disc"], ["box", "sheet"]]
if thang.shape in rectangular and @shape in rectangular
return @.rectangle().distanceToRectangle(thang.rectangle())
@pos.distance thang.pos
distanceSquared: (thang) ->
if thang.isVector
return @pos.distanceSquared thang
@pos.distanceSquared thang.pos
intersects: (thang, t1=null) ->
[elliptical, rectangular] = [["ellipsoid", "disc"], ["box", "sheet"]]
t1 ?= @
t2 = thang
if t1.contains(t2)
return true
if t1.shape in elliptical and t2.shape in elliptical
thisEllipse = t1.ellipse()
thatEllipse = t2.ellipse()
return thisEllipse.intersectsEllipse(thatEllipse)
if (t1.shape in elliptical and t2.shape in rectangular) or (t1.shape in rectangular and t2.shape in elliptical)
[ellipse, rectangle] = if t1.shape in elliptical then [t1.ellipse(), t2.rectangle()] else [t2.ellipse(), t1.rectangle()]
vertices = rectangle.vertices()
lineSegments = [[vertices[0], vertices[1]], [vertices[1], vertices[2]], [vertices[2], vertices[3]], [vertices[3], vertices[0]]]
for lineSegment in lineSegments
[p1, p2] = [lineSegment[0], lineSegment[1]]
if ellipse.intersectsLineSegment(p1, p2)
return true
if t1.shape in rectangular and t2.shape in rectangular
thisRectangle = t1.rectangle()
thatRectangle = t2.rectangle()
return thisRectangle.intersectsRectangle(thatRectangle)
false
toString: ->
"<#{@shape} - #{@pos.toString()} - #{@width} x #{@height} x #{@depth}"
log = (args...) ->
$('#output').append($('<div></div>').text(args.join(' ')))
rect1 = new Thang({x: 0, y: 0}, 4, 4, 0, "box", Math.PI / 4)
rect2 = new Thang({x: 4, y: -4}, 2, 2, 0, "box", 0)
log("rectangle-rectangle distance. should be 2.2426: ", rect1.distance(rect2))
ellipse = new Thang({x: 1, y: 2}, 4, 6, 0, "ellipsoid", Math.PI / 4)
log("ellipse with y major axis, off-origin center, and 45 degree rotation", ellipse)
point = new Thang({x: 0, y: 0}, 0, 0, 0, "ellipsoid")
log("ellipse.contains(1, 2) should be true: ", ellipse.contains(new Thang({x: 1, y: 2}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(-1, 3) should be true: ", ellipse.contains(new Thang({x: -1, y: 3}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(0, 4) should be true: ", ellipse.contains(new Thang({x: 0, y: 4}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(1, 4) should be true: ", ellipse.contains(new Thang({x: 1, y: 4}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(3, 0) should be true: ", ellipse.contains(new Thang({x: 3, y: 0}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(1, 0) should be true: ", ellipse.contains(new Thang({x: 1, y: 0}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(0, 1) should be true: ", ellipse.contains(new Thang({x: 0, y: 1}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(-1, 2) should be true: ", ellipse.contains(new Thang({x: -1, y: 2}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(2, 2) should be true: ", ellipse.contains(new Thang({x: 2, y: 2}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(0, 0) should be false: ", ellipse.contains(new Thang({x: 0, y: 0}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(0, 5) should be false: ", ellipse.contains(new Thang({x: 0, y: 5}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(3, 4) should be false: ", ellipse.contains(new Thang({x: 3, y: 4}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(4, 0) should be false: ", ellipse.contains(new Thang({x: 4, y: 0}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(2, -1) should be false: ", ellipse.contains(new Thang({x: 2, y: -1}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(0, -3) should be false: ", ellipse.contains(new Thang({x: 0, y: -3}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(-2, -2) should be false: ", ellipse.contains(new Thang({x: -2, y: -2}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(-2, 0) should be false: ", ellipse.contains(new Thang({x: -2, y: 0}, 0, 0, 0, "ellipsoid")))
log("ellipse.contains(-2, 4) should be false: ", ellipse.contains(new Thang({x: -2, y: 4}, 0, 0, 0, "ellipsoid")))
log("ellipse.intersects(rectangle: 0, 0, 2, 2, 0) should be true: ", ellipse.intersects(new Thang({x: 0, y: 0}, 2, 2, 0, "box", 0)))
log("ellipse.intersects(rectangle: 0, -1, 2, 3, 0) should be true: ", ellipse.intersects(new Thang({x: 0, y: -1}, 2, 3, 0, "box", 0)))
log("ellipse.intersects(rectangle: -1, -0.5, 2rt2, 2rt2, 45) should be true: ", ellipse.intersects(new Thang({x: -1, y: -0.5}, 2 * Math.SQRT2, 2 * Math.SQRT2, 0, "box", Math.PI / 4)))
log("ellipse.intersects(rectangle: -1, -0.5, 2rt2, 2rt2, 0) should be true: ", ellipse.intersects(new Thang({x: -1, y: -0.5}, 2 * Math.SQRT2, 2 * Math.SQRT2, 0, "box", 0)))
log("ellipse.intersects(rectangle: -1, -1, 2rt2, 2rt2, 0) should be true: ", ellipse.intersects(new Thang({x: -1, y: -1}, 2 * Math.SQRT2, 2 * Math.SQRT2, 0, "box", 0)))
log("ellipse.intersects(rectangle: -1, -1, 2rt2, 2rt2, 45) should be false: ", ellipse.intersects(new Thang({x: -1, y: -1}, 2 * Math.SQRT2, 2 * Math.SQRT2, 0, "box", Math.PI / 4)))
log("ellipse.intersects(rectangle: -2, -2, 2, 2, 0) should be false: ", ellipse.intersects(new Thang({x: -2, y: -2}, 2, 2, 0, "box", 0)))
log("ellipse.intersects(rectangle: -Math.SQRT2 / 2, -Math.SQRT2 / 2, Math.SQRT2, Math.SQRT2, 0) should be false: ", ellipse.intersects(new Thang({x: -Math.SQRT2 / 2, y: -Math.SQRT2 / 2}, Math.SQRT2, Math.SQRT2, 0, "box", 0)))
log("ellipse.intersects(rectangle: -Math.SQRT2 / 2, -Math.SQRT2 / 2, Math.SQRT2, Math.SQRT2, Math.PI / 4) should be false: ", ellipse.intersects(new Thang({x: -Math.SQRT2 / 2, y: -Math.SQRT2 / 2}, Math.SQRT2, Math.SQRT2, 0, "box", Math.PI / 4)))
log("ellipse.intersects(rectangle: -2, 0, 2, 2, 0) should be false: ", ellipse.intersects(new Thang({x: -2, y: 0}, 2, 2, 0, "box", 0)))
log("ellipse.intersects(rectangle: 0, -2, 2, 2, 0) should be false: ", ellipse.intersects(new Thang({x: 0, y: -2}, 2, 2, 0, "box", 0)))
Also see: Tab Triggers