Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorModel/BasicTypes/SvgPoint.cs @ 12762

Last change on this file since 12762 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 2.6 KB
Line 
1// <developer>niklas@protocol7.com</developer>
2// <developer>kevin@kevlindev.com</developer>
3// <completed>100</completed>
4
5using System;
6
7namespace SharpVectors.Dom.Svg
8{
9  /// <summary>
10  /// Many of the SVG DOM interfaces refer to objects of class SvgPoint.
11  /// An SvgPoint is an (x,y) coordinate pair. When used in matrix
12  /// operations, an SvgPoint is treated as a vector of the form:
13  ///     [x]
14  ///     [y]
15  ///     [1]
16  /// </summary>
17    public sealed class SvgPoint : ISvgPoint
18  {
19    #region Fields
20
21    private double x;
22    private double y;
23   
24        #endregion
25   
26    #region Constructor
27
28    public SvgPoint(double x, double y)
29    {
30      this.x = x;
31      this.y = y;
32    }
33
34    #endregion
35
36        #region ISvgPoint Members
37
38        public double X
39    {
40      get { return x; }
41      set { x = value; }
42    }
43
44        public double Y
45    {
46      get { return y; }
47      set { y = value; }
48    }
49
50    public ISvgPoint MatrixTransform(ISvgMatrix matrix)
51    {
52      return new SvgPoint(matrix.A*x + matrix.C*y + matrix.E,
53                matrix.B*x + matrix.D*y + matrix.F);
54    }
55
56    #endregion
57
58        #region Additional operators
59
60        public SvgPoint lerp(SvgPoint that, double percent)         {
61            return new SvgPoint(
62                this.x + (that.x - this.x)*percent,
63                this.y + (that.y - this.y)*percent
64            );
65        }
66
67        public static SvgPoint operator+(SvgPoint a, SvgPoint b)
68        {
69            return new SvgPoint(
70                a.x + b.x,
71                a.y + b.y
72            );
73        }
74
75        public static SvgPoint operator-(SvgPoint a, SvgPoint b)
76        {
77            return new SvgPoint(
78                a.x - b.x,
79                a.y - b.y
80            );
81        }
82
83        public static SvgPoint operator*(SvgPoint a, double scalar)
84        {
85            return new SvgPoint(
86                a.x * scalar,
87                a.y * scalar
88            );
89        }
90
91        public static SvgPoint operator*(double scalar, SvgPoint a)
92        {
93            return new SvgPoint(
94                scalar * a.x,
95                scalar * a.y
96            );
97        }
98       
99        public static SvgPoint operator/(SvgPoint a, double scalar)
100        {
101            return new SvgPoint(
102                a.x / scalar,
103                a.y / scalar
104                );
105        }
106
107        public static SvgPoint operator/(double scalar, SvgPoint a)
108        {
109            return new SvgPoint(
110                scalar / a.x,
111                scalar / a.y
112                );
113        }
114
115        #endregion
116  }
117}
Note: See TracBrowser for help on using the repository browser.