Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C#

What can be simpler than graphical primitives? Part 3

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
8 Apr 2013CPOL43 min read 23.8K   560   32  
using System;
using System .Collections .Generic;
using System .ComponentModel;
using System .Drawing;
using System .Drawing .Drawing2D;
using System .Windows .Forms;

using MoveGraphLibrary;

namespace GraphicalPrimitives
{
    public class Hole
    {
        Shape m_shape;
        PointF m_center;
        float m_radius;
        int nVertices;
        double m_angle;

        static float minRad = 10;

        // -------------------------------------------------
        public Hole (PointF ptC, float rad)
        {
            m_shape = Shape .Circle;
            m_center = ptC;
            m_radius = Math .Max (minRad, rad);
            nVertices = 0;
            m_angle = 0;
        }
        // -------------------------------------------------
        public Hole (PointF ptC, float rad, int nPoints, double angleDegree)
        {
            switch (nPoints)
            {
                case 3:
                default:
                    m_shape = Shape .Polyg_3;
                    nVertices = 3;
                    break;
                case 4:
                    m_shape = Shape .Polyg_4;
                    nVertices = 4;
                    break;
                case 5:
                    m_shape = Shape .Polyg_5;
                    nVertices = 5;
                    break;
                case 6:
                    m_shape = Shape .Polyg_6;
                    nVertices = 6;
                    break;
                case 7:
                    m_shape = Shape .Polyg_7;
                    nVertices = 7;
                    break;
                case 8:
                    m_shape = Shape .Polyg_8;
                    nVertices = 8;
                    break;
            }
            m_center = ptC;
            m_radius = Math .Max (minRad, rad);
            nVertices = Math .Max (3, nPoints);
            m_angle = Auxi_Convert .DegreeToRadian (angleDegree);
        }
        // -------------------------------------------------        Shape
        public Shape Shape
        {
            get { return (m_shape); }
        }
        // -------------------------------------------------        Center
        public PointF Center
        {
            get { return (m_center); }
            set { m_center = value; }
        }
        // -------------------------------------------------        Radius
        public float Radius
        {
            get { return (m_radius); }
        }
        // -------------------------------------------------        MinimumRadius
        static public float MinimumRadius
        {
            get { return (minRad); }
        }
        // -------------------------------------------------        VerticesNumber
        public int VerticesNumber
        {
            get { return (nVertices); }
        }
        // -------------------------------------------------        Angle
        public double Angle
        {
            get { return (m_angle); }
        }
        // -------------------------------------------------        Vertices
        public PointF [] Vertices
        {
            get { return ((m_shape == Shape .Circle) ? null : Auxi_Geometry .RegularPolygon (m_center, m_radius, nVertices, m_angle)); }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions