discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Do multiple "false" make a single "true"?

W
wolf
Fri, Jul 14, 2017 6:10 AM

Consider this code:

AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291,
1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047,
-2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478,
0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563,
-2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549,
1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291,
-1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3, 0,
1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291,
1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8],
[1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4],
[-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165,
2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]],
[[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3],
[-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3],
[3, 0, 3]]];
echo("AA",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] );
//ECHO: "AA", [false, false, false, false, false]
echo("BB",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] ?
"TRue" : "FaLse");    //ECHO: "BB", "TRue"

Line 2 and 3 contain identical test instructions. Does anyone know how to
change line 3 so that multiple "true"s return a True_Condition, and one or
more "false"s return a False_Condition?

Thanks

wolf

--
View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Consider this code: AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291, 1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047, -2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478, 0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563, -2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549, 1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291, -1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3, 0, 1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291, 1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8], [1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4], [-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165, 2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]], [[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3], [-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3], [3, 0, 3]]]; echo("AA",[ for (i=[1:len(AnyShape)-1]) AnyShape[0][0]==AnyShape[0][i] ] ); //ECHO: "AA", [false, false, false, false, false] echo("BB",[ for (i=[1:len(AnyShape)-1]) AnyShape[0][0]==AnyShape[0][i] ] ? "TRue" : "FaLse"); //ECHO: "BB", "TRue" Line 2 and 3 contain identical test instructions. Does anyone know how to change line 3 so that multiple "true"s return a True_Condition, and one or more "false"s return a False_Condition? Thanks wolf -- View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Fri, Jul 14, 2017 8:59 AM

I think this does what you want:

function allTrue(list, i = 1) =
i >= len(list) ? true
: list[0][0] != list[0][i] ? false
: allTrue(list, i + 1);

echo(allTrue(AnyShape) ? "TRue" : "FaLse");

On 14 July 2017 at 07:10, wolf wv99999@gmail.com wrote:

Consider this code:

AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291,
1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047,
-2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478,
0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563,
-2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549,
1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291,
-1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3,
0,
1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291,
1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8],
[1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4],
[-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165,
2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]],
[[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3],
[-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3],
[3, 0, 3]]];
echo("AA",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ]
);
//ECHO: "AA", [false, false, false, false, false]
echo("BB",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] ?
"TRue" : "FaLse");    //ECHO: "BB", "TRue"

Line 2 and 3 contain identical test instructions. Does anyone know how to
change line 3 so that multiple "true"s return a True_Condition, and one or
more "false"s return a False_Condition?

Thanks

wolf

--
View this message in context: http://forum.openscad.org/Do-
multiple-false-make-a-single-true-tp21822.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I think this does what you want: function allTrue(list, i = 1) = i >= len(list) ? true : list[0][0] != list[0][i] ? false : allTrue(list, i + 1); echo(allTrue(AnyShape) ? "TRue" : "FaLse"); On 14 July 2017 at 07:10, wolf <wv99999@gmail.com> wrote: > Consider this code: > > AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291, > 1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047, > -2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478, > 0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563, > -2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549, > 1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291, > -1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3, > 0, > 1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291, > 1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8], > [1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4], > [-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165, > 2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]], > [[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3], > [-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3], > [3, 0, 3]]]; > echo("AA",[ for (i=[1:len(AnyShape)-1]) AnyShape[0][0]==AnyShape[0][i] ] > ); > //ECHO: "AA", [false, false, false, false, false] > echo("BB",[ for (i=[1:len(AnyShape)-1]) AnyShape[0][0]==AnyShape[0][i] ] ? > "TRue" : "FaLse"); //ECHO: "BB", "TRue" > > Line 2 and 3 contain identical test instructions. Does anyone know how to > change line 3 so that multiple "true"s return a True_Condition, and one or > more "false"s return a False_Condition? > > Thanks > > wolf > > > > > -- > View this message in context: http://forum.openscad.org/Do- > multiple-false-make-a-single-true-tp21822.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
W
wolf
Sun, Jul 16, 2017 7:22 AM

Thanks, that worked a treat. Packaging a Test_Condition as a function never
crossed my mind.

wolf

--
View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822p21832.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Thanks, that worked a treat. Packaging a Test_Condition as a function never crossed my mind. wolf -- View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822p21832.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Sun, Jul 16, 2017 10:16 AM

I should have called the function allSame rather than allTrue.

On 16 July 2017 at 08:22, wolf wv99999@gmail.com wrote:

Thanks, that worked a treat. Packaging a Test_Condition as a function never
crossed my mind.

wolf

--
View this message in context: http://forum.openscad.org/Do-
multiple-false-make-a-single-true-tp21822p21832.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I should have called the function allSame rather than allTrue. On 16 July 2017 at 08:22, wolf <wv99999@gmail.com> wrote: > Thanks, that worked a treat. Packaging a Test_Condition as a function never > crossed my mind. > > wolf > > > > -- > View this message in context: http://forum.openscad.org/Do- > multiple-false-make-a-single-true-tp21822p21832.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
JH
Joshua Holbrook
Sun, Jul 16, 2017 8:28 PM

Traditional names for these kind of functions some/any and each/every.

I dunno what it would involve, but adding these to the openscad stdlib is a
reasonable idea.

--Josh

On Sun, Jul 16, 2017 at 6:16 AM, nop head nop.head@gmail.com wrote:

I should have called the function allSame rather than allTrue.

On 16 July 2017 at 08:22, wolf wv99999@gmail.com wrote:

Thanks, that worked a treat. Packaging a Test_Condition as a function
never
crossed my mind.

wolf

--
View this message in context: http://forum.openscad.org/Do-m
ultiple-false-make-a-single-true-tp21822p21832.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Traditional names for these kind of functions some/any and each/every. I dunno what it would involve, but adding these to the openscad stdlib is a reasonable idea. --Josh On Sun, Jul 16, 2017 at 6:16 AM, nop head <nop.head@gmail.com> wrote: > I should have called the function allSame rather than allTrue. > > On 16 July 2017 at 08:22, wolf <wv99999@gmail.com> wrote: > >> Thanks, that worked a treat. Packaging a Test_Condition as a function >> never >> crossed my mind. >> >> wolf >> >> >> >> -- >> View this message in context: http://forum.openscad.org/Do-m >> ultiple-false-make-a-single-true-tp21822p21832.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >