コード例 #1
0
ファイル: FigureTest.cs プロジェクト: rajeshwarn/MochaNote
        public void TestNodeToEdgeRelation()
        {
            var node = new SimpleRect();
            var edge = new LineEdge();

            Assert.AreEqual(0, node.Outgoings.Count);
            Assert.AreEqual(0, node.Incomings.Count);
            Assert.AreEqual(null, edge.Source);
            Assert.AreEqual(null, edge.Target);

            edge.Source = node;
            Assert.AreEqual(1, node.Outgoings.Count);
            Assert.AreEqual(node, edge.Source);

            node.Outgoings.Remove(edge);
            Assert.AreEqual(0, node.Outgoings.Count);
            Assert.AreEqual(null, edge.Source);

            node.Incomings.Add(edge);
            Assert.AreEqual(1, node.Incomings.Count);
            Assert.AreEqual(node, edge.Target);

            edge.Target = null;
            Assert.AreEqual(0, node.Outgoings.Count);
            Assert.AreEqual(null, edge.Source);
        }
コード例 #2
0
        public void TestEdge()
        {
            var fig1 = new LineEdge();
            var fig2 = new LineEdge();
            var fig3 = new LineEdge();

            TestStructure(fig1, fig2, fig3);
        }
コード例 #3
0
    public List <Intersection> Intersect(LineEdge target, LineEdge tool)
    {
        var res = new List <Intersection>();

        // intersect corresponding lines. 1 or zero intersections
        var target_data = target.Data;
        var tool_data   = tool.Data;

        Vector2R target_p0 = new Vector2R(target_data.p0);
        Vector2R target_p1 = new Vector2R(target_data.p1);

        Vector2R tool_p0 = new Vector2R(tool_data.p0);
        Vector2R tool_p1 = new Vector2R(tool_data.p1);

        Vector2R dir1 = target_p1 - target_p0;
        Vector2R dir2 = tool_p1 - tool_p0;

        if (dir1.SqrMagnitude == Rational.FromLong(0) ||
            dir2.SqrMagnitude == Rational.FromLong(0))       // one vector is degenerate
        {
            return(res);
        }

        if (Vector2R.Cross(dir1, dir2) == new Rational(0))       // parallel or collinear
        {
            return(res);
        }

        Rational target_t = Vector2R.Cross(tool_p0 - target_p0, dir2 / Vector2R.Cross(dir1, dir2));
        Rational tool_t   = Vector2R.Cross(target_p0 - tool_p0, dir1 / Vector2R.Cross(dir2, dir1));

        if (target_t >= Rational.FromLong(0) && target_t <= Rational.FromLong(1) &&
            tool_t >= Rational.FromLong(0) && tool_t <= Rational.FromLong(1))
        {
            if (!target.Sense)
            {
                target_t = Rational.FromLong(1) - target_t;
            }
            if (!tool.Sense)
            {
                tool_t = Rational.FromLong(1) - tool_t;
            }

            Intersection i = new Intersection
            {
                face_edge_param  = target_t,
                cut_param        = tool_t,
                tool_edge_enters = Vector2R.TestLeftHemiplane(dir2, dir1) == (target.Sense == tool.Sense)
            };
            res.Add(i);
        }

        return(res);
    }
コード例 #4
0
        public void TestMoveEdge()
        {
            var edge = new LineEdge();

            edge.First = new Point(100, 100);
            edge.Last  = new Point(200, 200);
            Assert.AreEqual(new Rectangle(new Point(100, 100), new Size(100, 100)), edge.Bounds);

            edge.Location = new Point(300, 300);
            Assert.AreEqual(new Rectangle(new Point(300, 300), new Size(100, 100)), edge.Bounds);
        }
コード例 #5
0
ファイル: Edges.cs プロジェクト: Snowball2012/camborne
        public void Visit(LineEdge line)
        {
            var data = m_edge.Data;

            if (at_begin)
            {
                data.p0 = line.Data.p1;
            }
            else
            {
                data.p1 = line.Data.p0;
            }

            m_edge.Data = data;
        }
コード例 #6
0
    private List <ICuttableEdge> MakeOcclusionLoop(CirclePrimitive player, CirclePrimitive obstacle, float radius_shift)
    {
        Vector2 center2center = player.center - obstacle.center;

        float      cp_param     = Mathf.Atan2(center2center.y, center2center.x);
        float      param_spread = Mathf.Acos(Mathf.Min((player.radius + obstacle.radius) / center2center.magnitude, 1.0f));
        CircleEdge circle_edge  = new CircleEdge(
            new CircleArc
        {
            center  = obstacle.center,
            radius  = obstacle.radius * (1 + radius_shift),
            t_start = cp_param - param_spread,
            t_end   = cp_param + param_spread
        },
            false);

        var      circle_end = circle_edge.Eval(0);
        LineEdge edge1      = new LineEdge(
            new LineSegment
        {
            p0 = circle_end.pt,
            p1 = circle_end.pt - circle_end.dir * 100
        },
            false);

        circle_end = circle_edge.Eval(1);
        LineEdge edge2 = new LineEdge(
            new LineSegment
        {
            p0 = circle_end.pt,
            p1 = circle_end.pt + circle_end.dir * 100
        },
            true);

        List <ICuttableEdge> res = new List <ICuttableEdge>();

        res.Add(edge1);

        for (int i = 0; i < 5; ++i)
        {
            res.Add(new LineEdge(new LineSegment {
                p0 = circle_edge.Eval(1.0f * i / 5).pt, p1 = circle_edge.Eval(1.0f * (i + 1) / 5).pt
            }, true));
        }
        res.Add(edge2);

        return(res);
    }
コード例 #7
0
 public void Visit(LineEdge line)
 {
     if (m_e1c != null || m_e1l != null)
     {
         if (m_e1c != null)
         {
             m_res = m_intersector.Intersect(line, m_e1c, true);
         }
         else
         {
             m_res = m_intersector.Intersect(m_e1l, line);
         }
     }
     else
     {
         m_e1l = line;
     }
 }
コード例 #8
0
 public List <Intersection> Intersect(LineEdge target, CircleEdge tool, bool flip)
 {
     /*
      * var target_data = target.Data;
      * var tool_data = tool.Data;
      *
      * float line_closest_param = target_data.ClosestPointParam( tool_data.center );
      * Vector2 line2center = ( target_data.Eval( line_closest_param ) - tool_data.center );
      * float line2center_dist = line2center.magnitude;
      *
      * var res = new List<Intersection>();
      * if ( line2center_dist <= tool_data.radius )
      * {
      *  float base_param = tool_data.GetClosestPoint( target_data.Eval( line_closest_param ) );
      *  float spread = Mathf.Acos( line2center_dist / tool_data.radius );
      *  if ( spread < 1.0e-3 )
      *      spread = 1.0e-3f;
      *
      *  for ( int i = -1; i <= 1; i += 2 )
      *  {
      *      float curve_param = base_param + spread * i;
      *
      *      float line_param = target_data.ClosestPointParam( tool_data.Eval( curve_param ) );
      *      if ( line_param > -1.0e-5 && line_param < 1.0 + 1.0e-5 )
      *      {
      *          bool in_edge_found = false;
      *          float min_dist = Mathf.PI * 4;
      *          curve_param -= Mathf.PI * 2;
      *          float corrected_curve_param = curve_param;
      *          while ( curve_param < Mathf.PI * 6 )
      *          {
      *              if ( curve_param >= tool_data.t_start && curve_param <= tool_data.t_end )
      *              {
      *                  corrected_curve_param = curve_param;
      *                  in_edge_found = true;
      *                  break;
      *              }
      *
      *              if ( curve_param < tool_data.t_start && ( tool_data.t_start - curve_param ) < min_dist )
      *              {
      *                  corrected_curve_param = curve_param;
      *                  min_dist = ( tool_data.t_start - curve_param );
      *              }
      *
      *              if ( curve_param > tool_data.t_end && ( curve_param - tool_data.t_end ) < min_dist )
      *              {
      *                  corrected_curve_param = curve_param;
      *                  min_dist = ( curve_param - tool_data.t_end );
      *                  break;
      *              }
      *
      *              curve_param += Mathf.PI * 2;
      *          }
      *
      *          if ( in_edge_found || min_dist < 1.0e-5 )
      *          {
      *              Intersection intersection = new Intersection
      *              {
      *                  face_edge_param = line_param,
      *                  cut_param = Mathf.InverseLerp( tool_data.t_start, tool_data.t_end, corrected_curve_param )
      *              };
      *              if ( !target.Sense )
      *                  intersection.face_edge_param = 1 - intersection.face_edge_param;
      *              if ( !tool.Sense )
      *                  intersection.cut_param = 1 - intersection.cut_param;
      *
      *              if ( !flip )
      *              {
      *                  intersection.tool_edge_enters = Utils.TestLeftHemiplane( line2center, target_data.p1 - target_data.p0 );
      *              }
      *              else
      *              {
      *                  intersection.tool_edge_enters = !Utils.TestLeftHemiplane( line2center, target_data.p1 - target_data.p0 );
      *              }
      *
      *              {
      *                  if ( i > 0 )
      *                      intersection.tool_edge_enters = !intersection.tool_edge_enters;
      *                  if ( ! target.Sense )
      *                      intersection.tool_edge_enters = !intersection.tool_edge_enters;
      *                  if ( ! tool.Sense )
      *                      intersection.tool_edge_enters = !intersection.tool_edge_enters;
      *
      *                  if ( flip )
      *                  {
      *                      float temp = intersection.cut_param;
      *                      intersection.cut_param = intersection.face_edge_param;
      *                      intersection.face_edge_param = temp;
      *                  }
      *
      *                  res.Add( intersection );
      *              }
      *          }
      *      }
      *  }
      *
      *  if ( res.Count == 2 )
      *  {
      *
      *      if ( flip && res[0].face_edge_param > res[1].face_edge_param
      || !flip && res[0].cut_param > res[1].cut_param )
      ||     {
      ||         var temp = res[0];
      ||         res[0] = res[1];
      ||         res[1] = temp;
      ||     }
      || }
      ||
      ||}
      */
     throw new System.NotImplementedException();
 }
コード例 #9
0
ファイル: Edges.cs プロジェクト: Snowball2012/camborne
 public EdgeVisitor(LineEdge edge, bool at_begin)
 {
     m_edge        = edge;
     this.at_begin = at_begin;
 }