【Unity】Mathd系列(三)Double型Vector4

    Vector4,还真不怎么常用,偶尔用过几次而已。既然要写就全写出来吧~

Vector4d:

/// Vector4d.cs
/// 
/// The double type version of the Unity struct Vector4.
/// It can solve the problem that the float type may not be accurate enough.
/// 
/// Unity Vector4结构体的double版实现,以解决float型精度可能不够的问题。
/// 
/// Created by D子宇 on 2018.3.17 
/// 
/// Email: [email protected]
using System;
using UnityEngine;

namespace Mathd
{
    public struct Vector4d
    {
        #region public members

        public double x;
        public double y;
        public double z;
        public double w;

        #endregion

        #region constructor

        public Vector4d(double p_x, double p_y)
        {
            x = p_x;
            y = p_y;
            z = 0;
            w = 0;
        }
        public Vector4d(double p_x, double p_y, double p_z)
        {
            x = p_x;
            y = p_y;
            z = p_z;
            w = 0;
        }
        public Vector4d(double p_x, double p_y, double p_z,double p_w)
        {
            x = p_x;
            y = p_y;
            z = p_z;
            w = p_w;
        }

        #endregion

        #region public properties

        public double this[int index] {
            get
            {
                switch (index)
                {
                    case 0:
                        return x;
                    case 1:
                        return y;
                    case 2:
                        return z;
                    case 3:
                        return w;
                    default:
                        throw new IndexOutOfRangeException("Invalid Vector4d index!");
                }
            }
            set
            {
                switch (index)
                {
                    case 0:
                        x = value;
                        break;
                    case 1:
                        y = value;
                        break;
                    case 2:
                        z = value;
                        break;
                    case 3:
                        w = value;
                        break;
                    default:
                        throw new IndexOutOfRangeException("Invalid Vector4d index!");
                }
            }
        }
        
        public static Vector4d one
        {
            get
            {
                return new Vector4d(1, 1, 1, 1);
            }
        }
        public static Vector4d zero
        {
            get
            {
                return new Vector4d(0, 0, 0, 0);
            }
        }
        public double magnitude
        {
            get
            {
                return Math.Sqrt(sqrMagnitude);
            
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值