AlecMcE.com

Coding on the Flash Platform

Archive for the ‘voronoi’ tag

Vector – Annoying Naming Conventions

View Comments

When Adobe released the Flash Player 10 last year, it facilitated a new class, a strongly-typed array: Vector.<T>. I suppose we should all be grateful; now we can finally type arrays, leading to more robust code. I don’t feel very grateful, though. Adobe has given me a headache.

In Geometry the word “vector” has a clear meaning: a vector describes a translation in space. To differentiate from other uses of the word, Wikipedia offer the terms Euclidean, Spatial or Geometric Vector. We recognise this use of the word because every single Flash coder understands the distinction between vector graphics and raster (or bitmap) graphics.

I have been working on a Geometric library recently (my as3voronoi library), and have found the need to create an interface to encapsulate a translation in Cartesian space. What will I call it? It’s a vector, but “Vector” is going to cause a lot of headaches, because Adobe’s new Vector class is in the default namespace.

Which leads me to an utterly futile question: why on earth would they call their strongly-typed array class “Vector”? Why not facilitate the strong-typing of Arrays, since Array is the existing term? Untyped Arrays could be considered functionally equivalent to Array.<*> or Array.<Object>. I realise that Adobe cannot change this decision now it has been made, but why did they do it in the first place?

The only answer that I can see is that the vector class is in the C++ standard template library as a one-dimensional array. Was the decision made on the basis that if it’s good enough for C++, then it’s good enough for Flash? I hope not, because the Array class is not like the C++ array, and I don’t see “bitset”, “deque”, “list”, “map”, “queue”, “set”, or “stack” anywhere in the Flash library. Why adopt the C++ convention in just this context?

Flash has a different context to C++. Flash is a word used to describe a player that uses ActionScript and a vector drawing tool rolled into one. Surely the word “vector” has particular significance for the users of Adobe technology?

So what do I call my vector interface? “Vector2D”? “EuclideanVector”? I haven’t called my Polygon interface “Polygon2D” or “EuclideanPolygon”, nor my line interface “Line2D” or “EuclideanLine”. I don’t need to. The terse name does the job perfectly well. If I only target Flash Player 9 I don’t need to call my vector interface anything other than “Vector”.

The headache is unresolved; I am stuck with wanting an array to be an Array and a vector to be a Vector, but will have to accept that an array will be a Vector and a vector … something else.

Written by alec

August 31st, 2009 at 3:39 pm

Voronoi Diagrams – as3voronoi v.0.2

View Comments

I have just posted an update for the as3voronoi library, which I started writing for a pet project of mine, after I became annoyed by the lack of a good open-source library!.

Here is a Delaunay Triangulation, generated by this class:

The Flash plugin is required to view this object.

Here is an incomplete Voronoi Triangulation, generated by this class. It is a first pass because it does not yet handle the closure of the loci of points at the extremities of the point cluster:

A stable working version of the Voronoi tessellation will appear here soon.

Written by alec

August 27th, 2009 at 11:11 pm

Posted in as3,library

Tagged with , ,