External/OxyPlot/OxyPlot/Foundation/ScreenVector.cs
changeset 391 5be8f2773237
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/External/OxyPlot/OxyPlot/Foundation/ScreenVector.cs	Sat Jun 08 16:53:22 2013 +0000
     1.3 @@ -0,0 +1,155 @@
     1.4 +// --------------------------------------------------------------------------------------------------------------------
     1.5 +// <copyright file="ScreenVector.cs" company="OxyPlot">
     1.6 +//   The MIT License (MIT)
     1.7 +//
     1.8 +//   Copyright (c) 2012 Oystein Bjorke
     1.9 +//
    1.10 +//   Permission is hereby granted, free of charge, to any person obtaining a
    1.11 +//   copy of this software and associated documentation files (the
    1.12 +//   "Software"), to deal in the Software without restriction, including
    1.13 +//   without limitation the rights to use, copy, modify, merge, publish,
    1.14 +//   distribute, sublicense, and/or sell copies of the Software, and to
    1.15 +//   permit persons to whom the Software is furnished to do so, subject to
    1.16 +//   the following conditions:
    1.17 +//
    1.18 +//   The above copyright notice and this permission notice shall be included
    1.19 +//   in all copies or substantial portions of the Software.
    1.20 +//
    1.21 +//   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    1.22 +//   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.23 +//   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.24 +//   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    1.25 +//   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.26 +//   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.27 +//   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    1.28 +// </copyright>
    1.29 +// <summary>
    1.30 +//   Represents a vector defined in the screen coordinate system.
    1.31 +// </summary>
    1.32 +// --------------------------------------------------------------------------------------------------------------------
    1.33 +namespace OxyPlot
    1.34 +{
    1.35 +    using System;
    1.36 +
    1.37 +    /// <summary>
    1.38 +    /// Represents a vector defined in the screen coordinate system.
    1.39 +    /// </summary>
    1.40 +    public struct ScreenVector
    1.41 +    {
    1.42 +        /// <summary>
    1.43 +        /// The x-coordinate.
    1.44 +        /// </summary>
    1.45 +        internal double x;
    1.46 +
    1.47 +        /// <summary>
    1.48 +        /// The y-coordinate.
    1.49 +        /// </summary>
    1.50 +        internal double y;
    1.51 +
    1.52 +        /// <summary>
    1.53 +        /// Initializes a new instance of the <see cref="ScreenVector"/> structure.
    1.54 +        /// </summary>
    1.55 +        /// <param name="x">
    1.56 +        /// The x-coordinate.
    1.57 +        /// </param>
    1.58 +        /// <param name="y">
    1.59 +        /// The y-coordinate.
    1.60 +        /// </param>
    1.61 +        public ScreenVector(double x, double y)
    1.62 +        {
    1.63 +            this.x = x;
    1.64 +            this.y = y;
    1.65 +        }
    1.66 +
    1.67 +        /// <summary>
    1.68 +        /// Gets the length.
    1.69 +        /// </summary>
    1.70 +        public double Length
    1.71 +        {
    1.72 +            get
    1.73 +            {
    1.74 +                return Math.Sqrt((this.x * this.x) + (this.y * this.y));
    1.75 +            }
    1.76 +        }
    1.77 +
    1.78 +        /// <summary>
    1.79 +        /// Gets the length squared.
    1.80 +        /// </summary>
    1.81 +        public double LengthSquared
    1.82 +        {
    1.83 +            get
    1.84 +            {
    1.85 +                return (this.x * this.x) + (this.y * this.y);
    1.86 +            }
    1.87 +        }
    1.88 +
    1.89 +        /// <summary>
    1.90 +        /// Gets or sets the x-coordinate.
    1.91 +        /// </summary>
    1.92 +        /// <value> The x-coordinate. </value>
    1.93 +        public double X
    1.94 +        {
    1.95 +            get
    1.96 +            {
    1.97 +                return this.x;
    1.98 +            }
    1.99 +
   1.100 +            set
   1.101 +            {
   1.102 +                this.x = value;
   1.103 +            }
   1.104 +        }
   1.105 +
   1.106 +        /// <summary>
   1.107 +        /// Gets or sets the y-coordinate.
   1.108 +        /// </summary>
   1.109 +        /// <value> The y-coordinate. </value>
   1.110 +        public double Y
   1.111 +        {
   1.112 +            get
   1.113 +            {
   1.114 +                return this.y;
   1.115 +            }
   1.116 +
   1.117 +            set
   1.118 +            {
   1.119 +                this.y = value;
   1.120 +            }
   1.121 +        }
   1.122 +
   1.123 +        /// <summary>
   1.124 +        /// Normalizes this vector.
   1.125 +        /// </summary>
   1.126 +        public void Normalize()
   1.127 +        {
   1.128 +            double l = Math.Sqrt((this.x * this.x) + (this.y * this.y));
   1.129 +            if (l > 0)
   1.130 +            {
   1.131 +                this.x /= l;
   1.132 +                this.y /= l;
   1.133 +            }
   1.134 +        }
   1.135 +
   1.136 +        /// <summary>
   1.137 +        /// Returns a <see cref="System.String"/> that represents this instance.
   1.138 +        /// </summary>
   1.139 +        /// <returns>
   1.140 +        /// A <see cref="System.String"/> that represents this instance.
   1.141 +        /// </returns>
   1.142 +        public override string ToString()
   1.143 +        {
   1.144 +            return this.x + " " + this.y;
   1.145 +        }
   1.146 +
   1.147 +        /// <summary>
   1.148 +        /// Implements the operator *.
   1.149 +        /// </summary>
   1.150 +        /// <param name="v"> The vector. </param>
   1.151 +        /// <param name="d"> The multiplication factor. </param>
   1.152 +        /// <returns> The result of the operator. </returns>
   1.153 +        public static ScreenVector operator *(ScreenVector v, double d)
   1.154 +        {
   1.155 +            return new ScreenVector(v.x * d, v.y * d);
   1.156 +        }
   1.157 +    }
   1.158 +}
   1.159 \ No newline at end of file