Magnetic grid

classic Classic list List threaded Threaded
5 messages Options
HJH
Reply | Threaded
Open this post in threaded view
|

Magnetic grid

HJH
Hello

I have a problem to have polygons (squares) snap to the magnetic grid. (DrGeo 2018 edition).

First 'Snap to grid was activated'.
Then two polygons (squares) were drawn. The result


Two squares drawn aligned to the grid.

But if I move around the second square it does not snap to the grid.

Second square not snapping to grid

What is the problem here?

Regards
Hannes
HJH
Reply | Threaded
Open this post in threaded view
|

Re: Magnetic grid

HJH
The result I would like to attain by direct manipulation is what is created by a script as follows


    | canvas square   |

    square := [:p1 :p2 :p3  :p4|
        c segment: p1 to: p2.
        c segment: p2 to: p3.
        c segment: p3 to: p4.
        c segment: p4 to: p1].
 
    c := DrGeoCanvas new.
    square value: 0@0 value: 0@10 value: 10@10 value: 10@0.
    square value: 5@5 value: 5@15 value: 15@15 value: 15@5.


Two squares created by a script
Reply | Threaded
Open this post in threaded view
|

Re: Magnetic grid

Hilaire Fernandes
Administrator
In reply to this post by HJH
Le 06/09/2018 à 10:52, HJH [via Dr. Geo Forum] a écrit :

I have a problem to have polygons (squares) snap to the magnetic grid. (DrGeo 2018 edition).

First 'Snap to grid was activated'.
Then two polygons (squares) were drawn. The result


Hi,

It is a bug!  I reported it there https://bugs.launchpad.net/drgeo/+bug/1791045

Thanks to the take the time to report it!


Hilaire

Was this message helpful?
Tell us!
Reply | Threaded
Open this post in threaded view
|

Re: Magnetic grid

Hilaire Fernandes
Administrator
In reply to this post by HJH
Hello,

To build a square you can also built in functions.

For a non constrained quadrilateral:

 | canvas square   |
canvas := DrGeoCanvas new.
canvas polygon: {0@0. 0@10. 10@10. 10@0}.



Or for a constrained square:

 | canvas square   |
canvas := DrGeoCanvas new.
canvas regularPolygonCenter: 5@5 vertex: 0@0 sides: 4

Best

Hilaire


Le 06/09/2018 à 12:25, HJH [via Dr. Geo Forum] a écrit :

> The result I would like to attain by direct manipulation is what is
> created by a script as follows
>
>
>     | canvas square   |
>
>     square := [:p1 :p2 :p3  :p4|
>         c segment: p1 to: p2.
>         c segment: p2 to: p3.
>         c segment: p3 to: p4.
>         c segment: p4 to: p1].
>  
>     c := DrGeoCanvas new.
>     square value: 0@0 value: 0@10 value: 10@10 value: 10@0.
>     square value: 5@5 value: 5@15 value: 15@15 value: 15@5.


Was this message helpful?
Tell us!
HJH
Reply | Threaded
Open this post in threaded view
|

Re: Magnetic grid

HJH
In reply to this post by Hilaire Fernandes
Hilaire, thanks your fix just now in the griding code (two methods updated, see below) it works now

Griding OK after fix


--Hannes

___


    PasteUpMorph subclass: #DrGDrawable

    gridWorldVector: ungriddedPoint
        self presenter isGridded ifFalse: [^ self morphToVector: ungriddedPoint].
        "do it the easy way"
        ^(self morphToVector: ungriddedPoint) roundTo: gridScale

and


    DrGSelectToolStateDragged

    handleMouseAt: aPoint
    |gridded|
  (self context isGridded and: [self mathItem isFreePointItem])
                ifFalse: [gridded := self area gridWorldVector: aPoint - self context last.
                        self context domain
                                moveEvent: self mathItem
                                inDirection: gridded
                                withDirty: self context mathItems.
                        "If no movement, keep previous last position in reference"
                        (gridded closeTo: 0@0) ifFalse: [self context last: (self context gridPoint: aPoint)]]
                ifTrue: [gridded := self context gridPoint: aPoint.
                        self context domain
                                moveEvent: self mathItem
                                at: (self area gridWorldPoint: gridded)
                                withDirty: self context mathItems.
                        self context last: gridded.].
        self area updateDottedLinesToParents.
        self area restartMouseStillDownHandle.
        ^ true