예제 #1
0
 public void IncrementEpochAndVC()
 {
     Epoch = VC.Tick(Mid);
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Updated {VC.ToString()} for {Mid} [Increment]");
     }
 }
예제 #2
0
 public void JoinThenIncrement(VectorClock other)
 {
     JoinEpochAndVC(other);
     IncrementEpochAndVC();
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Updated {VC.ToString()} for {Mid}");
     }
 }
예제 #3
0
 public void JoinEpochAndVC(VectorClock other)
 {
     VC.Max(other);
     Epoch = this.VC.GetComponent(this.Mid);
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Updated {VC.ToString()} for {Mid} [Join {other.ToString()}]");
     }
 }
예제 #4
0
 public MachineState(ulong id, ILogger logger, bool enableLogging)
 {
     this.VC            = new VectorClock(0);
     this.Mid           = (long)id;
     this.Logger        = logger;
     this.EnableLogging = enableLogging;
     this.IncrementEpochAndVC();  // initialize
     Assert(VC.GetComponent(Mid) == Epoch, "Epoch and VC inconsistent!");
     if (EnableLogging)
     {
         Logger.WriteLine($"<VCLog> Created {VC.ToString()} for {Mid}");
     }
 }
예제 #5
0
    void ModuleUpdateAngle()
    {
        Vertex   VtxA       = VA.GetComponent <Vertex>();         // 対象となる点A
        Vertex   VtxB       = VB.GetComponent <Vertex>();         // 対象となる点B
        Vertex   VtxC       = VC.GetComponent <Vertex>();         // 対象となる点C
        float    FinalAngle = Mathf.Abs(ParaA * Mathf.PI / 180f); // 対象となる角
        HypPoint PA         = new HypPoint(VtxA.XY);
        HypPoint PB         = new HypPoint(VtxB.XY);
        HypPoint PC         = new HypPoint(VtxC.XY);
        HypPoint PO         = new HypPoint(0, 0);
        // Bを原点に移す写像を求める。
        HypLine  LA  = HTransform.GetHBisectorOfTwoPoints(PB, PO);
        HypPoint PAA = HTransform.GetInversionAlongHLine(LA, PA);
        HypPoint PCC = HTransform.GetInversionAlongHLine(LA, PC);
        //角ABCを求める
        float DeclineA = Mathf.Atan2(PAA.GetY(), PAA.GetX());
        float DeclineC = Mathf.Atan2(PCC.GetY(), PCC.GetX());
        float AngleAC  = DeclineC - DeclineA;

        if (AngleAC > Mathf.PI)
        {
            AngleAC -= (Mathf.PI * 2f);
        }
        if (AngleAC < -Mathf.PI)
        {
            AngleAC += (Mathf.PI * 2f);
        }
        // 修正する角度をもとめる。
        float error = (AngleAC - FinalAngle) * 0.1f;

        if (AngleAC < 0)
        {
            error = (AngleAC + FinalAngle) * 0.1f;
        }
        //今一度点の取り直し。
        {//線分ABのとりなおし
            PA = new HypPoint(VtxA.XY);
            PB = new HypPoint(VtxB.XY);
            HypPoint PM = HTransform.GetMidPointOfTwoPoint(PA, PB);
            LA = HTransform.GetHBisectorOfTwoPoints(PM, PO);
            HypPoint PPA    = HTransform.GetInversionAlongHLine(LA, PA);
            HypPoint PPB    = HTransform.GetInversionAlongHLine(LA, PB);
            HypPoint NewPPA = HTransform.GetRotationOfPoint(PO, error, PPA);
            HypPoint NewPPB = HTransform.GetRotationOfPoint(PO, error, PPB);
            HypPoint NewPA  = HTransform.GetInversionAlongHLine(LA, NewPPA);
            HypPoint NewPB  = HTransform.GetInversionAlongHLine(LA, NewPPB);
            if (!VtxA.Fixed && NewPA.InWorld())
            {
                VtxA.XY.x = NewPA.GetX();
                VtxA.XY.y = NewPA.GetY();
            }
            if (!VtxB.Fixed && NewPB.InWorld())
            {
                VtxB.XY.x = NewPB.GetX();
                VtxB.XY.y = NewPB.GetY();
            }
        }
        {//線分BCの取り直し
            PC = new HypPoint(VtxC.XY);
            PB = new HypPoint(VtxB.XY);
            HypPoint PM = HTransform.GetMidPointOfTwoPoint(PC, PB);
            LA = HTransform.GetHBisectorOfTwoPoints(PM, PO);
            HypPoint PPC    = HTransform.GetInversionAlongHLine(LA, PC);
            HypPoint PPB    = HTransform.GetInversionAlongHLine(LA, PB);
            HypPoint NewPPC = HTransform.GetRotationOfPoint(PO, -error, PPC);
            HypPoint NewPPB = HTransform.GetRotationOfPoint(PO, -error, PPB);
            HypPoint NewPC  = HTransform.GetInversionAlongHLine(LA, NewPPC);
            HypPoint NewPB  = HTransform.GetInversionAlongHLine(LA, NewPPB);
            if (!VtxC.Fixed && NewPC.InWorld())
            {
                VtxC.XY.x = NewPC.GetX();
                VtxC.XY.y = NewPC.GetY();
            }
            if (!VtxB.Fixed && NewPB.InWorld())
            {
                VtxB.XY.x = NewPB.GetX();
                VtxB.XY.y = NewPB.GetY();
            }
        }
    }
예제 #6
0
 public void ModuleUpdate()
 {
     for (int repeat = 0; repeat < 10; repeat++)
     {
         if (Mode == MODE.ADD_MIDPOINT)
         {
             HypPoint V1    = new HypPoint(VA.GetComponent <Vertex>().XY);
             HypPoint V2    = new HypPoint(VB.GetComponent <Vertex>().XY);
             HypPoint V3    = new HypPoint(VC.GetComponent <Vertex>().XY);
             HypPoint W1    = HTransform.ParallelTransform(V2, V3, V3);
             HypPoint W2    = HTransform.ParallelTransform(V1, V3, V3);
             HypPoint W3    = HTransform.GetMidPointOfTwoPoint(V1, V2);
             float    dist1 = HTransform.GetHDistanceOfTwoPoints(V1, W1);
             float    dist2 = HTransform.GetHDistanceOfTwoPoints(V2, W2);
             float    dist3 = HTransform.GetHDistanceOfTwoPoints(V3, W3);
             HypPoint U1    = HTransform.GetHMoveAlongTwoPoints(V1, W1, dist1 * 0.1f);
             HypPoint U2    = HTransform.GetHMoveAlongTwoPoints(V2, W2, dist2 * 0.1f);
             HypPoint U3    = HTransform.GetHMoveAlongTwoPoints(V3, W3, dist3 * 0.1f);
             //if (!U1.InWorld() || !U2.InWorld() || !U3.InWorld())
             //{
             //    V1.Println("V1:");
             //    V2.Println("V2:");
             //    V3.Println("V3:");
             //    W1.Println("W1:");
             //    Debug.Log("dist1:" + dist1);
             //    U1.Println("U1:");
             //}
             if (U1.InWorld() && U2.InWorld() && U3.InWorld())
             {
                 if (!VA.GetComponent <Vertex>().Fixed)
                 {
                     VA.GetComponent <Vertex>().XY.x = U1.GetX();
                     VA.GetComponent <Vertex>().XY.y = U1.GetY();
                 }
                 if (!VB.GetComponent <Vertex>().Fixed)
                 {
                     VB.GetComponent <Vertex>().XY.x = U2.GetX();
                     VB.GetComponent <Vertex>().XY.y = U2.GetY();
                 }
                 if (!VC.GetComponent <Vertex>().Fixed)
                 {
                     VC.GetComponent <Vertex>().XY.x = U3.GetX();
                     VC.GetComponent <Vertex>().XY.y = U3.GetY();
                 }
             }
         }
         else if (Mode == MODE.POINT_TO_POINT)
         {
             if (VA != null && VB != null)
             {
                 Vector2 V1    = VA.GetComponent <Vertex>().XY;
                 Vector2 V2    = VB.GetComponent <Vertex>().XY;
                 Vector2 NewV1 = 0.75f * V1 + 0.25f * V2;
                 Vector2 NewV2 = 0.25f * V1 + 0.75f * V2;
                 if (!VA.GetComponent <Vertex>().Fixed)
                 {
                     VA.GetComponent <Vertex>().XY = NewV1;
                 }
                 if (!VB.GetComponent <Vertex>().Fixed)
                 {
                     VB.GetComponent <Vertex>().XY = NewV2;
                 }
             }
         }
         else if (Mode == MODE.POINT_TO_LINE)
         {
             if (VA != null && VB != null)
             {
                 ModuleUpdatePointToLine2();
             }
         }
         else if (Mode == MODE.POINT_TO_CIRCLE)
         {
             if (VA != null && VB != null)
             {
                 ModuleUpdatePointToCircle();
             }
         }
         else if (Mode == MODE.ISOMETRY)
         {
             if (VA != null && VB != null)
             {
                 ModuleUpdateIsometry();
             }
         }
         else if (Mode == MODE.PERPENDICULAR)
         {
             if (VA != null && VB != null)
             {
                 ModuleUpdatePerpendicular();
             }
         }
         else if (Mode == MODE.ANGLE)
         {
             if (VA != null && VB != null && VC != null)
             {
                 ModuleUpdateAngle();
             }
         }
         else if (Mode == MODE.TANGENT_C2L)
         {
             if (VA != null && VB != null)
             {
                 ModuleUpdateTangentCircleToLine();
             }
         }
         else if (Mode == MODE.TANGENT_C2C)
         {
             if (VA != null && VB != null)
             {
                 HCircle hcircle1 = VA.GetComponent <HCircle>(); //対象となる円1
                 HCircle hcircle2 = VB.GetComponent <HCircle>(); //対象となる円2
                 if (hcircle1 != null && hcircle2 != null)
                 {
                     HypCircle C1 = hcircle1.HCR;
                     HypCircle C2 = hcircle2.HCR;
                     HypPoint  P1 = new HypPoint(hcircle1.VA.GetComponent <Vertex>().XY);
                     HypPoint  P2 = new HypPoint(hcircle2.VA.GetComponent <Vertex>().XY);
                     //HypLine L1 = HTransform.GetHLineThruTwoPoints(P1,P2);
                     float dist     = HTransform.GetHDistanceOfTwoPoints(P1, P2);
                     float errorOut = dist - (C1.HR + C2.HR);
                     float errorIn  = dist - Mathf.Abs(C1.HR - C2.HR);
                     if (Mathf.Abs(errorOut) < Mathf.Abs(errorIn))
                     {// 外接と思われる
                         float error = errorOut * 0.1f;
                         //円C1を寄せる
                         HypPoint P3  = HTransform.GetHMoveAlongTwoPoints(P1, P2, error);
                         Vertex   C1V = hcircle1.VA.GetComponent <Vertex>();
                         if (!C1V.Fixed && P3.InWorld())
                         {
                             C1V.XY.x = P3.GetX();
                             C1V.XY.y = P3.GetY();
                         }
                         //円C1の半径を調節する。
                         C1.HR += error;
                         //円C2を寄せる
                         HypPoint P4  = HTransform.GetHMoveAlongTwoPoints(P2, P1, error);
                         Vertex   C2V = hcircle2.VA.GetComponent <Vertex>();
                         if (!C2V.Fixed && P4.InWorld())
                         {
                             C2V.XY.x = P4.GetX();
                             C2V.XY.y = P4.GetY();
                         }
                         //円C2の半径を調節する。
                         C2.HR += error;
                     }
                     else
                     {//内接と思われる
                         float error = errorIn * 0.1f;
                         bool  C1Out = false;
                         if (C1.HR > C2.HR)
                         {// C1が外側と思われる
                             C1Out = true;
                         }
                         //円C1を寄せる
                         HypPoint P3  = HTransform.GetHMoveAlongTwoPoints(P1, P2, error);
                         Vertex   C1V = hcircle1.VA.GetComponent <Vertex>();
                         if (!C1V.Fixed && P3.InWorld())
                         {
                             C1V.XY.x = P3.GetX();
                             C1V.XY.y = P3.GetY();
                         }
                         if (C1Out)
                         {
                             C1.HR += error;
                         }
                         else
                         {
                             C1.HR -= error;
                         }
                         //円C2を寄せる
                         HypPoint P4  = HTransform.GetHMoveAlongTwoPoints(P2, P1, error);
                         Vertex   C2V = hcircle2.VA.GetComponent <Vertex>();
                         if (!C2V.Fixed && P4.InWorld())
                         {
                             C2V.XY.x = P4.GetX();
                             C2V.XY.y = P4.GetY();
                         }
                         //円C2の半径を調節する。
                         if (C1Out)
                         {
                             C2.HR -= error;
                         }
                         else
                         {
                             C2.HR += error;
                         }
                     }
                 }
             }
         }
     }
 }