[SerializeField] public GameObject end_point; // 終点のオブジェクト public bool HitTest(ShapeLine other) { // 線分1の始点、終点 Vector2 s1 = start_point.transform.position; Vector2 e1 = end_point.transform.position; // 線分2の始点、終点 Vector2 s2 = other.start_point.transform.position; Vector2 e2 = other.end_point.transform.position; // 線分1のベクトル var vec1 = e1 - s1; // 線分2のベクトル var vec2 = e2 - s2; /* * 線分1、2の始点と互いの始点、終点とのベクトルの外積の * 結果が異なる符号同士なら交差している */ if (Cross(vec1, s2 - s1) * Cross(vec1, e2 - s1) < 0 && Cross(vec2, s1 - s2) * Cross(vec2, e1 - s2) < 0) { return(true); } return(false); }
public void ShowShadow(Point point, PointType pointType, object sender) { if ((this.BeginElement == null && this.EndElement == null) || (this.BeginElement != null && this.EndElement != null && this.State == ElementState.Focus)) { ShapeLine.ShowShadow(point, pointType); } }
public void Move() { if ((this.BeginElement == null && this.EndElement == null) || (this.BeginElement != null && this.EndElement != null && this.State == ElementState.Focus)) { ShapeLine.ShowMe(); } }
public override void OnMouseDown(Canvas drawArea, MouseEventArgs e) { UndoService.BeginTransaction("Add a line"); Point p = drawArea.BackTrackMouse(new Point(e.X, e.Y)); SignType sign = drawArea.MessageControl.Sign.Type; int zoom = drawArea.Document.Zoom; Point s = p.PointMultiplyDouble(1d / zoom); ShapeLine line = new ShapeLine(zoom, s, new Point(s.X + 1, s.Y + 1), drawArea.Document.CurrentShapePaintInfo, sign); AddNewObject(drawArea, line); }
public void MoveShadow(double x, double y) { if ((this.BeginElement == null && this.EndElement == null) || (this.BeginElement != null && this.EndElement != null && this.State == ElementState.Focus)) { Point pOld = this.GetBegin(); Point pNew = this.GetBegin(); pNew.X += x; pNew.Y += y; PointCollection points = ShapeLine.GetPloyline(ShapeLine.plShadow.Points, pOld, pNew); if (ShapeLine.CheckPoints(points)) { ShapeLine.plShadow.Points = points; } } }
public override void VisitLine(ShapeLine line) { var signSize = new Size(Sign.Width, Sign.Height); Size nsize = GetOffsetSizeBySign(signSize); double wrate = 1d * signSize.Width / Message.Size.Width; double hrate = 1d * signSize.Height / Message.Size.Height; double rate = wrate <= hrate ? wrate : hrate; line.Start = new Point((int)Math.Round(line.Start.X * rate), (int)Math.Round(line.Start.Y * rate)); line.End = new Point((int)Math.Round(line.End.X * rate), (int)Math.Round(line.End.Y * rate)); line.Start = line.Start + nsize; line.End = line.End + nsize; VisitShape(line); }
public void ShowMe(Point mousePoint, object sender) { ShapeLine.ShowMe(); }
public void ShowShadow(PointCollection points) { ShapeLine.ShowShadow(points); }
public void ShowShadow(Point pBegin, Point pEnd) { ShapeLine.ShowShadow(pBegin, pEnd); }
public virtual void VisitLine(ShapeLine line) { }
public bool CheckPoint(Point mousePosition) { return(ShapeLine.CheckPoints(ShapeLine.plShadow.Points)); }
public void SetFocus() { ShapeLine.SetFocus(); ShapeLine.Opacity = 1.0; }
private void ParallelCopy() { parallelCopyShapes.Clear(); if (parallelCopyTargetShape != null) { Vector2 pos = Main.MouseWorld; Vector2 offset = Vector2.Zero; switch (parallelCopyTargetShape.type) { case ShapeType.Line: ShapeLine line = parallelCopyTargetShape as ShapeLine; int direction = pos.GetDirection(line.pointStart, line.pointEnd); if (0 < direction) { float radian = 0; if (direction == 1) { radian = (-90f).ToRadian(); } else if (direction == 2) { radian = (90f).ToRadian(); } float rotation = line.pointStart.GetRadian(line.pointEnd); int distance = SettingUI.instance.ParallelCopy_Distance * ModUtils.tileSize; var cloneLine = line.Clone(); for (int i = 1; i <= SettingUI.instance.ParallelCopy_Count; i++) { cloneLine.pointStart = cloneLine.pointStart.ToRotationVector(distance, rotation - radian, true); cloneLine.pointEnd = cloneLine.pointEnd.ToRotationVector(distance, rotation - radian, true); parallelCopyShapes.Add(cloneLine.Clone()); } } break; case ShapeType.Rect: case ShapeType.Circle: case ShapeType.Image: switch (parallelCopyTargetShape.GetRect().Center().GetDirection(pos)) { case 1: offset.X = -SettingUI.instance.ParallelCopy_Distance * ModUtils.tileSize; break; case 2: offset.Y = -SettingUI.instance.ParallelCopy_Distance * ModUtils.tileSize; break; case 3: offset.X = SettingUI.instance.ParallelCopy_Distance * ModUtils.tileSize; break; case 4: offset.Y = SettingUI.instance.ParallelCopy_Distance * ModUtils.tileSize; break; } var clone = parallelCopyTargetShape.Clone(); for (int i = 1; i <= SettingUI.instance.ParallelCopy_Count; i++) { clone.pointStart += offset; clone.pointEnd += offset; parallelCopyShapes.Add(clone.Clone()); } break; } } }
public void Grow(int inc, Keys key, Size size) { foreach (ShapeBase shape in this) { if (shape.IsSelected) { if (shape.Type == ShapeType.Line) { int changeSize = inc * Zoom; ShapeLine sl = ((ShapeLine)(shape)); Point endPoint = sl.VirtualEnd; switch (key) { case Keys.Left: endPoint.X -= changeSize; if (endPoint.X < 0) { return; } break; case Keys.Up: endPoint.Y -= changeSize; if (endPoint.Y < 0) { return; } break; case Keys.Right: endPoint.X += changeSize; if (endPoint.X > size.Width) { return; } break; case Keys.Down: endPoint.Y += changeSize; if (endPoint.Y > size.Height) { return; } break; } sl.ChangeEndPoint(endPoint); } else { Rectangle bounds = shape.VirtualBounds; int changeSize = inc * Zoom; switch (key) { case Keys.Left: bounds.Width -= changeSize; break; case Keys.Up: bounds.Height -= changeSize; break; case Keys.Right: bounds.Width += changeSize; if (bounds.Right > size.Width) { return; } break; case Keys.Down: bounds.Height += changeSize; if (bounds.Bottom > size.Height) { return; } break; } shape.VirtualBounds = GetSurroundRectangle(bounds); } } } }
public void ShowMe(Point pBegin, Point pEnd) { ShapeLine.ShowMe(pBegin, pEnd); }
public void ShowMe(PointCollection points) { ShapeLine.ShowMe(points); }
public void SetUnFocus() { ShapeLine.SetUnFocus(); ShapeLine.Opacity = 0.7; }
public bool IsInside(Point point, double x, double y) { return(ShapeLine.IsInside(point, x, y)); }
public void SetSelected() { ShapeLine.SetSelected(); ShapeLine.Opacity = 1.0; }
public void SetXY(Point mousePoint) { ShapeLine.SetPreviousPoint(mousePoint); }
public unsafe void Load(byte[] buffer) { if (buffer == null) { return; } string theString; fixed (byte* pBuffer = &buffer[0]) { theString = BufferReader.ReadString(pBuffer, buffer.Length); } Tokenizer tokenizer = new Tokenizer(theString, _geometryExpressions, addNewLine: true); tokenizer.First(); Tokenizer.Token token; Character currentCharacter; while (tokenizer.Current() != null) { if (tokenizer.Current().Type != EXPRESSION_CHARACTER) { throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current()); } currentCharacter = new Character(); tokenizer.Next(); CommonParser.GoToValue(tokenizer); if (tokenizer.Current().Type != EXPRESSION_SHAPE) { throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current()); } IShape shape = null; token = tokenizer.Next(); switch (token.Type) { case EXPRESSION_SHAPE_SOLID: ShapeSolid shapeSolid = new ShapeSolid(); shapeSolid.Color = new Color( byte.Parse(token.Match.Groups["C"].Captures[0].Value), byte.Parse(token.Match.Groups["C"].Captures[1].Value), byte.Parse(token.Match.Groups["C"].Captures[2].Value), byte.Parse(token.Match.Groups["C"].Captures[3].Value)); shape = shapeSolid; break; case EXPRESSION_SHAPE_LINE: ShapeLine shapeLine = new ShapeLine(); shapeLine.Width = float.Parse(token.Match.Groups["Width"].Value); shapeLine.Color = new Color( byte.Parse(token.Match.Groups["C"].Captures[0].Value), byte.Parse(token.Match.Groups["C"].Captures[1].Value), byte.Parse(token.Match.Groups["C"].Captures[2].Value), byte.Parse(token.Match.Groups["C"].Captures[3].Value)); shape = shapeLine; break; case EXPRESSION_SHAPE_TEXTURE: ShapeTexture shapeTexture = new ShapeTexture(); shapeTexture.Color = new Color( byte.Parse(token.Match.Groups["C"].Captures[0].Value), byte.Parse(token.Match.Groups["C"].Captures[1].Value), byte.Parse(token.Match.Groups["C"].Captures[2].Value), byte.Parse(token.Match.Groups["C"].Captures[3].Value)); shapeTexture.TextureId = uint.Parse(token.Match.Groups["TextureId"].Value); shapeTexture.Rotation = new Matrix2x2( float.Parse(token.Match.Groups["R"].Captures[0].Value), float.Parse(token.Match.Groups["R"].Captures[1].Value), float.Parse(token.Match.Groups["R"].Captures[2].Value), float.Parse(token.Match.Groups["R"].Captures[3].Value)); shapeTexture.Translation = new Vector2( float.Parse(token.Match.Groups["T"].Captures[0].Value), float.Parse(token.Match.Groups["T"].Captures[1].Value)); shape = shapeTexture; break; } currentCharacter.TheShape.Type = shape; tokenizer.Next(); CommonParser.GoToValue(tokenizer); while ((token = tokenizer.Current()) != null && token.Type != EXPRESSION_CHARACTER) { IShapeItem item = null; switch (token.Type) { case EXPRESSION_LINE: ItemLine itemLine = new ItemLine(); itemLine.Start = new Vector2( float.Parse(token.Match.Groups["V"].Captures[0].Value), float.Parse(token.Match.Groups["V"].Captures[1].Value)); itemLine.End = new Vector2( float.Parse(token.Match.Groups["V"].Captures[2].Value), float.Parse(token.Match.Groups["V"].Captures[3].Value)); item = itemLine; break; case EXPRESSION_TRIANGLE: ItemTriangle itemTriangle = new ItemTriangle(); itemTriangle.V0 = new Vector2( float.Parse(token.Match.Groups["V"].Captures[0].Value), float.Parse(token.Match.Groups["V"].Captures[1].Value)); itemTriangle.V1 = new Vector2( float.Parse(token.Match.Groups["V"].Captures[2].Value), float.Parse(token.Match.Groups["V"].Captures[3].Value)); itemTriangle.V2 = new Vector2( float.Parse(token.Match.Groups["V"].Captures[4].Value), float.Parse(token.Match.Groups["V"].Captures[5].Value)); item = itemTriangle; break; } currentCharacter.TheShape.Items.Add(item); tokenizer.Next(); CommonParser.GoToValue(tokenizer); } _characters.Add(currentCharacter); } }