Advertisement
Guest User

Untitled

a guest
Oct 8th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. using Pathfinding;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. namespace JustAnotherNamespace
  7. {
  8.     public class BoundsProfile : MonoBehaviour
  9.     {
  10.        
  11.         private bool Intersects (Bounds b1, Bounds b2)     
  12.         {
  13.             Vector3 min1 = b1.min;
  14.             Vector3 max1 = b1.max;
  15.             Vector3 min2 = b2.min;
  16.             Vector3 max2 = b2.max;
  17.             return min1.x <= max2.x && max1.x >= min2.x && min1.y <= max2.y && max1.y >= min2.y && min1.z <= max2.z && max1.z >= min2.z;
  18.         }
  19.        
  20.         public void Start () {
  21.             int seed = UnityEngine.Random.seed;
  22.             Profile prof1 = new Profile("U bounds");
  23.             Profile prof2 = new Profile("U2 bounds");
  24.             for (int test=0;test<10;test++) {
  25.                 int c = 0;
  26.                
  27.                 System.Random rnd = new System.Random(seed);
  28.                 c = 0;
  29.                 prof1.Start();
  30.                 for (int q=0;q<10;q++) {
  31.                     Bounds b1 = new Bounds(rnd.Next(10)*Vector3.one, rnd.Next(10)*Vector3.one);
  32.                     Bounds b2 = new Bounds(rnd.Next(10)*Vector3.one, rnd.Next(10)*Vector3.one);
  33.                     for (int i=0;i<100000;i++) {
  34.                         if (b1.Intersects(b2)) {
  35.                             c++;
  36.                         }
  37.                     }
  38.                 }
  39.                 prof1.Stop(c);
  40.                
  41.                 rnd = new System.Random(seed);
  42.                 c = 0;
  43.                 prof2.Start();
  44.                
  45.                 for (int q=0;q<10;q++) {
  46.                     Bounds b1 = new Bounds(rnd.Next(10)*Vector3.one, rnd.Next(10)*Vector3.one);
  47.                     Bounds b2 = new Bounds(rnd.Next(10)*Vector3.one, rnd.Next(10)*Vector3.one);
  48.                     for (int i=0;i<100000;i++) {
  49.                         if (Intersects(b1,b2)) {
  50.                             c++;
  51.                         }
  52.                     }
  53.                 }
  54.                 prof2.Stop(c);
  55.                
  56.             }
  57.            
  58.             prof1.Log();
  59.             prof2.Log();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement