[OpenSCAD] Function to return the Opposite value

Alex Gibson alex at alexgibson.net
Thu Oct 31 10:51:53 EDT 2019


Easy:

	oppositeThing = 1-isThing;

So if isThing is 1, oppositeThing is 0, and if isThing is 0, oppositeThing
is 1.


I sometimes also use this as a dirty way of enabling or disable whole chunks
of code, by putting it within a scale fubction - IE

module thingwithtwoversions()
	{
	scale([1,1,isThing])
		{
		Your module, primary version
		}
	scale([1,1,oppositeThing])
		{
		Your module, alternate version
		}
	}

This can be done more intelligently using logical if statements but this way
is quick to insert!

Alex Gibson

admg consulting

edumaker limited

. Project management
. Operations & Process improvement 
. 3D Printing


-----Original Message-----
From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Bryan
Lee
Sent: 31 October 2019 07:18
To: discuss at lists.openscad.org
Subject: [OpenSCAD] Function to return the Opposite value

I want to define a value at the top of my program:

	isThing=1;  // isThing can be 0 or 1

But later on I need to be able to use the opposite value.  
I.E.  
	1 if isThing==0 or
	0 if isThing==1

Note that this needs to be a number, not a boolean because I will be
multiplying vectors by it.

I am happy with either defining a variable or using a function to get this
opposite value.


How can I do this?

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




More information about the Discuss mailing list