|
From: <J.B...@ew...> - 2008-05-16 22:04:38
|
Hi all, How do I access Curve elements in a Path for *writing* ? Geom::Path::iterator it = _path.end(); (*it) will give me a const reference to a Curve, because Geom::Path::iterator is a BaseIterator that only provides const refs. Do I have to copy the curve, and then use replace method? Why is this so? Thanks, Johan __________________________________________________ ir. J.B.C. Engelen PhD student Micro Electromechanical Systems (MEMS) TST EWI, University of Twente The NETHERLANDS e-mail: j.b...@ut... |
|
From: <J.B...@ew...> - 2008-05-18 12:40:09
|
Hmm I just figured that writing directly to Curve is maybe not a good idea.
For example, what I need to do is reset the start and end points of a path:
(PathVector _pathv)
_pathv.front().setInitial( point );
_pathv.front().setFinal( point2 );
These set methods do not yet exist.
This won't work I think, because of the final_ segment in the path:
_pathv.front().front().setInitial( point);
_pathv.front().back().setFinal( point2 );
Please comment!
Johan
> -----Original Message-----
> From: lib...@li...
> [mailto:lib...@li...] On
> Behalf Of J.B...@ew...
> Sent: zaterdag 17 mei 2008 0:05
> To: lib...@li...
> Subject: [Lib2geom-devel] Accessing Curve elements in Path
>
> Hi all,
>
> How do I access Curve elements in a Path for *writing* ?
>
> Geom::Path::iterator it = _path.end();
> (*it) will give me a const reference to a Curve, because
> Geom::Path::iterator is a BaseIterator that only provides const refs.
>
> Do I have to copy the curve, and then use replace method? Why
> is this so?
>
> Thanks,
> Johan
>
>
> __________________________________________________
> ir. J.B.C. Engelen
> PhD student Micro Electromechanical Systems (MEMS) TST EWI,
> University of Twente The NETHERLANDS
> e-mail: j.b...@ut...
>
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Microsoft Defy all
> challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Lib2geom-devel mailing list
> Lib...@li...
> https://lists.sourceforge.net/lists/listinfo/lib2geom-devel
>
|
|
From: Marco <mrc...@gm...> - 2008-05-19 12:54:19
|
On Sat, 17 May 2008 00:04:33 +0200, <J.B...@ew...> wrote: > Hi all, > > How do I access Curve elements in a Path for *writing* ? > > Geom::Path::iterator it = _path.end(); > (*it) will give me a const reference to a Curve, because > Geom::Path::iterator is a BaseIterator that only provides const refs. > > Do I have to copy the curve, and then use replace method? Why is this so? > > Thanks, > Johan > Yes, I think you have to use the replace method. The reason is that a path has to be continuos. Allowing to get a non const iterator would mean bypassing the check on continuity preservation that is performed when the path is modified by the append/replace/erase methods. Anyway I don't know what is the rationale to have "iterator begin()" and "iterator end()" methods. Marco -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ |
|
From: MenTaLguY <me...@ry...> - 2008-05-20 03:32:32
|
On Mon, 2008-05-19 at 14:53 +0200, Marco wrote: > Yes, I think you have to use the replace method. > The reason is that a path has to be continuos. > Allowing to get a non const iterator would mean bypassing > the check on continuity preservation that is performed > when the path is modified by the append/replace/erase methods. Correct. Modifying the Curve directly would bypass the invariant checks. For now the best procedure is to copy out the sequence of Curves you are interested in, modify then, and then replace them. We do need a path editing abstraction which can ensure the invariants while providing a nicer API, however. I still haven't come up with anything satisfactory yet though. -mental |
|
From: Marco <mrc...@gm...> - 2008-05-19 12:54:20
|
On Sun, 18 May 2008 14:40:00 +0200, <J.B...@ew...> wrote:
> Hmm I just figured that writing directly to Curve is maybe not a good
> idea.
>
> For example, what I need to do is reset the start and end points of a
> path:
>
> (PathVector _pathv)
> _pathv.front().setInitial( point );
> _pathv.front().setFinal( point2 );
>
> These set methods do not yet exist.
>
> This won't work I think, because of the final_ segment in the path:
> _pathv.front().front().setInitial( point);
> _pathv.front().back().setFinal( point2 );
>
Yes, if we modify front() and back() to return a Curve&
we'll introduce a breaking change because the closing segment
extremes are not updated.
So it seems sensible to make up two path methods
as you are suggesting:
void setInitial(Point const& p)
{
curves_[0].setInitial(p);
final_.setFinal(p);
}
void setFinal(Point const& p)
{
curves_[curves_.size()-2].setFinal(p);
final_.setInitial(p);
}
> Please comment!
>
> Johan
>
>
Marco
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
From: MenTaLguY <me...@ry...> - 2008-05-20 03:29:50
|
On Mon, 2008-05-19 at 14:53 +0200, Marco wrote:
> void setInitial(Point const& p)
> {
> curves_[0].setInitial(p);
> final_.setFinal(p);
> }
>
> void setFinal(Point const& p)
> {
> curves_[curves_.size()-2].setFinal(p);
> final_.setInitial(p);
> }
This seems reasonable to me, although the second one will need be
modified to accommodate the case where curves.size() < 2.
-mental
|
|
From: MenTaLguY <me...@ry...> - 2008-05-20 03:53:19
|
On Mon, 2008-05-19 at 23:30 -0400, MenTaLguY wrote: > This seems reasonable to me, although the second one will need be > modified to accommodate the case where curves.size() < 2. I take that back. I just finished talking through the problems with njh and I think we'll need to stick with staging the changed curves outside of the Path and using replace to make modifications. We do need some API changes to make that friendlier though. -mental |
|
From: Marco <mrc...@gm...> - 2008-05-20 10:31:12
|
On Tue, 20 May 2008 05:53:51 +0200, MenTaLguY <me...@ry...> wrote:
> On Mon, 2008-05-19 at 23:30 -0400, MenTaLguY wrote:
>> This seems reasonable to me, although the second one will need be
>> modified to accommodate the case where curves.size() < 2.
>
> I take that back. I just finished talking through the problems with njh
> and I think we'll need to stick with staging the changed curves outside
> of the Path and using replace to make modifications. We do need some
> API changes to make that friendlier though.
>
> -mental
Anyway I'd like to have a safe version of them in order to avoid to
write always the same code when we need to perform these tasks.
So I'm going to commit the following version:
void setInitial(Point const& p)
{
if ( empty() ) return;
Curve* head = front().duplicate();
head->setInitial(p);
Sequence::iterator replaced = curves_.begin();
Sequence source(1, head);
try
{
do_update(replaced, replaced + 1,
source.begin(), source.end());
}
catch (...)
{
delete_range(source.begin(), source.end());
throw;
}
}
void setFinal(Point const& p)
{
if ( empty() ) return;
Curve* tail = back().duplicate();
tail->setFinal(p);
Sequence::iterator replaced = curves_.end() - 2;
Sequence source(1, tail);
try
{
do_update(replaced, replaced + 1,
source.begin(), source.end());
}
catch (...)
{
delete_range(source.begin(), source.end());
throw;
}
}
Comments ?
Regards,
Marco
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
From: Marco <mrc...@gm...> - 2008-05-20 11:29:43
|
On Tue, 20 May 2008 13:09:30 +0200, Peter Moulder
<Pet...@in...> wrote:
> On Tue, May 20, 2008 at 12:31:02PM +0200, Marco wrote:
>
>> Comments ?
>
> For one thing, it still hasn't addressed mental's comment:
>
>>> On Mon, 2008-05-19 at 23:30 -0400, MenTaLguY wrote:
>>>> the second one will need be
>>>> modified to accommodate the case where curves.size() < 2.
>
>> void setFinal(Point const& p)
>> {
>> if ( empty() ) return;
>> Curve* tail = back().duplicate();
>> tail->setFinal(p);
>> Sequence::iterator replaced = curves_.end() - 2;
>
> The above creates an invalid iterator if curves_.size() < 2. (I presume
> that empty() only tests whether curves_.size() == 0, and I presume that
> curves_.size() == 1 is still possible.) Bad things can happen if one
> creates invalid iterators/pointers, whether or not one uses the
> iterator/pointer.
>
> (I haven't looked at how setFinal/setInitial are used, so I can't give
> any other comments.)
>
> pjrm.
No, empty() test if curves_.size() == 1.
So if !empty() there must be at least two elements inside curves_,
because there is no modifying ops that return a Path object with
a state where curves_.size() == 0.
Btw my implementation doesn't allow to set the initial and the final
points when the Path is empty and I think this is the correct behaviour.
Marco
PS: I'm sorry for the double mail Peter
I always forgot to to make reply all :-)
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|
|
From: <J.B...@ew...> - 2008-05-22 19:42:35
|
Thanks a lot for adding this safe method to 2geom!
-johan
> -----Original Message-----
> From: Marco [mailto:mrc...@gm...]
> Sent: dinsdag 20 mei 2008 13:30
> To: Peter Moulder
> Cc: MenTaLguY; Engelen, J.B.C. (Johan);
> lib...@li...; njh
> Subject: Re: [Lib2geom-devel] Accessing Curve elements in Path
>
> On Tue, 20 May 2008 13:09:30 +0200, Peter Moulder
> <Pet...@in...> wrote:
>
> > On Tue, May 20, 2008 at 12:31:02PM +0200, Marco wrote:
> >
> >> Comments ?
> >
> > For one thing, it still hasn't addressed mental's comment:
> >
> >>> On Mon, 2008-05-19 at 23:30 -0400, MenTaLguY wrote:
> >>>> the second one will need be
> >>>> modified to accommodate the case where curves.size() < 2.
> >
> >> void setFinal(Point const& p)
> >> {
> >> if ( empty() ) return;
> >> Curve* tail = back().duplicate();
> >> tail->setFinal(p);
> >> Sequence::iterator replaced = curves_.end() - 2;
> >
> > The above creates an invalid iterator if curves_.size() < 2. (I
> > presume that empty() only tests whether curves_.size() == 0, and I
> > presume that
> > curves_.size() == 1 is still possible.) Bad things can
> happen if one
> > creates invalid iterators/pointers, whether or not one uses the
> > iterator/pointer.
> >
> > (I haven't looked at how setFinal/setInitial are used, so I
> can't give
> > any other comments.)
> >
> > pjrm.
>
> No, empty() test if curves_.size() == 1.
> So if !empty() there must be at least two elements inside
> curves_, because there is no modifying ops that return a Path
> object with a state where curves_.size() == 0.
> Btw my implementation doesn't allow to set the initial and
> the final points when the Path is empty and I think this is
> the correct behaviour.
>
> Marco
>
> PS: I'm sorry for the double mail Peter
> I always forgot to to make reply all :-)
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>
|