Skip to content

Commit 06a46c8

Browse files
committed
- clean all my tests. create a lpytest repository that will be played during tests
- fix bug with production in the middle of the text git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/vplants/vplants/trunk/lpy@13754 ab253cce-29fb-0310-bb2f-979600cdbdeb
1 parent 1035f0f commit 06a46c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1174
-35
lines changed

src/cpp/lpy_parser.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ has_keyword_pattern(std::string::const_iterator& pos,
9494
const std::string& pattern){
9595

9696
size_t s = pattern.size();
97-
if ( (std::distance(pos,end) >= s) &&
98-
(std::string(pos,pos+s) == pattern) && ( (pos==beg) || !isalnum(*(pos-1)) )){
99-
pos+=s;
97+
std::string::const_iterator res = pos+s;
98+
if (
99+
(std::distance(pos,end) >= s) &&
100+
(std::string(pos,pos+s) == pattern) &&
101+
( (pos==beg) || !isalnum(*(pos-1)) ) &&
102+
( (res==end) || !isalnum(*(res)) )
103+
){
104+
pos=res;
100105
return true;
101106
}
102107
else return false;
@@ -442,11 +447,18 @@ Lsystem::set( const std::string& _rules , std::string * pycode,
442447
case 'p':
443448
_it2 = _it;
444449
if(has_keyword_pattern(_it,begcode,endpycode,"production")){
445-
code+=std::string(beg,_it2);
446-
toendlineC(_it,endpycode);
447-
code+="# "+std::string(_it2,_it);
448-
beg = _it;
449-
mode = 0;
450+
// printf("-'%c' '%c'\n",*(_it2-1),*_it);
451+
/*if ((_it2 != begcode && *(_it2-1) != '\n') || (_it == *_it != ' ' && *_it != ':' && *_it != '\t')){
452+
// We are not in the production statement
453+
if(_it!=endpycode)++_it; toendlineA(_it,endpycode);
454+
}
455+
else {*/
456+
code+=std::string(beg,_it2);
457+
toendlineC(_it,endpycode);
458+
code+="# "+std::string(_it2,_it);
459+
beg = _it;
460+
mode = 0;
461+
// }
450462
}
451463
else if(has_keyword_pattern(_it,begcode,endpycode,"produce")){
452464
// LsysWarning("Cannot use 'produce' outside production body. Use 'nproduce' instead.",filename,lineno);
@@ -660,7 +672,7 @@ Lsystem::set( const std::string& _rules , std::string * pycode,
660672
PROCESS_RULE(rule,code,addedcode,mode,group)
661673
}
662674
_it2 = _it;
663-
if(has_keyword_pattern(_it,begcode,endpycode,"group ")){
675+
if(has_keyword_pattern(_it,begcode,endpycode,"group")){
664676
beg = _it;
665677
while( _it!=endpycode && (*_it)!=':' && (*_it)!='\n')
666678
_it++;

test/diese_bug.lpy

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Axiom: #(0.001)-(90)F(1)
2+
derivation length: 5
3+
4+
production:
5+
6+
F(x) :
7+
produce F(x/3.0)+F(x/3.0)--F(x/3.0)+F(x/3.0)
8+
9+
10+
endlsystem
11+
###### INITIALISATION ######
12+
13+
__copyright__ = """open-source GPL"""
14+
__description__ = """- start from an axiom representing a triangle with equal side lengths
15+
16+
- try other fractal rules"""
17+
__institutes__ = """INRIA - CIRAD Virtual Plants"""
18+
__authors__ = """C. Godin, F. Boudon"""

test/image/bjunipc.png

227 KB
Loading

test/lpytest/MoveToBug.lpy

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# with Pt2=0,1,0 the line is drawn from 0,0,10 to 0,1,0
2+
# with Pt2=0,0,1 the line is drawn from 0,0,10 to 0,0,11
3+
4+
# following generates incorrect line, to fix save y component to something small in pt2!
5+
Axiom: Pt1(0,0,10) Pt2(0,0,0)
6+
# following generates correct line
7+
# Axiom: -(90) Frame Pt1(0,10,0) Pt2(0,0,0)
8+
# following generates correct line
9+
#Axiom: Pt1(10,0,0) Pt2(0,0,0)
10+
11+
derivation length: 1
12+
production:
13+
14+
interpretation:
15+
16+
# same thing happens if you use LineTo or MoveTo for the first pt
17+
Pt1(x,y,z):
18+
produce MoveTo(x,y,z) Sphere(0.5) [@M(x,y,z) SetColor(2) Sphere(1.0)]
19+
20+
Pt2(x,y,z):
21+
produce LineTo(x,y,z) Sphere(0.5) [@M(x,y,z) SetColor(3) Sphere(1.0)]
22+
23+
endlsystem

test/lpytest/nF.lpy

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Axiom: _(1) @Tp(0,0,1)Elasticity(0.05) +(90) @Gc() nF(10,0.1,0.02)
2+
3+
derivation length: 1
4+
production:
5+
6+
7+
interpretation:
8+
9+
10+
endlsystem
11+
###### INITIALISATION ######
12+
13+
__lpy_code_version__ = 1.1
14+
15+
def __initialiseContext__(context):
16+
import openalea.plantgl.all as pgl
17+
radius = pgl.NurbsCurve2D(
18+
ctrlPointList = pgl.Point3Array([(0, 0.98719, 1),(0.0357168, 0.407384, 1),(0.260088, 0.407384, 1),(0.260088, 0.949652, 1),(0.546428, 0.964524, 1),(0.555714, 0.249528, 1),(0.78476, 0.265004, 1),(0.828093, 0.942858, 1),(0.953572, 0.936943, 1),(1, 0.109243, 1)]) ,
19+
)
20+
radius.name = "radius"
21+
panel_0 = ({'active': True, 'visible': True, 'name': 'Panel 1'},[('Function',radius)])
22+
parameterset = [panel_0,]
23+
context["__functions__"] = [('radius',radius),]
24+
context["__curves__"] = []
25+
context["__parameterset__"] = parameterset
26+
context["radius"] = pgl.QuantisedFunction(radius)

test/lpytest/nodeposition.lpy

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
dt = 0.2
2+
maxlilength = 2
3+
4+
def EndEach(lstring,scene):
5+
from openalea.plantgl.all import Translated
6+
if scene:
7+
# create a dictionnary that gives all shape for any id
8+
shapedict = {}
9+
for shape in scene:
10+
shapedict[shape.id] = shapedict.get(shape.id,[])+[shape]
11+
12+
# create a dictionnary that gives position for any id
13+
positions = {}
14+
for i,m in enumerate(lstring):
15+
if m.name == 'I': # look only for I module
16+
firstshape = shapedict[i][0] # find geometric rep of i
17+
if isinstance(firstshape.geometry,Translated) :
18+
positions[i] = firstshape.geometry.translation
19+
else:
20+
positions[i] = (0,0,0)
21+
22+
Axiom: A
23+
24+
derivation length: 6
25+
production:
26+
27+
A --> I(0)/(137.5)[+A][-A] A
28+
I(t) --> I(t+dt)
29+
30+
interpretation:
31+
32+
I(t) --> _(idiam(t)/10) F(maxlilength*ilength(t))
33+
34+
endlsystem
35+
###### INITIALISATION ######
36+
37+
__lpy_code_version__ = 1.1
38+
39+
def __initialiseContext__(context):
40+
context.animation_timestep = 0.262
41+
import openalea.plantgl.all as pgl
42+
ilength = pgl.NurbsCurve2D(
43+
ctrlPointList = pgl.Point3Array([(0, 0.0769619, 1),(0.543139, 0.181159, 1),(0.800964, 0.707373, 1),(1, 1.02556, 1)]) ,
44+
)
45+
ilength.name = "ilength"
46+
idiam = pgl.NurbsCurve2D(
47+
ctrlPointList = pgl.Point3Array([(0, 0.0562771, 1),(0.324675, 0.298701, 1),(0.588745, 0.532467, 1),(1, 0.679654, 1)]) ,
48+
)
49+
idiam.name = "idiam"
50+
panel_0 = ({'active': True, 'visible': True, 'name': 'Panel 1'},[('Function',ilength),('Function',idiam)])
51+
parameterset = [panel_0,]
52+
context["__functions__"] = [('ilength',ilength),('idiam',idiam),]
53+
context["__curves__"] = []
54+
context["__parameterset__"] = parameterset
55+
context["ilength"] = pgl.QuantisedFunction(ilength)
56+
context["idiam"] = pgl.QuantisedFunction(idiam)

test/lpytest/nodeposition2.lpy

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
dt = 0.2
2+
maxlilength = 2
3+
positions = []
4+
5+
6+
def StartEach():
7+
useGroup(getGroup()%2 +1)
8+
print 'group',getGroup()
9+
global positions
10+
positions = []
11+
12+
def EndEach():
13+
if getGroup() == 2:
14+
print len(positions)
15+
16+
17+
Axiom: A
18+
19+
derivation length: 12
20+
production:
21+
22+
group 1: # growth
23+
24+
A --> ?P() I(dt)/(137.5)[+A][-A] A
25+
I(t) --> I(t+dt)
26+
27+
28+
group 2: # position retrieval
29+
30+
?P(p) I(t):
31+
global positions
32+
positions.append(p)
33+
34+
group 0:
35+
interpretation:
36+
37+
I(t) --> _(idiam(min(1.0,t))/10.) F(maxlilength*ilength(min(1.0,t)))
38+
?P(p) --> [,(3)@D(1.1)@O]
39+
40+
endlsystem
41+
###### INITIALISATION ######
42+
43+
__lpy_code_version__ = 1.1
44+
45+
def __initialiseContext__(context):
46+
context.animation_timestep = 0.262
47+
context.options.setSelection('Early return when no matching',0)
48+
import openalea.plantgl.all as pgl
49+
ilength = pgl.NurbsCurve2D(
50+
ctrlPointList = pgl.Point3Array([(0, 0.0769619, 1),(0.543139, 0.181159, 1),(0.800964, 0.707373, 1),(1, 1.02556, 1)]) ,
51+
)
52+
ilength.name = "ilength"
53+
idiam = pgl.NurbsCurve2D(
54+
ctrlPointList = pgl.Point3Array([(0, 0.0562771, 1),(0.324675, 0.298701, 1),(0.588745, 0.532467, 1),(1, 0.679654, 1)]) ,
55+
)
56+
idiam.name = "idiam"
57+
panel_0 = ({'active': True, 'visible': True, 'name': 'Panel 1'},[('Function',ilength),('Function',idiam)])
58+
parameterset = [panel_0,]
59+
context["__functions__"] = [('ilength',ilength),('idiam',idiam),]
60+
context["__curves__"] = []
61+
context["__parameterset__"] = parameterset
62+
context["ilength"] = pgl.QuantisedFunction(ilength)
63+
context["idiam"] = pgl.QuantisedFunction(idiam)

test/lpytest/sweep.lpy

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Axiom: Frame() Sweep(path,section,10,0.1,0.5,radius)
2+
3+
derivation length: 1
4+
production:
5+
6+
7+
interpretation:
8+
9+
10+
endlsystem
11+
###### INITIALISATION ######
12+
13+
__lpy_code_version__ = 1.1
14+
15+
def __initialiseContext__(context):
16+
scalars = [('default_scalar', 1, 0, 100), ('default_scalar2', 1, 0, 100), ('default_scalar3', 1, 0, 100)]
17+
context["__scalars__"] = scalars
18+
for n,v,mnv,mxv in scalars:
19+
context[n] = v
20+
import openalea.plantgl.all as pgl
21+
radius = pgl.NurbsCurve2D(
22+
ctrlPointList = pgl.Point3Array([(0, 0.98719, 1),(0.0357168, 0.407384, 1),(0.260088, 0.407384, 1),(0.260088, 0.949652, 1),(0.546428, 0.964524, 1),(0.555714, 0.249528, 1),(0.78476, 0.265004, 1),(0.828093, 0.942858, 1),(0.953572, 0.936943, 1),(1, 0.109243, 1)]) ,
23+
)
24+
radius.name = "radius"
25+
import openalea.plantgl.all as pgl
26+
path = pgl.NurbsCurve2D(
27+
ctrlPointList = pgl.Point3Array([(-0.5, 0, 1),(-0.218615, 0.164502, 1),(0.0238095, -0.290043, 1),(0.517316, 0.246753, 1)]) ,
28+
)
29+
path.name = "path"
30+
section = pgl.NurbsCurve2D(
31+
ctrlPointList = pgl.Point3Array([(-0.5, 0, 1),(-0.331169, 0.333333, 1),(-0.166667, -0.155844, 1),(0.201299, 0.214286, 1),(0.5, 0, 1)]) ,
32+
)
33+
section.name = "section"
34+
import openalea.plantgl.all as pgl
35+
parameter = pgl.NurbsPatch(
36+
pgl.Point4Matrix([[(-0.0797013, -0.362725, -0.0718943, 1), (0.165875, -0.0593558, 0.0786184, 1), (-0.204907, 0.0787067, -0.105177, 1), (0.19717, 0.672553, 0.0853212, 1)], [(-0.0814571, -0.7365, 0.327935, 1), (0.284639, -0.469756, 0.556274, 1), (0, 0.166667, 0.333333, 1), (0.216553, 0.529145, 0.456017, 1)], [(0, -0.5, 0.666667, 1), (0, -0.166667, 0.666667, 1), (0, 0.166667, 0.666667, 1), (0, 0.5, 0.666667, 1)], [(-0.259848, -0.651558, 1.17402, 1), (-0.0401437, -0.224966, 1.32802, 1), (0, 0.166667, 1, 1), (0.340902, 0.64979, 1.19505, 1)]]) ,
37+
)
38+
parameter.name = "parameter"
39+
panel_0 = ({'active': False, 'visible': True, 'name': 'Panel 1'},[('Function',radius),('Curve2D',path),('Curve2D',section),('NurbsPatch',parameter)])
40+
radius = pgl.NurbsCurve2D(
41+
ctrlPointList = pgl.Point3Array([(0, 0.98719, 1),(0.0357168, 0.407384, 1),(0.260088, 0.407384, 1),(0.260088, 0.949652, 1),(0.546428, 0.964524, 1),(0.555714, 0.249528, 1),(0.78476, 0.265004, 1),(0.828093, 0.942858, 1),(0.953572, 0.936943, 1),(1, 0.109243, 1)]) ,
42+
)
43+
radius.name = "radius"
44+
path = pgl.NurbsCurve2D(
45+
ctrlPointList = pgl.Point3Array([(-0.5, 0, 1),(-0.218615, 0.164502, 1),(0.0238095, -0.290043, 1),(0.517316, 0.246753, 1)]) ,
46+
)
47+
path.name = "path"
48+
section = pgl.NurbsCurve2D(
49+
ctrlPointList = pgl.Point3Array([(-0.5, 0, 1),(-0.331169, 0.333333, 1),(-0.166667, -0.155844, 1),(0.201299, 0.214286, 1),(0.5, 0, 1)]) ,
50+
)
51+
section.name = "section"
52+
parameter_2 = pgl.NurbsPatch(
53+
pgl.Point4Matrix([[(-0.0797013, -0.362725, -0.0718943, 1), (0.165875, -0.0593558, 0.0786184, 1), (-0.204907, 0.0787067, -0.105177, 1), (0.19717, 0.672553, 0.0853212, 1)], [(-0.0814571, -0.7365, 0.327935, 1), (0.284639, -0.469756, 0.556274, 1), (0, 0.166667, 0.333333, 1), (0.216553, 0.529145, 0.456017, 1)], [(0, -0.5, 0.666667, 1), (0, -0.166667, 0.666667, 1), (0, 0.166667, 0.666667, 1), (0, 0.5, 0.666667, 1)], [(-0.259848, -0.651558, 1.17402, 1), (-0.0401437, -0.224966, 1.32802, 1), (0, 0.166667, 1, 1), (0.340902, 0.64979, 1.19505, 1)]]) ,
54+
)
55+
parameter_2.name = "parameter_2"
56+
import openalea.plantgl.scenegraph.interpolated_profile as ip
57+
parameter_3 = ip.InterpolatedProfile(interpolator=ip.CSplineMethod)
58+
parameter_3.name = 'parameter_3'
59+
parameter_3.set_param_range(0.0, 1.0)
60+
section0 = ip.CrossSection(*[(-0.5, 0.0), (-0.1590227484703064, 0.27564427256584167), (0.19117572903633118, -0.084947317838668823), (0.5, 0.0)])
61+
parameter_3.add_cross_section(0.0, section0)
62+
section1 = ip.CrossSection(*[(-0.5, 0.0), (-0.28442138433456421, 0.23209185898303986), (0.33333333333333331, 0.0), (0.5, 0.0)])
63+
parameter_3.add_cross_section(1.0, section1)
64+
panel_1 = ({'active': True, 'visible': True, 'name': 'Panel 1 2'},[('Function',radius),('Curve2D',path),('Curve2D',section),('NurbsPatch',parameter_2),('InterpolatedProfile',parameter_3)])
65+
parameterset = [panel_0,panel_1,]
66+
context["__functions__"] = [('radius',radius),]
67+
context["__curves__"] = [('path',path),('section',section),]
68+
context["__parameterset__"] = parameterset
69+
context["radius"] = pgl.QuantisedFunction(radius)
70+
context["path"] = path
71+
context["section"] = section
72+
context["parameter_2"] = parameter_2
73+
context["parameter_3"] = parameter_3

test/lpytest/test_axialmatching.lpy

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
matched = False
2+
3+
def StartEach():
4+
global matched
5+
matched = False
6+
7+
def EndEach():
8+
global matched
9+
assert matched
10+
11+
Axiom: I(0) [ I(1) [ I(2) I(3) ] I(4) ]
12+
13+
14+
derivation length: 1
15+
production:
16+
17+
[ I(x) [ < I(y) > I(z):
18+
global matched
19+
matched = True
20+
assert (x,y,z) == (1,2,3)
21+
22+
23+
interpretation:
24+
25+
26+
endlsystem
File renamed without changes.
File renamed without changes.

test/lpytest/test_concavepoly.lpy

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def End(lstring,lscene):
2+
faceset = lscene[0].geometry
3+
assert faceset.indexList == [[1,2,3],[3,4,5],[0,1,3,5],[0,5,6,7],[7,8,9],[9,10,11],[7,9,11],[0,7,11]]
4+
5+
Axiom: +(90) BP F-F++F-F++F-F++F-F++F-F++F-F EP(True)
6+
#Axiom: -(90) BP F+F--F+F--F+F--F+F--F+F--F+F EP(True)
7+
8+
derivation length: 1
9+
production:
10+
11+
12+
interpretation:
13+
14+
15+
endlsystem

test/lpytest/test_emptyline.lpy

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Axiom: A
2+
3+
derivation length: 1
4+
production:
5+
6+
A:
7+
pass
8+
9+
10+
11+
produce A
12+
B :
13+
produce B
14+
15+
interpretation:
16+
17+
18+
endlsystem

test/lpytest/test_endeach_modif.lpy

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def EndEach(lstring):
2+
assert len(lstring) == getIterationNb()+1
3+
lstring += 'B'
4+
global ok
5+
ok = True
6+
return lstring
7+
8+
derivation length : 5
9+
10+
ok = False
11+
12+
def End():
13+
assert ok == True
14+
15+
Axiom: A
16+
production:
17+
A --> A
18+
19+
endlsystem
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)