Lisp HUG Maillist Archive

squirrely drawing with gp:draw-polygon on Mac OS X

I'm getting weird results with draw-polygon. Here's a simple test case which should draw a close approximation of a circle. Instead, there are odd little bumps and divots at various points on the circle's circumference. Changing the defaut for :line-joint-style doesn't seem to rectify this. Load the following two functions, then execute:

(circle-window)

BTW, this code should be cross-platform compatible for all versions of LispWorks as it only uses capi and gp APIs.

(defun display-true-circle (self x y width height &key divisions)
  (declare (ignore x y width height)
           (optimize (speed 0) (safety 3) (debug 3)))
  (let* ((vertex-list
          (loop with arc-increment = (/ (* 2 pi) divisions)
                for i below (* 2 pi) by arc-increment
                with center-x = 350
                with center-y = 350
                with radius = 200
                for perimeter-x = (+ center-x  (* radius (cos i)))
                for perimeter-y = (+ center-y  (* radius (sin i)))
                collect perimeter-x collect perimeter-y)))
    (gp:draw-polygon 
     self
     vertex-list
     :filled t 
     :foreground :orange)))



(defun circle-window (&key (divisions 200))
  (capi:contain (make-instance
                 'capi:output-pane
                 :display-callback (lambda (self x y width height)
                                     (display-true-circle self x y width height
                                                          :divisions divisions))
                 :background :greenyellow)
                :best-width 700 :best-height 700))

warmest regards,

Ralph

Raffael Cavallaro
raffaelcavallaro@me.com






Re: squirrely drawing with gp:draw-polygon on Mac OS X

Don't you think this is due to the fact that there is no anti-aliasing in
the draw functions of the CAPI ? Is you draw the circle not filled, you can
clearly see the approximation errors.

I tried also to make something with bezier curves using gp:draw-line, and
the result was very bad, for the same reason.

Best regards

Denis


Le 22/04/10 18:16, « [NOM] » <[ADRESSE]> a écrit :

> 
> I'm getting weird results with draw-polygon. Here's a simple test case which
> should draw a close approximation of a circle. Instead, there are odd little
> bumps and divots at various points on the circle's circumference. Changing the
> defaut for :line-joint-style doesn't seem to rectify this. Load the following
> two functions, then execute:
> 
> (circle-window)
> 
> BTW, this code should be cross-platform compatible for all versions of
> LispWorks as it only uses capi and gp APIs.
> 
> (defun display-true-circle (self x y width height &key divisions)
>   (declare (ignore x y width height)
>            (optimize (speed 0) (safety 3) (debug 3)))
>   (let* ((vertex-list
>           (loop with arc-increment = (/ (* 2 pi) divisions)
>                 for i below (* 2 pi) by arc-increment
>                 with center-x = 350
>                 with center-y = 350
>                 with radius = 200
>                 for perimeter-x = (+ center-x  (* radius (cos i)))
>                 for perimeter-y = (+ center-y  (* radius (sin i)))
>                 collect perimeter-x collect perimeter-y)))
>     (gp:draw-polygon
>      self
>      vertex-list
>      :filled t 
>      :foreground :orange)))
> 
> 
> 
> (defun circle-window (&key (divisions 200))
>   (capi:contain (make-instance
>                  'capi:output-pane
>                  :display-callback (lambda (self x y width height)
>                                      (display-true-circle self x y width
> height
>                                                           :divisions
> divisions))
>                  :background :greenyellow)
>                 :best-width 700 :best-height 700))
> 
> warmest regards,
> 
> Ralph
> 
> Raffael Cavallaro
> raffaelcavallaro@me.com
> 
> 
> 
> 
> 

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



Re: squirrely drawing with gp:draw-polygon on Mac OS X


On Apr 22, 2010, at 1:58 PM, Denis Pousseur wrote:

> Don't you think this is due to the fact that there is no anti-aliasing in
> the draw functions of the CAPI ?

There is anti-aliasing in draw-polygon on the mac, so, no I don't think that's what's going on here. (I think it's implemented using the underlying platform's polygon drawing primitives - on the mac, things like CGContextBeginPath, CGContextMoveToPoint, CGContextAddLineToPoint, CGContextClosePath, CGContextStrokePath, CGContextFillPath, and/or CGContextDrawPath, all of which take floats btw)

The drawing with gp:draw-polygon *is* antialised, it's just lumpy  - i.e., it's smooth, not pixel-jaggy-aliased, it's just that the smooth drawing has smooth lumps and smooth divots in it - it just isn't a circle.

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Re: squirrely drawing with gp:draw-polygon on Mac OS X


On Apr 22, 2010, at 3:17 PM, Joshua TAYLOR wrote:

> I've drawn some bézier curves using gp:draw-lines too


Ditto. The circle example was just an attempt to provide a minimal case whose intended output is unambiguous.

Clearly a number of us have tried (and failed) to use gp:draw-polygon to do cubic bezier curves (which it ought to be up to doing). Let's hope the LW guys can shed some light on this.

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Re: squirrely drawing with gp:draw-polygon on Mac OS X


On Apr 27, 2010, at 6:43 PM, Joshua TAYLOR wrote:

> Was there any followup on this?

I sent it to support but haven't heard back yet (apart from the automated incident tracking number of course). I'll be sure to let the list know if I hear anything useful from support.

warmest regards,

Ralph


Raffael Cavallaro
raffaelcavallaro@me.com






Updated at: 2020-12-10 08:39 UTC