Skip to content

Commit

Permalink
Expose classes when compiling to js, and use PolyTools.exposeEnum() t…
Browse files Browse the repository at this point in the history
…o make enums visible from the js side...

also converted CCLabeler's Connectivity abstract to enum
  • Loading branch information
azrafe7 committed Oct 18, 2015
1 parent e192389 commit 23cd173
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 12 deletions.
10 changes: 5 additions & 5 deletions openflDemo.hxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
<class path="C:\HaxeToolkit\haxe\openfl\3,1,0" />
<class path="C:\HaxeToolkit\haxe\lime\git" />
<class path="D:\Downloads\Dev\Haxe\openfl_git" />
<class path="C:\HaxeToolkit\haxe\lime\2,6,7" />
<class path="D:\Downloads\Dev\Haxe\hxPixels_git\src" />
<class path="src" />
<class path="bin\flash\haxe" />
<class path="bin\html5\haxe" />
</classpaths>
<!-- Build options -->
<build>
<option directives="openfl=3.1.0&#xA;lime=2.4.4&#xA;hxPixels=0.0.0&#xA;openfl-next&#xA;tools=2.4.4&#xA;no-compilation&#xA;openfl-flash&#xA;web&#xA;swf-script-timeout=60" />
<option directives="openfl=3.3.6&#xA;lime=2.6.7&#xA;hxPixels=0.0.0&#xA;openfl-next&#xA;tools=2.6.7&#xA;no-compilation&#xA;openfl-html5&#xA;canvas&#xA;lime-html5&#xA;html5&#xA;web&#xA;swf-script-timeout=60&#xA;html5&#xA;display" />
<option flashStrict="False" />
<option noInlineOnDebug="False" />
<option mainClass="ApplicationMain" />
<option enabledebug="True" />
<option additional="-swf-version 11.2&#xA;-debug " />
<option additional="--remap flash:openfl&#xA;--macro allowPackage(&quot;flash&quot;)&#xA;-debug " />
</build>
<!-- haxelib libraries -->
<haxelib>
Expand Down
2 changes: 1 addition & 1 deletion src/GeomAlgoTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ class CustomLabeler extends CCLabeler
{
var pixelInfoMap:Map<Int, PixelInfo>; // cache

public function new(pixels:Pixels, alphaThreshold:Int = 1, traceContours:Bool = true, connectivity:Connectivity = Connectivity.EIGHT_CONNECTED, calcArea:Bool = false)
public function new(pixels:Pixels, alphaThreshold:Int = 1, traceContours:Bool = true, ?connectivity:Connectivity, calcArea:Bool = false)
{
super(pixels, alphaThreshold, traceContours, connectivity, calcArea);

Expand Down
1 change: 1 addition & 0 deletions src/hxGeomAlgo/Bayazit.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import hxGeomAlgo.PolyTools;
using hxGeomAlgo.PolyTools;


@:expose
class Bayazit
{

Expand Down
18 changes: 13 additions & 5 deletions src/hxGeomAlgo/CCLabeler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ import hxGeomAlgo.PolyTools.Poly;
import hxPixels.Pixels;


@:enum abstract Connectivity(Int) {
var FOUR_CONNECTED = 4;
var EIGHT_CONNECTED = 8;
@:expose
enum Connectivity {
FOUR_CONNECTED;
EIGHT_CONNECTED;
}


@:expose
class CCLabeler
{
#if js
static function __init__() {
PolyTools.exposeEnum(Connectivity);
}
#end

/** Minimum alpha value to consider a pixel opaque (in the range 1-255). */
public var alphaThreshold:Int;

Expand Down Expand Up @@ -90,12 +98,12 @@ class CCLabeler
* @param connectivity Type of connectivity to search for (defaults to EIGHT_CONNECTED).
* @param calcArea Whether to compute and store components' area (in areaMap) while labeling.
*/
public function new(pixels:Pixels, alphaThreshold:Int = 1, traceContours:Bool = true, connectivity:Connectivity = Connectivity.EIGHT_CONNECTED, calcArea:Bool = false)
public function new(pixels:Pixels, alphaThreshold:Int = 1, traceContours:Bool = true, ?connectivity:Connectivity, calcArea:Bool = false)
{
setSource(pixels);

this.alphaThreshold = alphaThreshold;
this.connectivity = connectivity;
this.connectivity = connectivity != null ? connectivity : EIGHT_CONNECTED;
this.traceContours = traceContours;
this.calcArea = calcArea;
numComponents = 0;
Expand Down
1 change: 1 addition & 0 deletions src/hxGeomAlgo/EarClipper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import hxGeomAlgo.PolyTools;
typedef Tri = Poly; // assumes Array<HxPoint> of length 3


@:expose
class EarClipper
{

Expand Down
1 change: 1 addition & 0 deletions src/hxGeomAlgo/IsoContours.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import hxPixels.Pixels;
typedef IsoFunction = Pixels->Int->Int->Float;


@:expose
class IsoContours
{

Expand Down
1 change: 1 addition & 0 deletions src/hxGeomAlgo/MarchingSquares.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum StepDirection {
}


@:expose
class MarchingSquares
{
/** Minimum alpha value to consider a pixel opaque (in the range 0-255). */
Expand Down
19 changes: 19 additions & 0 deletions src/hxGeomAlgo/PolyTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import hxGeomAlgo.HxPoint;
typedef Poly = Array<HxPoint>;


@:expose
class PolyTools
{
static private var point:HxPoint = new HxPoint(); // used internally
Expand Down Expand Up @@ -387,4 +388,22 @@ class PolyTools
return [new HxPoint(start.x - ny, start.y + nx), new HxPoint(end.x - ny, end.y + nx),
new HxPoint(end.x + ny, end.y - nx), new HxPoint(start.x + ny, start.y - nx)];
}

/** Used internally to expose enums in js. */
@:noUsing @:noCompletion static public function exposeEnum<T>(enumClass:Enum<T>, ?as:String) {
#if js
var dotPath = (as != null ? as : enumClass.getName()).split(".");
untyped {
var exports = $hx_exports;
var i = 0;
while (i < dotPath.length - 1) {
var currPath = dotPath[i];
exports[currPath] = exports[currPath] || { };
exports = exports[currPath];
i++;
}
exports[dotPath[i]] = enumClass;
}
#end
}
}
1 change: 1 addition & 0 deletions src/hxGeomAlgo/RamerDouglasPeucker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package hxGeomAlgo;

import hxGeomAlgo.PolyTools;

@:expose
class RamerDouglasPeucker
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/hxGeomAlgo/SnoeyinkKeil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import hxGeomAlgo.SnoeyinkKeil.DecompPoly;

using hxGeomAlgo.PolyTools;


@:expose
class SnoeyinkKeil
{

Expand Down
10 changes: 10 additions & 0 deletions src/hxGeomAlgo/Tess2.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import hxGeomAlgo.PolyTools.Poly;
import hxGeomAlgo.Debug;


@:expose
enum WindingRule
{
ODD;
Expand All @@ -61,6 +62,7 @@ enum WindingRule
ABS_GEQ_TWO;
}

@:expose
enum ResultType
{
POLYGONS;
Expand Down Expand Up @@ -91,6 +93,13 @@ typedef TessResult = {
@:expose
class Tess2
{
#if js
static function __init__() {
PolyTools.exposeEnum(WindingRule);
PolyTools.exposeEnum(ResultType);
}
#end

/**
* Tesselates the specified `contours`.
*
Expand Down Expand Up @@ -2974,6 +2983,7 @@ private class Sweep
*
* Further reading: http://www.glprogramming.com/red/chapter11.html
*/
@:expose
class Tesselator
{
/*** state needed for collecting the input data ***/
Expand Down
1 change: 1 addition & 0 deletions src/hxGeomAlgo/Visibility.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum VertexType {
}


@:expose
class Visibility
{
inline static private var NOT_SAVED:Int = -1;
Expand Down
8 changes: 8 additions & 0 deletions src/hxGeomAlgo/VisvalingamWhyatt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ import hxGeomAlgo.Debug;


/** Specifies the method to use in the simplification process. */
@:expose
enum SimplificationMethod {
MaxPoints(n:Int); // Allow max n points (n > 2).
ThresholdArea(a:Float); // Filter out all triangles with area <= a.
Ratio(r:Float); // Retain r ratio of all points (0 < r <= 1).
}


@:expose
class VisvalingamWhyatt
{
#if js
static function __init__() {
PolyTools.exposeEnum(SimplificationMethod);
}
#end

static private var method:SimplificationMethod;
static private var minHeap:Heap<Triangle>;

Expand Down

0 comments on commit 23cd173

Please sign in to comment.