dotgnu-pnet-commits
[Top][All Lists]
Advanced

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

[Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing/Toolkit ToolkitGraphi


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Drawing/Toolkit ToolkitGraphicsBase.cs,1.3,1.4
Date: Thu, 12 Jun 2003 05:53:40 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Drawing/Toolkit
In directory subversions:/tmp/cvs-serv4321/System.Drawing/Toolkit

Modified Files:
        ToolkitGraphicsBase.cs 
Log Message:
Bezier drawing algorithm


Index: ToolkitGraphicsBase.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Drawing/Toolkit/ToolkitGraphicsBase.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ToolkitGraphicsBase.cs      12 Jun 2003 02:55:48 -0000      1.3
--- ToolkitGraphicsBase.cs      12 Jun 2003 09:53:38 -0000      1.4
***************
*** 268,278 ****
        public abstract void FillPolygon(Point[] points, FillMode fillMode);
  
        // Draw a bezier curve using the current pen.
-       [TODO]
        public virtual void DrawBezier(int x1, int y1, int x2, int y2,
                                                                   int x3, int 
y3, int x4, int y4)
                        {
!                               // TODO: implement a default bezier drawing 
algorithm
!                               // for systems that don't have their own.
                        }
  
--- 268,332 ----
        public abstract void FillPolygon(Point[] points, FillMode fillMode);
  
+       private static Point ComputePoint(float u,
+                                                                               
int x1, int y1,
+                                                                               
int x2, int y2,
+                                                                               
int x3, int y3,
+                                                                               
int x4, int y4)
+               {
+                       float px=0;
+                       float py=0;
+                       float blend;
+                       float u2=(1.0f-u);
+ 
+                       // Point 0
+                       blend = u2*u2*u2;
+                       px += blend * x1;
+                       py += blend * y1;
+ 
+                       // Point 1
+                       blend = 3 * u * u2 * u2;
+                       px += blend * x2;
+                       py += blend * y2;
+ 
+                       // Point 2
+                       blend = 3 * u * u * u2;
+                       px += blend * x3;
+                       py += blend * y3;
+ 
+                       // Point 3
+                       blend = u * u * u;
+                       px += blend * x4;
+                       py += blend * y4;
+ 
+                       return new 
Point((int)Math.Round(px),(int)Math.Round(py));
+               }
+ 
+       private int ComputeSteps(int x1, int y1, int x2, int y2, int x3,
+                                                               int y3, int x4, 
int y4)
+               {
+                       double length=0L;
+                       
+                       length+=Math.Sqrt((x1-x2)*(x1-x2) + (y1-y2) * (y1-y2));
+                       length+=Math.Sqrt((x2-x3)*(x2-x3) + (y2-y3) * (y2-y3));
+                       length+=Math.Sqrt((x3-x4)*(x3-x3) + (y3-y3) * (y3-y3));
+ 
+                       return (int)Math.Ceiling(length);       
+               }
+       
        // Draw a bezier curve using the current pen.
        public virtual void DrawBezier(int x1, int y1, int x2, int y2,
                                                                   int x3, int 
y3, int x4, int y4)
                        {
!                               int steps=ComputeSteps(x1,y1,x2,y2,x3,y3,x4,y4);
!                               Point [] points=new Point[steps];
!                               for(int i=0;i<steps;i++)
!                               {
!                                       float coeff=((float)i+1)/steps;
!                                       points[i]=ComputePoint(coeff , x1, y1, 
x2,y2,
!                                                                               
        x3,y3,x4,y4);
!                               }
!                               // TODO: Optimize this to plot points without 
!                               // involving line-drawing operations
!                               DrawLines(points);
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]