package edu.agh.tunev.ui;

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Random;
import java.util.Vector;

import edu.agh.tunev.model.PersonProfile;
import edu.agh.tunev.world.Obstacle;

final class PeopleFactory {

	static Random rng = new Random();

	static Vector<PersonProfile> random(int num, Point2D.Double maxPosition,
			Vector<Obstacle> obstacles) {
		Vector<PersonProfile> r = new Vector<PersonProfile>();
		Vector<Rectangle2D.Double> obstacleRectangles = new Vector<Rectangle2D.Double>();

		for (Obstacle o : obstacles) {
			final double x = Math.min(o.p1.x, o.p2.x);
			final double y = Math.min(o.p1.y, o.p2.y);
			final double w = Math.abs(o.p2.x - o.p1.x);
			final double h = Math.abs(o.p2.y - o.p1.y);
			obstacleRectangles.add(new Rectangle2D.Double(x, y, w, h));
		}

		for (int i = 0; i < num; i++) {
			Point2D.Double p;
			boolean insideAnyObstacle;
			do {
				p = new Point2D.Double(rng.nextDouble() * maxPosition.x,
						rng.nextDouble() * maxPosition.y);
				insideAnyObstacle = false;
				for (Rectangle2D.Double rect : obstacleRectangles)
					if (rect.contains(p)) {
						insideAnyObstacle = true;
						break;
					}
			} while (insideAnyObstacle);
			r.add(new PersonProfile(p));
		}

		return r;
	}

	private PeopleFactory() {
	}

}

@@ -54,42 +54,8 @@
 2D;%0A
-import java.awt.geom.Rectangle2D;%0A
 impo
@@ -75,16 +75,16 @@
 Random;%0A
+
 import j
@@ -413,379 +413,8 @@
 %3E();
-%0A%09%09Vector%3CRectangle2D.Double%3E obstacleRectangles = new Vector%3CRectangle2D.Double%3E();%0A%0A%09%09for (Obstacle o : obstacles) %7B%0A%09%09%09final double x = Math.min(o.p1.x, o.p2.x);%0A%09%09%09final double y = Math.min(o.p1.y, o.p2.y);%0A%09%09%09final double w = Math.abs(o.p2.x - o.p1.x);%0A%09%09%09final double h = Math.abs(o.p2.y - o.p1.y);%0A%09%09%09obstacleRectangles.add(new Rectangle2D.Double(x, y, w, h));%0A%09%09%7D
 %0A%0A%09%09
@@ -650,31 +650,18 @@
 or (
-Rectangle2D.Double rect
+Obstacle o
  : o
@@ -671,17 +671,8 @@
 acle
-Rectangle
 s)%0A%09
@@ -683,12 +683,9 @@
 if (
-rect
+o
 .con
@@ -829,18 +829,645 @@
 turn r;%0A
-
 %09%7D
+%0A%09%0A%09/*%0A%09 * metoda generacji z poprzedniego modelu (kkm)%0A%09 * %0A%09public void initAgents() %7B%0A%09%09for (Obstacle ob : obstacles) %7B%0A%09%09%09Point start = ob.getStartPoint();%0A%09%09%09Point end = ob.getEndPoint();%0A%09%09%09double veh_len = end.y - start.y;%0A%09%09%09int passengers = rng.nextInt(3) + 1;%0A%0A%09%09%09for (int i = 0; i %3C passengers; ++i) %7B%0A%09%09%09%09Point coord = (i %25 2 == 0) ? new Point(start.x - 2%0A%09%09%09%09%09%09* Agent.BROADNESS, start.y + (i / 2) * (veh_len / 2)%0A%09%09%09%09%09%09+ 2 * Agent.BROADNESS) : new Point(end.x + 2%0A%09%09%09%09%09%09* Agent.BROADNESS, start.y + (i / 2) * (veh_len / 2)%0A%09%09%09%09%09%09+ 2 * Agent.BROADNESS);%0A%09%09%09%09agents.add(new Agent(this, coord));%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09 *%0A%09 */
 %0A%0A%09priva

Fix PeopleFactory; copy generation method from the old model