Exemplo n.º 1
0
 // does this shape (including the boundary) contain the given point?
 public bool contains(CartPt pt)
 {
     /*---------------------------------------------------
     *  // ** TEMPLATE **
     *  public returnType methodName() {
     *  ... this.center ...              -- CartPt
     *  ... this.radius ...              -- int
     *  ... this.color ...               -- String
     *
     *  ... this.area() ...                  -- double
     *  ... this.distToOrigin() ...          -- double
     *  ... this.grow(int inc) ...           -- IShape
     *
     *  ... this.center.distToOrigin() ...      -- double
     *  ... this.center.distTo(CartPt x) ...    -- double
     *
     *  ... pt.distToOrigin() ...               -- double
     *  ... pt.distTo(CartPt x) ...             -- double
     *  ---------------------------------------------------*/
     return(this.center.distTo(pt) <= this.radius);
 }
Exemplo n.º 2
0
 // does this shape (including the boundary) contain the given point?
 public bool contains(CartPt pt)
 {
     /*---------------------------------------------------
     *  // ** TEMPLATE **
     *  public returnType methodName() {
     *  ... this.nw ...                  -- CartPt
     *  ... this.size ...                -- int
     *  ... this.color ...               -- String
     *
     *  ... this.area() ...                  -- double
     *  ... this.distToOrigin() ...          -- double
     *  ... this.grow(int inc) ...           -- IShape
     *
     *  ... this.nw.distToOrigin() ...       -- double
     *  ... this.nw.distTo(CartPt x) ...     -- double
     *
     *  ... pt.distToOrigin() ...               -- double
     *  ... pt.distTo(CartPt x) ...             -- double
     *  ---------------------------------------------------*/
     return((_nw.X <= pt.X) && (pt.X <= _nw.X + _size) &&
            (_nw.Y <= pt.Y) && (pt.Y <= _nw.Y + _size));
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            CartPt pt1 = new CartPt(0, 0);
            CartPt pt2 = new CartPt(3, 4);
            CartPt pt3 = new CartPt(7, 1);

            IShape c1 = new Circle(new CartPt(50, 50), 10, "red");
            IShape c2 = new Circle(new CartPt(50, 50), 30, "red");
            IShape c3 = new Circle(new CartPt(30, 100), 30, "blue");

            IShape s1 = new Square(new CartPt(50, 50), 30, "red");
            IShape s2 = new Square(new CartPt(50, 50), 50, "red");
            IShape s3 = new Square(new CartPt(20, 40), 10, "green");


            var result1 = pt1.distToOrigin();
            var result2 = c2.area();
            var result3 = s3.biggerThan(c3);
            var result4 = s3.grow(30);


            Console.WriteLine(result1);
        }
Exemplo n.º 4
0
 public Square(CartPt nw, int size, string color)
 {
     _nw    = nw;
     _size  = size;
     _color = color;
 }
Exemplo n.º 5
0
 // to compute the distance form this point to the given point
 public double distTo(CartPt pt)
 {
     return(Math.Sqrt((_x - pt._x) * (_x - pt._x) +
                      (_y - pt._y) * (_y - pt._y)));
 }
Exemplo n.º 6
0
 public Circle(CartPt center, int radius, String color)
 {
     this.center = center;
     this.radius = radius;
     this.color  = color;
 }