扩展和重载 MS 和点类型
我是否可以创建自己的点和向量类型来重载它们?为什么这不起作用?
namespace System . windows
{
public partial struct Point : IFormattable
{
public static Point operator * ( Point P , double D )
{
Point Po = new Point ( );
return Po;
}
}
}
namespace SilverlightApplication36
{
public partial class MainPage : UserControl
{
public static void ShrinkingRectangle ( WriteableBitmap wBM , int x1 , int y1 , int x2 , int y2 , Color C )
{
wBM . DrawRectangle ( x1 , y1 , x2 , y2 , Colors . Red );
Point Center = Mean ( x1 , y1 , x2 , y2 );
wBM . SetPixel ( Center , Colors.Blue , 3 );
Point P1 = new Point ( x1 , y1 );
Point P2 = new Point ( x1 , y2 );
Point P3 = new Point ( x1 , y2 );
Point P4 = new Point ( x2 , y1 );
const int Steps = 10;
for ( int i = 0 ; i < Steps ; i++ )
{
double iF = (double)(i+1) / (double)Steps;
double jF = ( 1.0 - iF );
Point P11 = **P1 * jF;**
}
}
Do I have make my own Point and Vector types to overload them ? Why does this not work ?
namespace System . windows
{
public partial struct Point : IFormattable
{
public static Point operator * ( Point P , double D )
{
Point Po = new Point ( );
return Po;
}
}
}
namespace SilverlightApplication36
{
public partial class MainPage : UserControl
{
public static void ShrinkingRectangle ( WriteableBitmap wBM , int x1 , int y1 , int x2 , int y2 , Color C )
{
wBM . DrawRectangle ( x1 , y1 , x2 , y2 , Colors . Red );
Point Center = Mean ( x1 , y1 , x2 , y2 );
wBM . SetPixel ( Center , Colors.Blue , 3 );
Point P1 = new Point ( x1 , y1 );
Point P2 = new Point ( x1 , y2 );
Point P3 = new Point ( x1 , y2 );
Point P4 = new Point ( x2 , y1 );
const int Steps = 10;
for ( int i = 0 ; i < Steps ; i++ )
{
double iF = (double)(i+1) / (double)Steps;
double jF = ( 1.0 - iF );
Point P11 = **P1 * jF;**
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我真的不明白你想用这一行实现什么:
如果你尝试为其供电,请使用
Math.Pow
函数。更新
您应该在结构中有一个表示您的值的内部字段,然后实现该运算符就非常容易。
至于
IFormattable
,我并没有真正测试我所写的内容,我只是从此处 为您提供想法:I don't really understand what you're trying to achieve with this line:
If you try to power it then use the
Math.Pow
function.Update
You should have an internal field in the structure that represents your values, then implementing the operator is very easy.
As for the
IFormattable
, I didn't really test what I am writing, I just copied the code from here to give you the idea: