Carlos Femmers Blog

Carlos Femmer lives in Lafayette, LA and builds a few solutions for JCLS and Agency Virtual Tours

Slides / Demos from Building Applications with Silverlight 2

April 1, 2008 05:10 by carlos

Thanks to everyone who attended the Acadiana .NET User Group Presentation.

Slides from the presentation

Source for Financial Demo

Source for Controls Demo

I will have a couple of follow up posts to answer some of the questions that came up during the meeting.  Also, I will post the full source for the Deep Zoom demo in a couple of days. 

 


Tags:
Categories: C# | Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

LINQ (Solution to OR Mapping problems?)

May 25, 2006 12:43 by carlos

Nice discussion of the problem and how LINQ provides a "cleaner" solution.

 Carlos


Tags:
Categories: C#
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed

Interfaces with Operator Overloading???

May 25, 2006 09:44 by carlos

Operator overloading makes numerical code much more readable than method calls. It would be nice if we could define operators that acted on interfaces in C#:
For example:

interface IMatrix{
   double this[int row, int column] { get; set; }
   Matrix Add( Matrix other);
   ...
}
 

then define:

   static IMatrix operator+ (IMatrix a, IMatrix b){
      return a.Add(b);
   }
 

The problem is that C# doesn't allow global methods (methods defined outside of a class) or static methods in an interface. This would work if IMatrix was an abstract class, but not as interface.

C++ allows global methods, would this work in C++/CLI?

public interface class IMatrix {
 public:
   property double default[int, int]  {
     double get(int row, int column);
     void set(int row, int column, double value);
   }
   IMatrix^ Add(IMatrix^ other);
   ...
};

 

IMatrix^ operator + (IMatrix^ a, IMatrix^ b){
   return a->Add(b);
}

int main(array<System::String ^> ^args){
   IMatrix^ a = gcnew Matrix(3,3);
   IMatrix^ b = gcnew Matrix(3,3);
   IMatrix^ c = a+b;
   
   return 0;
}
 

Yep it compiles with /clr:safe (no CLS compliant warnings) and runs. Cool, can we now call this from C#? Nope. The problems is that CSC will not compile line 3:

   IMatrix a = new Matrix(3, 3);
   IMatrix b = new Matrix(3, 3);
   IMatrix c = a + b;
 

error: Operator '+' cannot be applied to operands of type 'IMatrix' and 'IMatrix'.
I wonder why this is. The DLL generated by C++/CLI contains the overloaded operator method.

Oh well, guess we cannot go this route.


Tags:
Categories: C#
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Calculate Angle between 2 points using C#

February 20, 2006 11:19 by carlos

I was looking for a function in C# to calculate the angle between two points.  I could not find one online so I decided to post this one.  This is based on code from http://plan.cs.drexel.edu/projects/legorobots/software/angle.c .  I will post the code if anyone is interested.

private void btnCalcAngle_Click(object sender, EventArgs e)

{

double x1 = 0;

double y1 = 0;

double x2 = 5;

double y2 = 5;

MessageBox.Show("Angle between x and y: " + Angle(x1,y1,x2,y2).ToString());

}

public double Angle(double px1, double py1, double px2, double py2)

{

// Negate X and Y values

double pxRes = px2 - px1;

double pyRes = py2 - py1;

double angle = 0.0;

// Calculate the angle

if (pxRes == 0.0)

{

   if (pxRes == 0.0)

         angle = 0.0;

   else if (pyRes > 0.0)          angle = System.Math.PI / 2.0;

   else

         angle = System.Math.PI * 3.0 / 2.0;

}

else if (pyRes == 0.0)

{

   if (pxRes > 0.0)

         angle = 0.0;

   else

         angle = System.Math.PI;

}

else

{

   if (pxRes < 0.0)

         angle = System.Math.Atan(pyRes / pxRes) + System.Math.PI;

   else if (pyRes < 0.0)          angle = System.Math.Atan(pyRes / pxRes) + (2 * System.Math.PI);

   else

         angle = System.Math.Atan(pyRes / pxRes);

}

// Convert to degrees

angle = angle * 180 / System.Math.PI;return angle;

 

}


Tags:
Categories: C#
Actions: E-mail | Permalink | Comments (31) | Comment RSSRSS comment feed