Sfoglia il codice sorgente

moved h3d.col 2d classes to h2d.col

ncannasse 12 anni fa
parent
commit
4aceff47e9
5 ha cambiato i file con 61 aggiunte e 61 eliminazioni
  1. 15 15
      h2d/col/Bounds.hx
  2. 3 3
      h2d/col/Point.hx
  3. 10 10
      h2d/col/Poly.hx
  4. 11 11
      h2d/col/Seg.hx
  5. 22 22
      h2d/col/Voronoi.hx

+ 15 - 15
h3d/col/Bounds2d.hx → h2d/col/Bounds.hx

@@ -1,6 +1,6 @@
-package h3d.col;
+package h2d.col;
 
-class Bounds2d {
+class Bounds {
 	
 	public var xMin : Float;
 	public var yMin : Float;
@@ -12,35 +12,35 @@ class Bounds2d {
 		empty();
 	}
 	
-	public inline function collide( b : Bounds2d ) {
+	public inline function collide( b : Bounds ) {
 		return !(xMin > b.xMax || yMin > b.yMax || xMax < b.xMin || yMax < b.yMin);
 	}
 	
-	public inline function add( b : Bounds2d ) {
+	public inline function add( b : Bounds ) {
 		if( b.xMin < xMin ) xMin = b.xMin;
 		if( b.xMax > xMax ) xMax = b.xMax;
 		if( b.yMin < yMin ) yMin = b.yMin;
 		if( b.yMax > yMax ) yMax = b.yMax;
 	}
 
-	public inline function addPoint( p : Point2d ) {
+	public inline function addPoint( p : Point ) {
 		if( p.x < xMin ) xMin = p.x;
 		if( p.x > xMax ) xMax = p.x;
 		if( p.y < yMin ) yMin = p.y;
 		if( p.y > yMax ) yMax = p.y;
 	}
 	
-	public inline function setMin( p : Point2d ) {
+	public inline function setMin( p : Point ) {
 		xMin = p.x;
 		yMin = p.y;
 	}
 
-	public inline function setMax( p : Point2d ) {
+	public inline function setMax( p : Point ) {
 		xMax = p.x;
 		yMax = p.y;
 	}
 	
-	public function load( b : Bounds2d ) {
+	public function load( b : Bounds ) {
 		xMin = b.xMin;
 		yMin = b.yMin;
 		xMax = b.xMax;
@@ -59,19 +59,19 @@ class Bounds2d {
 	}
 	
 	public inline function getMin() {
-		return new Point2d(xMin, yMin);
+		return new Point(xMin, yMin);
 	}
 	
 	public inline function getCenter() {
-		return new Point2d((xMin + xMax) * 0.5, (yMin + yMax) * 0.5);
+		return new Point((xMin + xMax) * 0.5, (yMin + yMax) * 0.5);
 	}
 
 	public inline function getSize() {
-		return new Point2d(xMax - xMin, yMax - yMin);
+		return new Point(xMax - xMin, yMax - yMin);
 	}
 	
 	public inline function getMax() {
-		return new Point2d(xMax, yMax);
+		return new Point(xMax, yMax);
 	}
 	
 	public inline function empty() {
@@ -89,7 +89,7 @@ class Bounds2d {
 	}
 	
 	public inline function clone() {
-		var b = new Bounds2d();
+		var b = new Bounds();
 		b.xMin = xMin;
 		b.yMin = yMin;
 		b.xMax = xMax;
@@ -101,8 +101,8 @@ class Bounds2d {
 		return "{" + getMin() + "," + getMax() + "}";
 	}
 	
-	public static inline function fromPoints( min : Point2d, max : Point2d ) {
-		var b = new Bounds2d();
+	public static inline function fromPoints( min : Point, max : Point ) {
+		var b = new Bounds();
 		b.setMin(min);
 		b.setMax(max);
 		return b;

+ 3 - 3
h3d/col/Point2d.hx → h2d/col/Point.hx

@@ -1,6 +1,6 @@
-package h3d.col;
+package h2d.col;
 
-class Point2d {
+class Point {
 	
 	public var x : Float;
 	public var y : Float;
@@ -11,7 +11,7 @@ class Point2d {
 	}
 	
 	public function toString() {
-		return "{" + FMath.fmt(x) + "," + FMath.fmt(y) + "}";
+		return "{" + h3d.FMath.fmt(x) + "," + h3d.FMath.fmt(y) + "}";
 	}
 	
 }

+ 10 - 10
h3d/col/Poly2d.hx → h2d/col/Poly.hx

@@ -1,9 +1,9 @@
-package h3d.col;
+package h2d.col;
 
-class Poly2d {
+class Poly {
 
-	public var points : Array<Point2d>;
-	var segments : Array<Seg2d>;
+	public var points : Array<Point>;
+	var segments : Array<Seg>;
 	
 	public function new( points ) {
 		this.points = points;
@@ -25,20 +25,20 @@ class Poly2d {
 			return segments;
 		segments = [];
 		for( i in 0...points.length ) {
-			var s = new Seg2d(points[i], points[(i + 1) % points.length]);
+			var s = new Seg(points[i], points[(i + 1) % points.length]);
 			segments.push(s);
 		}
 		return segments;
 	}
 	
-	public function hasPoint( p : Point2d ) {
+	public function hasPoint( p : Point ) {
 		for( s in getSegments() )
 			if( s.side(p) < 0 )
 				return false;
 		return true;
 	}
 	
-	public function project( p : Point2d ) : Point2d {
+	public function project( p : Point ) : Point {
 		var dmin = 1e20, smin = null;
 		for( s in getSegments() ) {
 			var d = s.distanceSq(p);
@@ -50,7 +50,7 @@ class Poly2d {
 		return smin.project(p);
 	}
 	
-	public function distanceSq( p : Point2d ) {
+	public function distanceSq( p : Point ) {
 		var dmin = 1e20;
 		for( s in getSegments() ) {
 			var d = s.distanceSq(p);
@@ -59,8 +59,8 @@ class Poly2d {
 		return dmin;
 	}
 	
-	public inline function distance( p : Point2d ) {
-		return FMath.sqrt(distanceSq(p));
+	public inline function distance( p : Point ) {
+		return h3d.FMath.sqrt(distanceSq(p));
 	}
 	
 }

+ 11 - 11
h3d/col/Seg2d.hx → h2d/col/Seg.hx

@@ -1,6 +1,6 @@
-package h3d.col;
+package h2d.col;
 
-class Seg2d {
+class Seg {
 
 	public var x : Float;
 	public var y : Float;
@@ -9,7 +9,7 @@ class Seg2d {
 	public var lenSq : Float;
 	public var invLenSq : Float;
 	
-	public inline function new( p1 : Point2d, p2 : Point2d ) {
+	public inline function new( p1 : Point, p2 : Point ) {
 		x = p1.x;
 		y = p1.y;
 		dx = p2.x - x;
@@ -18,11 +18,11 @@ class Seg2d {
 		invLenSq = 1 / lenSq;
 	}
 	
-	public inline function side( p : Point2d ) {
+	public inline function side( p : Point ) {
 		return dx * (p.y - y) - dy * (p.x - x);
 	}
 	
-	public inline function distanceSq( p : Point2d ) {
+	public inline function distanceSq( p : Point ) {
 		var px = p.x - x;
 		var py = p.y - y;
 		var t = px * dx + py * dy;
@@ -40,21 +40,21 @@ class Seg2d {
 		}
 	}
 
-	public inline function distance( p : Point2d ) {
-		return FMath.sqrt(distanceSq(p));
+	public inline function distance( p : Point ) {
+		return h3d.FMath.sqrt(distanceSq(p));
 	}
 	
-	public inline function project( p : Point2d ) : Point2d {
+	public inline function project( p : Point ) : Point {
 		var px = p.x - x;
 		var py = p.y - y;
 		var t = px * dx + py * dy;
 		return if( t < 0 )
-			new Point2d(x, y);
+			new Point(x, y);
 		else if( t > lenSq )
-			new Point2d(x + dx, y + dy);
+			new Point(x + dx, y + dy);
 		else {
 			var tl2 = t * invLenSq;
-			new Point2d(x + tl2 * dx, y + tl2 * dy);
+			new Point(x + tl2 * dx, y + tl2 * dy);
 		}
 	}
 

+ 22 - 22
h3d/col/Voronoi.hx → h2d/col/Voronoi.hx

@@ -15,7 +15,7 @@
 	Credits: See https://github.com/gorhill/Javascript-Voronoi/CREDITS.md
 	History: See https://github.com/gorhill/Javascript-Voronoi/CHANGELOG.md
 */
-package h3d.col;
+package h2d.col;
 
 // ---------------------------------------------------------------------------
 // Red-Black tree code (based on C version of "rbtree" by Franck Bui-Huu
@@ -321,7 +321,7 @@ private class RBNode<T:RBNode<T>> {
 class Cell {
 	
 	public var id : Int;
-	public var point : Point2d;
+	public var point : Point;
 	public var halfedges : Array<Halfedge>;
 	
 	public function new(id, point) {
@@ -440,12 +440,12 @@ class Cell {
 class Edge {
 
 	public var id : Int;
-	public var lPoint : Point2d;
-	public var rPoint : Point2d;
+	public var lPoint : Point;
+	public var rPoint : Point;
 	public var lCell : Null<Cell>;
 	public var rCell : Null<Cell>;
-	public var va : Null<Point2d>;
-	public var vb : Null<Point2d>;
+	public var va : Null<Point>;
+	public var vb : Null<Point>;
 	
 	public function new(lPoint, rPoint) {
 		this.lPoint = lPoint;
@@ -457,11 +457,11 @@ class Edge {
 
 class Halfedge {
 	
-	public var point : Point2d;
+	public var point : Point;
 	public var edge : Edge;
 	public var angle : Float;
 	
-	public function new(edge, lPoint:Point2d, rPoint:Point2d) {
+	public function new(edge, lPoint:Point, rPoint:Point) {
 		this.point = lPoint;
 		this.edge = edge;
 		// 'angle' is a value to be used for properly sorting the
@@ -500,7 +500,7 @@ class Halfedge {
 
 class Diagram {
 	public var cells : Array<Cell>;
-	public var points : Array<Point2d>;
+	public var points : Array<Point>;
 	public var edges : Array<Edge>;
 	public var execTime : Float;
 	public function new() {
@@ -508,7 +508,7 @@ class Diagram {
 }
 
 private class Beachsection extends RBNode<Beachsection> {
-	public var point : Point2d;
+	public var point : Point;
 	public var edge : Edge;
 	public var circleEvent : CircleEvent;
 	public function new() {
@@ -516,7 +516,7 @@ private class Beachsection extends RBNode<Beachsection> {
 }
 
 private class CircleEvent extends RBNode<CircleEvent> {
-	public var point : Point2d;
+	public var point : Point;
 	public var arc : Beachsection;
 	public var x : Float;
 	public var y : Float;
@@ -528,14 +528,14 @@ private class CircleEvent extends RBNode<CircleEvent> {
 class Voronoi {
 	
 	var beachline : RBTree<Beachsection>;
-	var vertices : Array<Point2d>;
+	var vertices : Array<Point>;
 	var edges : Array<Edge>;
 	var cells : Array<Cell>;
 	var beachsectionJunkyard : Array<Beachsection>;
 	var circleEventJunkyard : Array<CircleEvent>;
 	var circleEvents : RBTree<CircleEvent>;
 	var firstCircleEvent : CircleEvent;
-	var pointCell : Map<Point2d,Cell>;
+	var pointCell : Map<Point,Cell>;
 
 	public function new() {
 		this.vertices = null;
@@ -576,7 +576,7 @@ class Voronoi {
 	inline function lessThanOrEqualWithEpsilon(a:Float,b:Float) return a-b<EPSILON;
 
 	function createVertex(x, y) {
-		var v = new Point2d(x, y);
+		var v = new Point(x, y);
 		this.vertices.push(v);
 		return v;
     }
@@ -635,7 +635,7 @@ class Voronoi {
 	// to avoid new memory allocation. This resulted in a measurable
 	// performance gain.
 
-	function createBeachsection(point:Point2d) {
+	function createBeachsection(point:Point) {
 		var beachsection = this.beachsectionJunkyard.pop();
 		if ( beachsection == null )
 			beachsection = new Beachsection();
@@ -802,7 +802,7 @@ class Voronoi {
 		this.attachCircleEvent(rArc);
     }
 
-	function addBeachsection(point:Point2d) {
+	function addBeachsection(point:Point) {
 		var x = point.x,
 			directrix = point.y;
 
@@ -1084,7 +1084,7 @@ class Voronoi {
 	// return value:
 	//   false: the dangling endpoint couldn't be connected
 	//   true: the dangling endpoint could be connected
-	function connectEdge(edge:Edge, bbox:Bounds2d) {
+	function connectEdge(edge:Edge, bbox:Bounds) {
 		// skip if end point already connected
 		var vb = edge.vb;
 		if (vb != null) {return true;}
@@ -1206,7 +1206,7 @@ class Voronoi {
 	//   http://www.skytopia.com/project/articles/compsci/clipping.html
 	// Thanks!
 	// A bit modified to minimize code paths
-	function clipEdge(edge:Edge, bbox:Bounds2d) {
+	function clipEdge(edge:Edge, bbox:Bounds) {
 		var ax = edge.va.x,
 			ay = edge.va.y,
 			bx = edge.vb.x,
@@ -1286,7 +1286,7 @@ class Voronoi {
 	}
 
 	// Connect/cut edges at bounding box
-	function clipEdges(bbox:Bounds2d) {
+	function clipEdges(bbox:Bounds) {
 		// connect all dangling edges to bounding box
 		// or get rid of them if it can't be done
 		var edges = this.edges,
@@ -1310,7 +1310,7 @@ class Voronoi {
 	// The cells are bound by the supplied bounding box.
 	// Each cell refers to its associated point, and a list
 	// of halfedges ordered counterclockwise.
-	function closeCells(bbox:Bounds2d) {
+	function closeCells(bbox:Bounds) {
 		// prune, order halfedges, then add missing ones
 		// required to close cells
 		var xl = bbox.xMin,
@@ -1380,7 +1380,7 @@ class Voronoi {
 	// ---------------------------------------------------------------------------
 	// Top-level Fortune loop
 
-	static function sortByXY(a:Point2d, b:Point2d) {
+	static function sortByXY(a:Point, b:Point) {
 		var r = b.y - a.y;
 		return r < 0 ? -1 : (r > 0 ? 1 : (b.x > a.x ? 1 : b.x < a.x ? -1 : 0));
 	}
@@ -1389,7 +1389,7 @@ class Voronoi {
 	//   Voronoi points are kept client-side now, to allow
 	//   user to freely modify content. At compute time,
 	//   *references* to points are copied locally.
-	public function compute(points:Array<Point2d>, bbox:Bounds2d) {
+	public function compute(points:Array<Point>, bbox:Bounds) {
 		// to measure execution time
 		var startTime = haxe.Timer.stamp();