TypeScript documentation generation
This is an idea for the future since the tools aren't fully there for it yet. However it is noted as an area for improvement on the TypeScript issue tracker thing: http://typescript.codeplex.com/workitem/16
Some documentation useful for everybody could be generated through parsing the TypeScript interfaces to three.js.
I noticed @kontan has written an experimental tool for doing this, it looks cool:
http://kontan.github.com/dtsdoc/three.d.ts.html#THREE.Vector3
That documentation is a little weird in that is seems to imply that Vector2 and Vector3 are subclasses of the class Vector. But maybe that is in a different version of Three.js.
Otherwise the inferencing is pretty nice.
Hi,
That Vector class is a temporary fix. There are a few reasons why Vector2 and Vector3 extends Vector. An object of CurvePath accepts Vector2 or Vector3 as their points. Both classes a common function 'addSelf' and CurvePath uses it. addSelf's parameter has same type as return type. Ideally, in Java, I think that the following declaration is best:
interface Vector<T>{
T addSelf(T v);
...
}
class Vector2 implements Vector<Vector2>{
public Vector2 addSelf(Vector2 v){ ... }
}
class Vector3 implements Vector<Vector3>{
public Vector3 addSelf(Vector3 v){ ... }
}
class BoundingBox<T extends Vector<T>>{
T centroid;
...
}
class CurvePath<T extends Vector<T>>{
BoundingBox<T> getBoundingBox(){ ... }
}
However, unfortunately, TypeScript dosn't have generics yet. If BoundingBox.centrois is 'any' or 'Object', it's difficult to know actual type of the property from the document, so I added new Vector class as the abstruct class of them. My three.d.ts contains some other quick fixes like that. Currently TypeScript's type system is slightly poor and it will become better. I thought that sometime in the future I might provide more proper documentation.
Thanks.
There is any costs to having long prototype chains on the performance of the small math tyoes? -ben
Nope. A file *.d.ts is only used for type check only in compile time and any additional codes will not be generated.
Yes, three.d.ts is an interface which adds compile-time type information, mostly for TypeScript tools to consume. No JavaScript code gets generated by it.
Given a three.d.ts annotated with jsdoc (or whatever gets supported), the future tooling support would maybe allow for generation of a more complete documentation for three.js.
Crossing fingers ;)