External/OxyPlot/OxyPlot/Foundation/ScreenVector.cs
author Stephane Lenclud
Sat, 30 Jan 2016 23:01:51 +0100
branchMiniDisplay
changeset 454 f84878f52cd9
permissions -rw-r--r--
Disabling Nuvoton NCT6791D because of fan full speed bug on Asus Z97 WS.
     1 // --------------------------------------------------------------------------------------------------------------------
     2 // <copyright file="ScreenVector.cs" company="OxyPlot">
     3 //   The MIT License (MIT)
     4 //
     5 //   Copyright (c) 2012 Oystein Bjorke
     6 //
     7 //   Permission is hereby granted, free of charge, to any person obtaining a
     8 //   copy of this software and associated documentation files (the
     9 //   "Software"), to deal in the Software without restriction, including
    10 //   without limitation the rights to use, copy, modify, merge, publish,
    11 //   distribute, sublicense, and/or sell copies of the Software, and to
    12 //   permit persons to whom the Software is furnished to do so, subject to
    13 //   the following conditions:
    14 //
    15 //   The above copyright notice and this permission notice shall be included
    16 //   in all copies or substantial portions of the Software.
    17 //
    18 //   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    19 //   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    20 //   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    21 //   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    22 //   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    23 //   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    24 //   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    25 // </copyright>
    26 // <summary>
    27 //   Represents a vector defined in the screen coordinate system.
    28 // </summary>
    29 // --------------------------------------------------------------------------------------------------------------------
    30 namespace OxyPlot
    31 {
    32     using System;
    33 
    34     /// <summary>
    35     /// Represents a vector defined in the screen coordinate system.
    36     /// </summary>
    37     public struct ScreenVector
    38     {
    39         /// <summary>
    40         /// The x-coordinate.
    41         /// </summary>
    42         internal double x;
    43 
    44         /// <summary>
    45         /// The y-coordinate.
    46         /// </summary>
    47         internal double y;
    48 
    49         /// <summary>
    50         /// Initializes a new instance of the <see cref="ScreenVector"/> structure.
    51         /// </summary>
    52         /// <param name="x">
    53         /// The x-coordinate.
    54         /// </param>
    55         /// <param name="y">
    56         /// The y-coordinate.
    57         /// </param>
    58         public ScreenVector(double x, double y)
    59         {
    60             this.x = x;
    61             this.y = y;
    62         }
    63 
    64         /// <summary>
    65         /// Gets the length.
    66         /// </summary>
    67         public double Length
    68         {
    69             get
    70             {
    71                 return Math.Sqrt((this.x * this.x) + (this.y * this.y));
    72             }
    73         }
    74 
    75         /// <summary>
    76         /// Gets the length squared.
    77         /// </summary>
    78         public double LengthSquared
    79         {
    80             get
    81             {
    82                 return (this.x * this.x) + (this.y * this.y);
    83             }
    84         }
    85 
    86         /// <summary>
    87         /// Gets or sets the x-coordinate.
    88         /// </summary>
    89         /// <value> The x-coordinate. </value>
    90         public double X
    91         {
    92             get
    93             {
    94                 return this.x;
    95             }
    96 
    97             set
    98             {
    99                 this.x = value;
   100             }
   101         }
   102 
   103         /// <summary>
   104         /// Gets or sets the y-coordinate.
   105         /// </summary>
   106         /// <value> The y-coordinate. </value>
   107         public double Y
   108         {
   109             get
   110             {
   111                 return this.y;
   112             }
   113 
   114             set
   115             {
   116                 this.y = value;
   117             }
   118         }
   119 
   120         /// <summary>
   121         /// Normalizes this vector.
   122         /// </summary>
   123         public void Normalize()
   124         {
   125             double l = Math.Sqrt((this.x * this.x) + (this.y * this.y));
   126             if (l > 0)
   127             {
   128                 this.x /= l;
   129                 this.y /= l;
   130             }
   131         }
   132 
   133         /// <summary>
   134         /// Returns a <see cref="System.String"/> that represents this instance.
   135         /// </summary>
   136         /// <returns>
   137         /// A <see cref="System.String"/> that represents this instance.
   138         /// </returns>
   139         public override string ToString()
   140         {
   141             return this.x + " " + this.y;
   142         }
   143 
   144         /// <summary>
   145         /// Implements the operator *.
   146         /// </summary>
   147         /// <param name="v"> The vector. </param>
   148         /// <param name="d"> The multiplication factor. </param>
   149         /// <returns> The result of the operator. </returns>
   150         public static ScreenVector operator *(ScreenVector v, double d)
   151         {
   152             return new ScreenVector(v.x * d, v.y * d);
   153         }
   154     }
   155 }