public static void onKillUnit(UnitPoint info) { if (EventControl.killUnit != null) { EventControl.killUnit (info); } }
public NodePointLine(Line owner, ePoint id) { m_owner = owner; m_clone = m_owner.Clone() as Line; m_pointId = id; m_originalPoint = GetPoint(m_pointId); }
public void Finish() { m_endPoint = GetPoint(m_pointId); m_owner.P1 = m_clone.P1; m_owner.P2 = m_clone.P2; m_clone = null; }
public void init(int unitId, int team, Transform moveFinalTarget) { this.moveFinalTarget = moveFinalTarget; unitPoint = new UnitPoint(); unitPoint.team = team; unitPoint.id = unitId; unitPoint.currentLife = unitPoint.info().life; }
public Line(UnitPoint point, UnitPoint endpoint, float width, Color color) { P1 = point; P2 = endpoint; Width = width; Color = color; Selected = false; }
public void SetPosition(UnitPoint pos) { if (Control.ModifierKeys == Keys.Control) pos = HitUtil.OrthoPointD(OtherPoint(m_pointId), pos, 45); if (m_angleLocked || Control.ModifierKeys == (Keys)(Keys.Control | Keys.Shift)) pos = HitUtil.NearestPointOnLine(m_owner.P1, m_owner.P2, pos, true); SetPoint(m_pointId, pos, m_clone); }
public SnapPointBase(ICanvas canvas, IDrawObject owner, UnitPoint snappoint) { m_owner = owner; m_snappoint = snappoint; float size = (float)canvas.ToUnit(14); m_boundingRect.X = (float)(snappoint.X - size / 2); m_boundingRect.Y = (float)(snappoint.Y - size / 2); m_boundingRect.Width = size; m_boundingRect.Height = size; }
static public void DrawNode(ICanvas canvas, UnitPoint nodepoint) { RectangleF r = new RectangleF(canvas.ToScreen(nodepoint), new SizeF(0, 0)); r.Inflate(3, 3); if (r.Right < 0 || r.Left > canvas.ClientRectangle.Width) return; if (r.Top < 0 || r.Bottom > canvas.ClientRectangle.Height) return; canvas.Graphics.FillRectangle(Brushes.White, r); r.Inflate(1, 1); canvas.Graphics.DrawRectangle(Pens.Black, ScreenUtils.ConvertRect(r)); }
public void SetNewPoints(DrawTools.Line l, UnitPoint hitpoint, UnitPoint intersectpoint) { SetLine(l); double hitToVp1 = HitUtil.Distance(hitpoint, l.P1); // hit point to vertex point double ispToVp1 = HitUtil.Distance(intersectpoint, l.P1); // intersect point to vertex point // if hit is closer than intersect point, then keep this point and adjust the other if (hitToVp1 <= ispToVp1) m_p2 = intersectpoint; else m_p1 = intersectpoint; ResetLine(); }
static public void DrawTriangleNode(ICanvas canvas, UnitPoint nodepoint) { PointF screenpoint = canvas.ToScreen(nodepoint); float size = 4; PointF[] p = new PointF[] { new PointF(screenpoint.X - size, screenpoint.Y), new PointF(screenpoint.X, screenpoint.Y + size), new PointF(screenpoint.X + size, screenpoint.Y), new PointF(screenpoint.X, screenpoint.Y - size), }; canvas.Graphics.FillPolygon(Brushes.White, p); }
public void OnMouseUp(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { }
public static ArcModelMini GetArcParametersFromThreePoints(UnitPoint startPoint, UnitPoint midPoint, UnitPoint endPoint) { ArcModelMini arcModel = new ArcModelMini(); arcModel.Clockwise = HitUtil.IsClockwiseByCross(startPoint, midPoint, endPoint); arcModel.Center = HitUtil.CenterPointFrom3Points(startPoint, midPoint, endPoint); arcModel.Radius = (float)HitUtil.Distance(arcModel.Center, startPoint); arcModel.StartAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(arcModel.Center, startPoint, 0)); float EndAngle = (float)HitUtil.RadiansToDegrees(HitUtil.LineAngleR(arcModel.Center, endPoint, 0)); arcModel.SweepAngle = (float)HitUtil.CalAngleSweep(arcModel.StartAngle, EndAngle, arcModel.Clockwise); return(arcModel); }
public virtual eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { Selected = false; if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Line) { Line src = snappoint.Owner as Line; m_p2 = HitUtil.NearestPointOnLine(src.P1, src.P2, m_p1, true); return eDrawObjectMouseDown.DoneRepeat; } /* if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Arc) { Arc src = snappoint.Owner as Arc; m_p2 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, m_p1, 0); return eDrawObjectMouseDown.DoneRepeat; } * */ if (Control.ModifierKeys == Keys.Control) point = HitUtil.OrthoPointD(m_p1, point, 45); m_p2 = point; return eDrawObjectMouseDown.DoneRepeat; }
public static double Distance(UnitPoint p1, UnitPoint p2) { return(Distance(p1, p2, true)); }
public void DrawBizer(ICanvas canvas, Pen pen, UnitPoint p1, UnitPoint p2, UnitPoint p3, UnitPoint p4) { try { m_canvas.DrawBizer(canvas, pen, p1, p2, p3, p4); } catch (Exception ex) { throw ex; } }
public override void OnMouseMove(ICanvas canvas, UnitPoint point) { if (m_perSnap != null) { MouseMovePerpendicular(canvas, point); return; } if (m_tanSnap != null) { MouseMoveTangent(canvas, point); return; } base.OnMouseMove(canvas, point); }
protected virtual void MouseMoveTangent(ICanvas canvas, UnitPoint point) { /* if (m_tanSnap.Owner is IArc) { IArc src = m_tanSnap.Owner as IArc; m_p1 = HitUtil.TangentPointOnCircle(src.Center, src.Radius, point, m_tanReverse); m_p2 = point; if (m_p1 == UnitPoint.Empty) m_p2 = m_p1 = src.Center; } * */ }
public void SetPosition(UnitPoint postion) { this.SetPoint(this.clone, postion); }
public INodePoint NodePoint(ICanvas canvas, UnitPoint point) { return(null); }
/// <summary> /// 设置线条 /// </summary> /// <param name="l"></param> public void SetLine(DrawTools.Line l) { m_line = l; m_p1 = l.P1; m_p2 = l.P2; }
public eDrawObjectMouseDownEnum OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { try { List <IDrawObject> drawitems = canvas.DataModel.GetHitObjects(canvas, point); List <DrawTools.LineTool> lines = GetLines(drawitems); if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift) { foreach (DrawTools.LineTool line in lines) { AddLine(point, line); } SetSelectHint(); return(eDrawObjectMouseDownEnum.Continue); } if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control) { foreach (DrawTools.LineTool line in lines) { if (m_originalLines.ContainsKey(line)) { RemoveLine(line); } else { AddLine(point, line); } } SetSelectHint(); return(eDrawObjectMouseDownEnum.Continue); } if (drawitems.Count == 0) { return(eDrawObjectMouseDownEnum.Continue); } if (drawitems[0] is DrawTools.LineTool) { DrawTools.LineTool edge = (DrawTools.LineTool)drawitems[0]; if (edge.Type == DrawTools.LineType.PointLine) { return(eDrawObjectMouseDownEnum.Done); } bool modified = false; foreach (LinePoints originalLp in m_originalLines.Values) { UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2); if (intersectpoint != UnitPoint.Empty) { LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = originalLp.MousePoint; m_modifiedLines.Add(lp.Line, lp); lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint); modified = true; continue; } if (intersectpoint == UnitPoint.Empty) { UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint( edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2, false, true); if (apprarentISPoint == UnitPoint.Empty) { continue; } modified = true; originalLp.Line.ExtendLineToPoint(apprarentISPoint); LinePoints lp = new LinePoints(); lp.SetLine(originalLp.Line); lp.MousePoint = point; m_modifiedLines.Add(lp.Line, lp); } } if (modified) { canvas.DataModel.AfterEditObjects(this); } return(eDrawObjectMouseDownEnum.Done); } return(eDrawObjectMouseDownEnum.Done); } catch (Exception ex) { throw ex; } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="canvas"></param> /// <param name="point"></param> /// <param name="snappoint"></param> /// <returns></returns> public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { List <IDrawObject> items = canvas.DataModel.GetHitObjects(canvas, point); DrawTools.Line line = null; //找到第一个线条 foreach (IDrawObject item in items) { if (item is DrawTools.Line) { line = item as DrawTools.Line; if (line != m_l1Original.Line) { break; } } } if (line == null) { if (m_l1Original.Line == null) { SetHint("No line selected. Select first line"); } else { SetHint("No line selected. Select second line"); } return(eDrawObjectMouseDown.Continue); } if (m_l1Original.Line == null) { line.Highlighted = true; m_l1Original.SetLine(line); m_l1Original.MousePoint = point; SetHint("Select second line"); return(eDrawObjectMouseDown.Continue); } if (m_l2Original.Line == null) { line.Highlighted = true; m_l2Original.SetLine(line); m_l2Original.MousePoint = point; UnitPoint intersectpoint = HitUtil.LinesIntersectPoint( m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2); // 如果线条不相交,则将线条延伸至相交点。 if (intersectpoint == UnitPoint.Empty) { UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2); if (apprarentISPoint == UnitPoint.Empty) { return(eDrawObjectMouseDown.Done); } m_l1Original.Line.ExtendLineToPoint(apprarentISPoint); m_l2Original.Line.ExtendLineToPoint(apprarentISPoint); m_l1NewPoint.SetLine(m_l1Original.Line); m_l2NewPoint.SetLine(m_l2Original.Line); canvas.DataModel.AfterEditObjects(this); return(eDrawObjectMouseDown.Done); } m_l1NewPoint.SetNewPoints(m_l1Original.Line, m_l1Original.MousePoint, intersectpoint); m_l2NewPoint.SetNewPoints(m_l2Original.Line, m_l2Original.MousePoint, intersectpoint); canvas.DataModel.AfterEditObjects(this); return(eDrawObjectMouseDown.Done); } return(eDrawObjectMouseDown.Done); }
public void SetHitObjects(UnitPoint point, List <IDrawObject> list) { }
/// <summary> /// UnitPoint转换成当前屏幕点 /// </summary> public PointF ToScreen(UnitPoint unitpoint) { return(m_canvas.ToScreen(unitpoint)); }
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List<IDrawObject> otherobjs, Type[] runningsnaptypes, Type usersnaptype) { float thWidth = ThresholdWidth(canvas, Width); if (runningsnaptypes != null) { foreach (Type snaptype in runningsnaptypes) { if (snaptype == typeof(VertextSnapPoint)) { if (HitUtil.CircleHitPoint(m_p1, thWidth, point)) return new VertextSnapPoint(canvas, this, m_p1); if (HitUtil.CircleHitPoint(m_p2, thWidth, point)) return new VertextSnapPoint(canvas, this, m_p2); } if (snaptype == typeof(MidpointSnapPoint)) { UnitPoint p = MidPoint(canvas, m_p1, m_p2, point); if (p != UnitPoint.Empty) return new MidpointSnapPoint(canvas, this, p); } if (snaptype == typeof(IntersectSnapPoint)) { Line otherline = Utils.FindObjectTypeInList(this, otherobjs, typeof(Line)) as Line; if (otherline == null) continue; UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2); if (p != UnitPoint.Empty) return new IntersectSnapPoint(canvas, this, p); } } return null; } if (usersnaptype == typeof(MidpointSnapPoint)) return new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(m_p1, m_p2)); if (usersnaptype == typeof(IntersectSnapPoint)) { Line otherline = Utils.FindObjectTypeInList(this, otherobjs, typeof(Line)) as Line; if (otherline == null) return null; UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2); if (p != UnitPoint.Empty) return new IntersectSnapPoint(canvas, this, p); } if (usersnaptype == typeof(VertextSnapPoint)) { double d1 = HitUtil.Distance(point, m_p1); double d2 = HitUtil.Distance(point, m_p2); if (d1 <= d2) return new VertextSnapPoint(canvas, this, m_p1); return new VertextSnapPoint(canvas, this, m_p2); } if (usersnaptype == typeof(NearestSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point); if (p != UnitPoint.Empty) return new NearestSnapPoint(canvas, this, p); } if (usersnaptype == typeof(PerpendicularSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point); if (p != UnitPoint.Empty) return new PerpendicularSnapPoint(canvas, this, p); } return null; }
public void OnMouseMove(ICanvas canvas, UnitPoint point) { }
/* public void GetObjectData(XmlWriter wr) { wr.WriteStartElement("line"); XmlUtil.WriteProperties(this, wr); wr.WriteEndElement(); } public void AfterSerializedIn() { } * */ #endregion public void ExtendLineToPoint(UnitPoint newpoint) { UnitPoint newlinepoint = HitUtil.NearestPointOnLine(P1, P2, newpoint, true); if (HitUtil.Distance(newlinepoint, P1) < HitUtil.Distance(newlinepoint, P2)) P1 = newlinepoint; else P2 = newlinepoint; }
public void SetPosition(UnitPoint pos) { this.Location = pos; }
public override eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { if (m_tanSnap != null && Control.MouseButtons == MouseButtons.Right) { ReverseTangent(canvas); return eDrawObjectMouseDown.Continue; } if (m_perSnap != null || m_tanSnap != null) { if (snappoint != null) point = snappoint.SnapPoint; OnMouseMove(canvas, point); if (m_singleLineSegment) return eDrawObjectMouseDown.Done; return eDrawObjectMouseDown.DoneRepeat; } eDrawObjectMouseDown result = base.OnMouseDown(canvas, point, snappoint); if (m_singleLineSegment) return eDrawObjectMouseDown.Done; return eDrawObjectMouseDown.DoneRepeat; }
public static double LineSlope(UnitPoint p1, UnitPoint p2) { return((p2.Y - p1.Y) / (p2.X - p1.X)); }
public static UnitPoint OrthoPointR(UnitPoint p1, UnitPoint p2, double roundToAngleR) { return(NearestPointOnLine(p1, p2, p2, roundToAngleR)); }
abstract public void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap);
public virtual void Copy(Line acopy) { base.Copy(acopy); m_p1 = acopy.m_p1; m_p2 = acopy.m_p2; Selected = acopy.Selected; }
/// <summary> /// 获取直线和圆的交点坐标 /// </summary> /// <param name="p1">线段起点</param> /// <param name="p2">线段终点</param> /// <param name="center">圆心坐标</param> /// <param name="radius">半径</param> /// <param name="thWidth">阈值宽度</param> /// <returns>交点坐标</returns> public static List <UnitPoint> GetIntersectPointLineWithCircle(UnitPoint p1, UnitPoint p2, UnitPoint center, float radius, float thWidth) { List <UnitPoint> unitPoints = new List <UnitPoint>(); UnitPoint intersectOne; UnitPoint intersectTwo; if (Math.Abs(p1.X - p2.X) < 0.000001) { intersectOne = new UnitPoint(p1.X, Math.Sqrt(radius * radius - (p1.X - center.X) * (p1.X - center.X)) + center.Y); intersectTwo = new UnitPoint(p1.X, -Math.Sqrt(radius * radius - (p1.X - center.X) * (p1.X - center.X)) + center.Y); } else if (Math.Abs(p1.Y - p2.Y) < 0.000001) { intersectOne = new UnitPoint(Math.Sqrt(radius * radius - (p1.Y - center.Y) * (p1.Y - center.Y)) + center.X, p1.Y); intersectTwo = new UnitPoint(-Math.Sqrt(radius * radius - (p1.Y - center.Y) * (p1.Y - center.Y)) + center.X, p1.Y); } else { double A = p1.Y - p2.Y; double B = p1.X - p2.X; double C = (p2.Y * B - p2.X * A) / B; double D = 1 + (A * A) / (B * B); double E = 2 * A * (C - center.Y) / B - 2 * center.X; double F = center.X * center.X + C * C + center.Y * center.Y - 2 * center.Y * C - radius * radius; double delta = Math.Sqrt(E * E - 4 * D * F); double x1 = (-E + delta) / (2 * D); double x2 = (-E - delta) / (2 * D); double y1 = (A / B) * x1 + C; double y2 = (A / B) * x2 + C; intersectOne = new UnitPoint(x1, y1); intersectTwo = new UnitPoint(x2, y2); } if (IsPointInLine(p1, p2, intersectOne, thWidth)) { unitPoints.Add(intersectOne); } if (IsPointInLine(p1, p2, intersectTwo, thWidth)) { unitPoints.Add(intersectTwo); } return(unitPoints); }
public IntersectSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint) : base(canvas, owner, snappoint) { }
public bool PointInObject(ICanvas canvas, UnitPoint point) { float thWidth = ThresholdWidth(canvas, Width); return HitUtil.IsPointInLine(m_p1, m_p2, point, thWidth); }
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype) { return(null); }
public static bool IsClockwiseByCross(UnitPoint startPoint, UnitPoint midPoint, UnitPoint endPoint) { double result = (midPoint.X - startPoint.X) * (endPoint.Y - midPoint.Y) - (midPoint.Y - startPoint.Y) * (endPoint.X - midPoint.X); return(result < 0);//顺时针方向 }
public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap) { P1 = P2 = point; Width = layer.Width; Color = layer.Color; Selected = true; }
public virtual void SetPosition(UnitPoint pos) { SetPoint(m_clone, pos); }
UnitPoint MidPoint(ICanvas canvas, UnitPoint p1, UnitPoint p2, UnitPoint hitpoint) { UnitPoint mid = HitUtil.LineMidpoint(p1, p2); float thWidth = ThresholdWidth(canvas, Width); if (HitUtil.CircleHitPoint(mid, thWidth, hitpoint)) return mid; return UnitPoint.Empty; }
public virtual void SetPosition(UnitPoint pos) { m_clone.OnMouseMove(null, pos); }
public virtual void OnMouseMove(ICanvas canvas, UnitPoint point) { if (Control.ModifierKeys == Keys.Control) point = HitUtil.OrthoPointD(m_p1, point, 45); m_p2 = point; }
public virtual void SetPosition(UnitPoint pos) { m_clone.Center = pos; }
/// <summary> /// 求取两条直线段的交点 /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="p3"></param> /// <param name="p4"></param> /// <returns></returns> public static UnitPoint LinesIntersectPoint(UnitPoint p1, UnitPoint p2, UnitPoint p3, UnitPoint p4) { double x = 0; double y = 0; if (LinesIntersect(p1, p2, p3, p4, ref x, ref y, true, false, false)) { return(new UnitPoint(x, y)); } return(UnitPoint.Empty); }
public virtual INodePoint NodePoint(ICanvas canvas, UnitPoint point) { //Console.WriteLine(m_p1.X+" "+m_p1.Y); float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel); if (HitUtil.PointInPoint(Center, point, thWidth))//圓心位移 { return(new NodePointCircleCenter(this)); } bool radiushit = HitUtil.PointInPoint(m_p1, point, thWidth); if (radiushit == false) { radiushit = HitUtil.PointInPoint(m_p2, point, thWidth); } if (radiushit == false) { radiushit = HitUtil.PointInPoint(m_p3, point, thWidth); } if (radiushit) { m_curPoint = eCurrentPoint.radius; m_lastPoint = Center; return(new NodePointCircleRadius(this)); } return(null); //float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel); //if (HitUtil.PointInPoint(P1, point, thWidth)) //{ // m_lastPoint = P1; // return new NodePointArc3PointPoint(this, eCurrentPoint.p1); //} //if (HitUtil.PointInPoint(P2, point, thWidth)) //{ // m_lastPoint = P2; // return new NodePointArc3PointPoint(this, eCurrentPoint.p2); //} //if (HitUtil.PointInPoint(P3, point, thWidth)) //{ // m_lastPoint = P3; // return new NodePointArc3PointPoint(this, eCurrentPoint.p3); //} //UnitPoint p = StartAngleNodePoint(canvas); //if (HitUtil.PointInPoint(p, point, thWidth)) //{ // m_lastPoint = p; // return new NodePointArc3PointPoint(this, eCurrentPoint.startangle); //} //p = EndAngleNodePoint(canvas); //if (HitUtil.PointInPoint(p, point, thWidth)) //{ // m_lastPoint = p; // return new NodePointArc3PointPoint(this, eCurrentPoint.endangle); //} //p = RadiusNodePoint(canvas); //if (HitUtil.PointInPoint(p, point, thWidth)) //{ // m_lastPoint = p; // return new NodePointArc3PointPoint(this, eCurrentPoint.radius); //} return(null); }
public INodePoint NodePoint(ICanvas canvas, UnitPoint point) { float thWidth = ThresholdWidth(canvas, Width); if (HitUtil.CircleHitPoint(m_p1, thWidth, point)) return new NodePointLine(this, NodePointLine.ePoint.P1); if (HitUtil.CircleHitPoint(m_p2, thWidth, point)) return new NodePointLine(this, NodePointLine.ePoint.P2); return null; }
public void UpdateCircleFrom3Points() { m_center = HitUtil.CenterPointFrom3Points(m_p1, m_p2, m_p3); m_radius = (float)HitUtil.Distance(m_center, m_p1); }
public void Move(UnitPoint offset) { m_p1.X += offset.X; m_p1.Y += offset.Y; m_p2.X += offset.X; m_p2.Y += offset.Y; }
public virtual ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype) { float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel); if (runningsnaptypes != null) { foreach (Type snaptype in runningsnaptypes) { if (snaptype == typeof(QuadrantSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 90); if (p != UnitPoint.Empty && HitUtil.PointInPoint(p, point, thWidth)) { return(new QuadrantSnapPoint(canvas, this, p)); } } if (snaptype == typeof(DivisionSnapPoint)) { double angle = 360 / 8; UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, angle); if (p != UnitPoint.Empty && HitUtil.PointInPoint(p, point, thWidth)) { return(new DivisionSnapPoint(canvas, this, p)); } } if (snaptype == typeof(CenterSnapPoint)) { if (HitUtil.PointInPoint(m_center, point, thWidth)) { return(new CenterSnapPoint(canvas, this, m_center)); } } if (snaptype == typeof(VertextSnapPoint)) { if (HitUtil.PointInPoint(HitUtil.PointOncircle(m_center, m_radius, 0), point, thWidth)) { return(new VertextSnapPoint(canvas, this, HitUtil.PointOncircle(m_center, m_radius, 0))); } if (HitUtil.PointInPoint(HitUtil.PointOncircle(m_center, m_radius, 360), point, thWidth)) { return(new VertextSnapPoint(canvas, this, HitUtil.PointOncircle(m_center, m_radius, 360))); } } } return(null); } if (usersnaptype == typeof(NearestSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 0); if (p != UnitPoint.Empty) { return(new NearestSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(PerpendicularSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 0); if (p != UnitPoint.Empty) { return(new PerpendicularSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(QuadrantSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 90); if (p != UnitPoint.Empty) { return(new QuadrantSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(DivisionSnapPoint)) { double angle = 360 / 8; UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, angle); if (p != UnitPoint.Empty) { return(new DivisionSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(TangentSnapPoint)) { IDrawObject drawingObject = canvas.CurrentObject; UnitPoint p = UnitPoint.Empty; if (drawingObject is LineEdit) { UnitPoint mousepoint = point; point = ((LineEdit)drawingObject).P1; UnitPoint p1 = HitUtil.TangentPointOnCircle(m_center, m_radius, point, false); UnitPoint p2 = HitUtil.TangentPointOnCircle(m_center, m_radius, point, true); double d1 = HitUtil.Distance(mousepoint, p1); double d2 = HitUtil.Distance(mousepoint, p2); if (d1 <= d2) { return(new TangentSnapPoint(canvas, this, p1)); } else { return(new TangentSnapPoint(canvas, this, p2)); } } //if (p != PointF.Empty) return(new TangentSnapPoint(canvas, this, p)); } if (usersnaptype == typeof(CenterSnapPoint)) { return(new CenterSnapPoint(canvas, this, m_center)); } return(null); // float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel); // if (runningsnaptypes != null) // { // foreach (Type snaptype in runningsnaptypes) // { // /* //if (snaptype == typeof(QuadrantSnapPoint)) //{ // UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 90); // if (p != UnitPoint.Empty && HitUtil.PointInPoint(p, point, thWidth)) // return new QuadrantSnapPoint(canvas, this, p); //} //if (snaptype == typeof(CenterSnapPoint)) //{ // if (HitUtil.PointInPoint(m_center, point, thWidth)) // return new CenterSnapPoint(canvas, this, m_center); //} // * */ // if (snaptype == typeof(VertextSnapPoint)) // { // if (HitUtil.PointInPoint(P1, point, thWidth)) // return new VertextSnapPoint(canvas, this, P1); // if (HitUtil.PointInPoint(P3, point, thWidth)) // return new VertextSnapPoint(canvas, this, P3); // } // } // return null; // } // if (usersnaptype == typeof(NearestSnapPoint)) // { // UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 0); // if (p != UnitPoint.Empty) // return new NearestSnapPoint(canvas, this, p); // } // if (usersnaptype == typeof(PerpendicularSnapPoint)) // { // UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 0); // if (p != UnitPoint.Empty) // return new PerpendicularSnapPoint(canvas, this, p); // } // if (usersnaptype == typeof(QuadrantSnapPoint)) // { // UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 90); // if (p != UnitPoint.Empty) // return new QuadrantSnapPoint(canvas, this, p); // } // if (usersnaptype == typeof(TangentSnapPoint)) // { // IDrawObject drawingObject = canvas.CurrentObject; // UnitPoint p = UnitPoint.Empty; // if (drawingObject is LineEdit) // { // UnitPoint mousepoint = point; // point = ((LineEdit)drawingObject).P1; // UnitPoint p1 = HitUtil.TangentPointOnCircle(m_center, m_radius, point, false); // UnitPoint p2 = HitUtil.TangentPointOnCircle(m_center, m_radius, point, true); // double d1 = HitUtil.Distance(mousepoint, p1); // double d2 = HitUtil.Distance(mousepoint, p2); // if (d1 <= d2) // return new TangentSnapPoint(canvas, this, p1); // else // return new TangentSnapPoint(canvas, this, p2); // } // //if (p != PointF.Empty) // return new TangentSnapPoint(canvas, this, p); // } // if (usersnaptype == typeof(CenterSnapPoint)) // { // return new CenterSnapPoint(canvas, this, m_center); // } // return null; }
public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap) { base.InitializeFromModel(point, layer, snap); m_perSnap = snap as PerpendicularSnapPoint; m_tanSnap = snap as TangentSnapPoint; }
public bool PointInObject(ICanvas canvas, UnitPoint point) { float thWidth = ThresholdWidth(canvas, Width); return(HitUtil.IsPointInLine(m_p1, m_p2, point, thWidth)); }
protected void SetPoint(ePoint pointid, UnitPoint point, Line line) { if (pointid == ePoint.P1) line.P1 = point; if (pointid == ePoint.P2) line.P2 = point; }
public static UnitPoint FindApparentIntersectPoint(UnitPoint p1, UnitPoint lp2, UnitPoint p3, UnitPoint p4, bool extendA, bool extendB) { double x = 0; double y = 0; if (LinesIntersect(p1, lp2, p3, p4, ref x, ref y, true, extendA, extendB)) { return(new UnitPoint(x, y)); } return(UnitPoint.Empty); }
protected virtual void MouseMovePerpendicular(ICanvas canvas, UnitPoint point) { if (m_perSnap.Owner is Line) { Line src = m_perSnap.Owner as Line; m_p1 = HitUtil.NearestPointOnLine(src.P1, src.P2, point, true); m_p2 = point; } /* if (m_perSnap.Owner is IArc) { IArc src = m_perSnap.Owner as IArc; m_p1 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, point, 0); m_p2 = point; } * */ }
public static UnitPoint OrthoPointD(UnitPoint p1, UnitPoint p2, double roundToAngleR) { return(OrthoPointR(p1, p2, DegreesToRadians(roundToAngleR))); }
void onUnitKilled(UnitPoint unitInfo) { if (destroyed) return; if (!hasActiveWaves()) { GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); int badEnemies = 0; UnitController control; for (int i = 0; i < enemies.Length; i++) { control = enemies[i].GetComponent<UnitController>(); if (control != null && !control.unitPoint.isDie() && control.unitPoint.team == Teams.BAD) { badEnemies++; } } if (badEnemies == 0) { EventControl.onLevelComplete(); } } }
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobjs, Type[] runningsnaptypes, Type usersnaptype) { float thWidth = ThresholdWidth(canvas, Width); if (runningsnaptypes != null) { foreach (Type snaptype in runningsnaptypes) { if (snaptype == typeof(VertextSnapPoint)) { if (HitUtil.CircleHitPoint(m_p1, thWidth, point)) { return(new VertextSnapPoint(canvas, this, m_p1)); } if (HitUtil.CircleHitPoint(m_p2, thWidth, point)) { return(new VertextSnapPoint(canvas, this, m_p2)); } } if (snaptype == typeof(MidpointSnapPoint)) { UnitPoint p = MidPoint(canvas, m_p1, m_p2, point); if (p != UnitPoint.Empty) { return(new MidpointSnapPoint(canvas, this, p)); } } if (snaptype == typeof(IntersectSnapPoint)) { Line otherline = Utils.FindObjectTypeInList(this, otherobjs, typeof(Line)) as Line; if (otherline == null) { continue; } UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2); if (p != UnitPoint.Empty) { return(new IntersectSnapPoint(canvas, this, p)); } } } return(null); } if (usersnaptype == typeof(MidpointSnapPoint)) { return(new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(m_p1, m_p2))); } if (usersnaptype == typeof(IntersectSnapPoint)) { Line otherline = Utils.FindObjectTypeInList(this, otherobjs, typeof(Line)) as Line; if (otherline == null) { return(null); } UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2); if (p != UnitPoint.Empty) { return(new IntersectSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(VertextSnapPoint)) { double d1 = HitUtil.Distance(point, m_p1); double d2 = HitUtil.Distance(point, m_p2); if (d1 <= d2) { return(new VertextSnapPoint(canvas, this, m_p1)); } return(new VertextSnapPoint(canvas, this, m_p2)); } if (usersnaptype == typeof(NearestSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point); if (p != UnitPoint.Empty) { return(new NearestSnapPoint(canvas, this, p)); } } if (usersnaptype == typeof(PerpendicularSnapPoint)) { UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point); if (p != UnitPoint.Empty) { return(new PerpendicularSnapPoint(canvas, this, p)); } } return(null); }