/// <override></override> public override Shape Clone() { Shape result = new RegularPolygoneBase(Type, this.Template); result.CopyFrom(this); return(result); }
private IEnumerable <ControlPointId> GetRegularPolygonAnchorPoints(RegularPolygoneBase polygonShape, Rectangle ownerBounds) { if (polygonShape == null) { throw new ArgumentNullException("polygonShape"); } // (Re)store the shape position and one resize point (sufficient for defining the radius) yield return(ControlPointId.Reference); // Calculate the point that is closest to the ownerBounds ControlPointId id = ControlPointId.None; int radius; Point dstA = Point.Empty, dstB = Point.Empty; if (ownerBounds.Width < ownerBounds.Height) { radius = ownerBounds.Width / 2; dstA.Offset(ownerBounds.Left, polygonShape.Y); dstB.Offset(ownerBounds.Right, polygonShape.Y); } else { radius = ownerBounds.Height / 2; dstA.Offset(polygonShape.X, ownerBounds.Top); dstB.Offset(polygonShape.X, ownerBounds.Bottom); } float lowestDistance = int.MaxValue; float angle = 360f / polygonShape.VertexCount; for (int i = 0; i < polygonShape.VertexCount; ++i) { Point p = Geometry.RotatePoint(polygonShape.X, polygonShape.Y, i * angle, polygonShape.X, polygonShape.Y + radius); float currentDistance = Math.Min(Geometry.DistancePointPoint(dstA, p), Geometry.DistancePointPoint(dstB, p)); if (currentDistance < lowestDistance) { lowestDistance = currentDistance; id = i + 1; } } yield return(id); // Correct the final position yield return(ControlPointId.Reference); }
/// <override></override> public override void CopyFrom(Shape source) { base.CopyFrom(source); if (source is RegularPolygoneBase) { RegularPolygoneBase src = (RegularPolygoneBase)source; VertexCount = src.VertexCount; diameter = src.diameter; if (pointCount != src.pointCount) { Array.Resize(ref shapePoints, src.pointCount); } Array.Copy(src.shapePoints, shapePoints, shapePoints.Length); for (int i = shapePoints.Length - 1; i >= 0; --i) { shapePoints[i] = src.shapePoints[i]; } CalcControlPoints(); drawCacheIsInvalid = true; } }
/// <override></override> public override void CopyFrom(Shape source) { base.CopyFrom(source); if (source is RegularPolygoneBase) { RegularPolygoneBase src = (RegularPolygoneBase)source; VertexCount = src.VertexCount; _radius = src._radius; if (_pointCount != src._pointCount) { Array.Resize(ref _shapePoints, src._pointCount); } Array.Copy(src._shapePoints, _shapePoints, _shapePoints.Length); for (int i = _shapePoints.Length - 1; i >= 0; --i) { _shapePoints[i] = src._shapePoints[i]; } CalcControlPoints(); DrawCacheIsInvalid = true; } }
private IEnumerable<ControlPointId> GetRegularPolygonAnchorPoints(RegularPolygoneBase polygonShape, Rectangle ownerBounds) { if (polygonShape == null) throw new ArgumentNullException("polygonShape"); // (Re)store the shape position and one resize point (sufficient for defining the radius) yield return ControlPointId.Reference; // Calculate the point that is closest to the ownerBounds ControlPointId id = ControlPointId.None; int radius; Point dstA = Point.Empty, dstB = Point.Empty; if (ownerBounds.Width < ownerBounds.Height) { radius = ownerBounds.Width / 2; dstA.Offset(ownerBounds.Left, polygonShape.Y); dstB.Offset(ownerBounds.Right, polygonShape.Y); } else { radius = ownerBounds.Height / 2; dstA.Offset(polygonShape.X, ownerBounds.Top); dstB.Offset(polygonShape.X, ownerBounds.Bottom); } float lowestDistance = int.MaxValue; float angle = 360f / polygonShape.VertexCount; for (int i = 0; i < polygonShape.VertexCount; ++i) { Point p = Geometry.RotatePoint(polygonShape.X, polygonShape.Y, i * angle, polygonShape.X, polygonShape.Y + radius); float currentDistance = Math.Min(Geometry.DistancePointPoint(dstA, p), Geometry.DistancePointPoint(dstB, p)); if (currentDistance < lowestDistance) { lowestDistance = currentDistance; id = i + 1; } } yield return id; // Correct the final position yield return ControlPointId.Reference; }
/// <override></override> public override Shape Clone() { Shape result = new RegularPolygoneBase(Type, (Template)null); result.CopyFrom(this); return result; }