[longomatch] Move Point class to a different file



commit d40306cd4820eb8d9a8f2ae9b7ee9ddc2e9ebd7b
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Apr 15 22:03:33 2014 +0200

    Move Point class to a different file

 LongoMatch.Core/LongoMatch.Core.mdp                |    3 +-
 LongoMatch.Core/Store/Coordinates.cs               |   59 ++++++++++++++++++++
 .../{Common/Coordinates.cs => Store/Point.cs}      |   59 ++++++--------------
 Tests/Core/TestPoint.cs                            |   32 +++++++++++
 4 files changed, 110 insertions(+), 43 deletions(-)
---
diff --git a/LongoMatch.Core/LongoMatch.Core.mdp b/LongoMatch.Core/LongoMatch.Core.mdp
index 31d48dc..52b6089 100644
--- a/LongoMatch.Core/LongoMatch.Core.mdp
+++ b/LongoMatch.Core/LongoMatch.Core.mdp
@@ -100,7 +100,6 @@
     <File subtype="Code" buildaction="Compile" name="Stats/GameUnitsStats.cs" />
     <File subtype="Code" buildaction="Compile" name="Common/PlaysFilter.cs" />
     <File subtype="Code" buildaction="Compile" name="Interfaces/Multimedia/IRemuxer.cs" />
-    <File subtype="Code" buildaction="Compile" name="Common/Coordinates.cs" />
     <File subtype="Code" buildaction="Compile" name="Interfaces/Multimedia/IVideoConverter.cs" />
     <File subtype="Code" buildaction="Compile" name="Common/SysInfo.cs" />
     <File subtype="Code" buildaction="Compile" name="Interfaces/IDataBaseManager.cs" />
@@ -127,6 +126,8 @@
     <File subtype="Code" buildaction="Compile" name="Store/Drawables/Rectangle.cs" />
     <File subtype="Code" buildaction="Compile" name="Store/Drawables/Selection.cs" />
     <File subtype="Code" buildaction="Compile" name="Store/Drawables/Angle.cs" />
+    <File subtype="Code" buildaction="Compile" name="Store/Coordinates.cs" />
+    <File subtype="Code" buildaction="Compile" name="Store/Point.cs" />
     <File subtype="Code" buildaction="Compile" name="Store/Drawables/Circle.cs" />
   </Contents>
   <References>
diff --git a/LongoMatch.Core/Store/Coordinates.cs b/LongoMatch.Core/Store/Coordinates.cs
new file mode 100644
index 0000000..46df10a
--- /dev/null
+++ b/LongoMatch.Core/Store/Coordinates.cs
@@ -0,0 +1,59 @@
+// 
+//  Copyright (C) 2013 Andoni Morales Alastruey
+// 
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+// 
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//  
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+// 
+using System;
+using System.Collections.Generic;
+
+namespace LongoMatch.Common
+{
+       [Serializable]
+       public class Coordinates: List<Point>
+       {
+               public Coordinates ()
+               {
+               }
+               
+               public override bool Equals (object obj)
+               {
+                       Coordinates c = obj as Coordinates;
+            if (c == null)
+                               return false;
+                               
+                       if (c.Count != Count)
+                               return false;
+                       
+                       for (int i=0; i<Count; i++) {
+                               if (c[i] != this[i])
+                                       return false;
+                       }
+                       return true;
+               }
+               
+               public override int GetHashCode ()
+               {
+                       string s = "";
+                       
+                       for (int i=0; i<Count; i++) {
+                               s += this[i].X.ToString() +  this[i].Y.ToString();
+                       }
+                       
+                       return int.Parse(s);
+               }
+       }
+       
+}
+
diff --git a/LongoMatch.Core/Common/Coordinates.cs b/LongoMatch.Core/Store/Point.cs
similarity index 69%
rename from LongoMatch.Core/Common/Coordinates.cs
rename to LongoMatch.Core/Store/Point.cs
index 5e6f8b9..7871336 100644
--- a/LongoMatch.Core/Common/Coordinates.cs
+++ b/LongoMatch.Core/Store/Point.cs
@@ -1,59 +1,26 @@
-// 
-//  Copyright (C) 2013 Andoni Morales Alastruey
-// 
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
 //  This program is free software; you can redistribute it and/or modify
 //  it under the terms of the GNU General Public License as published by
 //  the Free Software Foundation; either version 2 of the License, or
 //  (at your option) any later version.
-// 
+//
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 //  GNU General Public License for more details.
-//  
+//
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
-// 
+//
+
 using System;
 using System.Collections.Generic;
 
 namespace LongoMatch.Common
 {
-       [Serializable]
-       public class Coordinates: List<Point>
-       {
-               public Coordinates ()
-               {
-               }
-               
-               public override bool Equals (object obj)
-               {
-                       Coordinates c = obj as Coordinates;
-            if (c == null)
-                               return false;
-                               
-                       if (c.Count != Count)
-                               return false;
-                       
-                       for (int i=0; i<Count; i++) {
-                               if (c[i] != this[i])
-                                       return false;
-                       }
-                       return true;
-               }
-               
-               public override int GetHashCode ()
-               {
-                       string s = "";
-                       
-                       for (int i=0; i<Count; i++) {
-                               s += this[i].X.ToString() +  this[i].Y.ToString();
-                       }
-                       
-                       return int.Parse(s);
-               }
-       }
        
        [Serializable]
        public class Point {
@@ -74,7 +41,16 @@ namespace LongoMatch.Common
                }
                
                public double Distance (Point p) {
-                       return Math.Sqrt (Math.Pow (this.X - p.X, 2) - Math.Pow (this.Y - Y, 2));
+                       return Math.Sqrt (Math.Pow (X - p.X, 2) + Math.Pow (Y - p.Y, 2));
+               }
+               
+               public Point Normalize (int width, int height) {
+                       return new Point (Math.Min(X, width) / width,
+                                         Math.Min (Y, height) / height);
+               }
+               
+               public Point Denormalize (int width, int height) {
+                       return new Point (X * width, Y * height);
                }
 
                public override string ToString ()
@@ -105,4 +81,3 @@ namespace LongoMatch.Common
                }
        }
 }
-
diff --git a/Tests/Core/TestPoint.cs b/Tests/Core/TestPoint.cs
index 915e90f..37f44ee 100644
--- a/Tests/Core/TestPoint.cs
+++ b/Tests/Core/TestPoint.cs
@@ -43,6 +43,38 @@ namespace Tests.Core
                        Point p2 = new Point (1, 2);
                        Assert.AreEqual (p1, p2);
                }
+               
+               [Test()]
+               public void TestDistance ()
+               {
+                       Point p1 = new Point (5, 5);
+                       Point p2 = new Point (0, 0);
+                       
+                       Assert.AreEqual (Math.Sqrt (50), p1.Distance (p2));
+                       
+                       p2 = new Point (5, 10);
+                       Assert.AreEqual (5, p1.Distance (p2));
+                       p1 = new Point (2, 10); 
+                       Assert.AreEqual (3, p1.Distance (p2));
+               }
+               
+               [Test()]
+               public void TestNormalize ()
+               {
+                       Point p1 = new Point (3, 5);
+                       Point p2 = p1.Normalize (100, 100);
+                       Assert.AreEqual ((double)p1.X / 100, p2.X);
+                       Assert.AreEqual ((double)p1.Y / 100, p2.Y);
+               }
+               
+               [Test()]
+               public void TestDenormalize ()
+               {
+                       Point p1 = new Point (0.2, 0.5);
+                       Point p2 = p1.Denormalize (100, 100);
+                       Assert.AreEqual ((double)p1.X * 100, p2.X);
+                       Assert.AreEqual ((double)p1.Y * 100, p2.Y);
+               }
 
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]