1- // Copyright (c) Microsoft Corporation. All rights reserved.
1+ // Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
44using UnityEngine ;
@@ -14,8 +14,8 @@ namespace HoloToolkit.Examples.GazeRuler
1414 public class PolygonManager : Singleton < PolygonManager > , IGeometry , IPolygonClosable
1515 {
1616 // save all geometries
17- public Stack < Ploygon > Ploygons = new Stack < Ploygon > ( ) ;
18- public Ploygon CurrentPloygon ;
17+ public Stack < Polygon > Polygons = new Stack < Polygon > ( ) ;
18+ public Polygon CurrentPolygon ;
1919
2020 /// <summary>
2121 /// handle new point users place
@@ -32,32 +32,32 @@ public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject T
3232 Position = hitPoint ,
3333 Root = point
3434 } ;
35- if ( CurrentPloygon . IsFinished )
35+ if ( CurrentPolygon . IsFinished )
3636 {
37- CurrentPloygon = new Ploygon ( )
37+ CurrentPolygon = new Polygon ( )
3838 {
3939 IsFinished = false ,
4040 Root = new GameObject ( ) ,
4141 Points = new List < Vector3 > ( )
4242 } ;
4343
44- CurrentPloygon . Points . Add ( newPoint . Position ) ;
45- newPoint . Root . transform . parent = CurrentPloygon . Root . transform ;
44+ CurrentPolygon . Points . Add ( newPoint . Position ) ;
45+ newPoint . Root . transform . parent = CurrentPolygon . Root . transform ;
4646 }
4747 else
4848 {
49- CurrentPloygon . Points . Add ( newPoint . Position ) ;
50- newPoint . Root . transform . parent = CurrentPloygon . Root . transform ;
51- if ( CurrentPloygon . Points . Count > 1 )
49+ CurrentPolygon . Points . Add ( newPoint . Position ) ;
50+ newPoint . Root . transform . parent = CurrentPolygon . Root . transform ;
51+ if ( CurrentPolygon . Points . Count > 1 )
5252 {
53- var index = CurrentPloygon . Points . Count - 1 ;
54- var centerPos = ( CurrentPloygon . Points [ index ] + CurrentPloygon . Points [ index - 1 ] ) * 0.5f ;
55- var direction = CurrentPloygon . Points [ index ] - CurrentPloygon . Points [ index - 1 ] ;
56- var distance = Vector3 . Distance ( CurrentPloygon . Points [ index ] , CurrentPloygon . Points [ index - 1 ] ) ;
53+ var index = CurrentPolygon . Points . Count - 1 ;
54+ var centerPos = ( CurrentPolygon . Points [ index ] + CurrentPolygon . Points [ index - 1 ] ) * 0.5f ;
55+ var direction = CurrentPolygon . Points [ index ] - CurrentPolygon . Points [ index - 1 ] ;
56+ var distance = Vector3 . Distance ( CurrentPolygon . Points [ index ] , CurrentPolygon . Points [ index - 1 ] ) ;
5757 var line = ( GameObject ) Instantiate ( LinePrefab , centerPos , Quaternion . LookRotation ( direction ) ) ;
5858 line . transform . localScale = new Vector3 ( distance , 0.005f , 0.005f ) ;
5959 line . transform . Rotate ( Vector3 . down , 90f ) ;
60- line . transform . parent = CurrentPloygon . Root . transform ;
60+ line . transform . parent = CurrentPolygon . Root . transform ;
6161 }
6262
6363 }
@@ -69,35 +69,35 @@ public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject T
6969 /// </summary>
7070 /// <param name="LinePrefab"></param>
7171 /// <param name="TextPrefab"></param>
72- public void ClosePloygon ( GameObject LinePrefab , GameObject TextPrefab )
72+ public void ClosePolygon ( GameObject LinePrefab , GameObject TextPrefab )
7373 {
74- if ( CurrentPloygon != null )
74+ if ( CurrentPolygon != null )
7575 {
76- CurrentPloygon . IsFinished = true ;
77- var area = CalculatePloygonArea ( CurrentPloygon ) ;
78- var index = CurrentPloygon . Points . Count - 1 ;
79- var centerPos = ( CurrentPloygon . Points [ index ] + CurrentPloygon . Points [ 0 ] ) * 0.5f ;
80- var direction = CurrentPloygon . Points [ index ] - CurrentPloygon . Points [ 0 ] ;
81- var distance = Vector3 . Distance ( CurrentPloygon . Points [ index ] , CurrentPloygon . Points [ 0 ] ) ;
76+ CurrentPolygon . IsFinished = true ;
77+ var area = CalculatePolygonArea ( CurrentPolygon ) ;
78+ var index = CurrentPolygon . Points . Count - 1 ;
79+ var centerPos = ( CurrentPolygon . Points [ index ] + CurrentPolygon . Points [ 0 ] ) * 0.5f ;
80+ var direction = CurrentPolygon . Points [ index ] - CurrentPolygon . Points [ 0 ] ;
81+ var distance = Vector3 . Distance ( CurrentPolygon . Points [ index ] , CurrentPolygon . Points [ 0 ] ) ;
8282 var line = ( GameObject ) Instantiate ( LinePrefab , centerPos , Quaternion . LookRotation ( direction ) ) ;
8383 line . transform . localScale = new Vector3 ( distance , 0.005f , 0.005f ) ;
8484 line . transform . Rotate ( Vector3 . down , 90f ) ;
85- line . transform . parent = CurrentPloygon . Root . transform ;
85+ line . transform . parent = CurrentPolygon . Root . transform ;
8686
8787 var vect = new Vector3 ( 0 , 0 , 0 ) ;
88- foreach ( var point in CurrentPloygon . Points )
88+ foreach ( var point in CurrentPolygon . Points )
8989 {
9090 vect += point ;
9191 }
9292 var centerPoint = vect / ( index + 1 ) ;
93- var direction1 = CurrentPloygon . Points [ 1 ] - CurrentPloygon . Points [ 0 ] ;
93+ var direction1 = CurrentPolygon . Points [ 1 ] - CurrentPolygon . Points [ 0 ] ;
9494 var directionF = Vector3 . Cross ( direction , direction1 ) ;
9595 var tip = ( GameObject ) Instantiate ( TextPrefab , centerPoint , Quaternion . LookRotation ( directionF ) ) ; //anchor.x + anchor.y + anchor.z < 0 ? -1 * anchor : anchor));
9696
9797 // unit is ㎡
9898 tip . GetComponent < TextMesh > ( ) . text = area + "㎡" ;
99- tip . transform . parent = CurrentPloygon . Root . transform ;
100- Ploygons . Push ( CurrentPloygon ) ;
99+ tip . transform . parent = CurrentPolygon . Root . transform ;
100+ Polygons . Push ( CurrentPolygon ) ;
101101 }
102102 }
103103
@@ -106,11 +106,11 @@ public void ClosePloygon(GameObject LinePrefab, GameObject TextPrefab)
106106 /// </summary>
107107 public void Clear ( )
108108 {
109- if ( Ploygons != null && Ploygons . Count > 0 )
109+ if ( Polygons != null && Polygons . Count > 0 )
110110 {
111- while ( Ploygons . Count > 0 )
111+ while ( Polygons . Count > 0 )
112112 {
113- var lastLine = Ploygons . Pop ( ) ;
113+ var lastLine = Polygons . Pop ( ) ;
114114 Destroy ( lastLine . Root ) ;
115115 }
116116 }
@@ -119,9 +119,9 @@ public void Clear()
119119 // delete latest geometry
120120 public void Delete ( )
121121 {
122- if ( Ploygons != null && Ploygons . Count > 0 )
122+ if ( Polygons != null && Polygons . Count > 0 )
123123 {
124- var lastLine = Ploygons . Pop ( ) ;
124+ var lastLine = Polygons . Pop ( ) ;
125125 Destroy ( lastLine . Root ) ;
126126 }
127127 }
@@ -133,7 +133,7 @@ public void Delete()
133133 /// <param name="p2"></param>
134134 /// <param name="p3"></param>
135135 /// <returns></returns>
136- float CalculateTriangleArea ( Vector3 p1 , Vector3 p2 , Vector3 p3 )
136+ private float CalculateTriangleArea ( Vector3 p1 , Vector3 p2 , Vector3 p3 )
137137 {
138138 var a = Vector3 . Distance ( p1 , p2 ) ;
139139 var b = Vector3 . Distance ( p1 , p3 ) ;
@@ -146,22 +146,22 @@ float CalculateTriangleArea(Vector3 p1, Vector3 p2, Vector3 p3)
146146 /// <summary>
147147 /// Calculate an area of geometry
148148 /// </summary>
149- /// <param name="ploygon "></param>
149+ /// <param name="polygon "></param>
150150 /// <returns></returns>
151- float CalculatePloygonArea ( Ploygon ploygon )
151+ private float CalculatePolygonArea ( Polygon polygon )
152152 {
153153 var s = 0.0f ;
154154 var i = 1 ;
155- var n = ploygon . Points . Count ;
155+ var n = polygon . Points . Count ;
156156 for ( ; i < n - 1 ; i ++ )
157- s += CalculateTriangleArea ( ploygon . Points [ 0 ] , ploygon . Points [ i ] , ploygon . Points [ i + 1 ] ) ;
157+ s += CalculateTriangleArea ( polygon . Points [ 0 ] , polygon . Points [ i ] , polygon . Points [ i + 1 ] ) ;
158158 return 0.5f * Mathf . Abs ( s ) ;
159159 }
160160
161161 // Use this for initialization
162- void Start ( )
162+ private void Start ( )
163163 {
164- CurrentPloygon = new Ploygon ( )
164+ CurrentPolygon = new Polygon ( )
165165 {
166166 IsFinished = false ,
167167 Root = new GameObject ( ) ,
@@ -175,10 +175,10 @@ void Start()
175175 /// </summary>
176176 public void Reset ( )
177177 {
178- if ( CurrentPloygon != null && ! CurrentPloygon . IsFinished )
178+ if ( CurrentPolygon != null && ! CurrentPolygon . IsFinished )
179179 {
180- Destroy ( CurrentPloygon . Root ) ;
181- CurrentPloygon = new Ploygon ( )
180+ Destroy ( CurrentPolygon . Root ) ;
181+ CurrentPolygon = new Polygon ( )
182182 {
183183 IsFinished = false ,
184184 Root = new GameObject ( ) ,
@@ -189,7 +189,7 @@ public void Reset()
189189 }
190190
191191
192- public class Ploygon
192+ public class Polygon
193193 {
194194 public float Area { get ; set ; }
195195
0 commit comments