[x3d-public] X3DJSAIL: Exceeding Java String limits on setValue? What do we do?

Don Brutzman brutzman at nps.edu
Fri Mar 24 20:36:33 PDT 2017


Interesting.  Some excerpts:

===========================================
.addFieldValue(new fieldValueObject()
	.setName("code")
	.setValue("82310 3 0 0 0 6 0 6 0 0 6 0 5 0 6 0 0 6 0 0 6 0 0 6 0 0 6 0 5 0 0 0 6 0 6 0 0 6 0 0
===========================================
.addFieldValue(new fieldValueObject()
	.setName("texCoord")
	addChild(new TextureCoordinateObject()
		.setPoint(new float[] {0f,0f,0f,0f,0f,0f,0f,0f,0f,0f,0f,0f,0f,0f,0f,-1f,0f,0f,0f,0f,0f,0f,0f,0f,0f,0f,-2f,-1f,0f,0f,0f,0f,0f,0f,0f,0f,-1f,0f,0f,0f,0f,0f,-1f,0f,0f,0f,0f,0f,0f,0f,0f,0f,-1f,0f,0f,0f,0f,0f,
===========================================
.addFieldValue(new fieldValueObject()
	.setName("coord")
	.addChild(new CoordinateObject()
	.setPoint(new float[] {-8f,-9f,4f,-7f,-7f,5f,-3f,0f,5f,8f,7f,-5f,9f,8f,-6f,5f,-2f,
===========================================

Some utility methods might help a little here.

a. for fieldObject and fieldValueObject, setValue methods that accepted a variety of different types beyond strings.  perhaps corresponding getValue methods as well.  This would allow
-  more efficient processing of inputs/outputs, and also
- more efficient storage of initial value arrays in the compiled Java program

Something like

	setValueSFInt32
	setValueMFFloat
	setValueMFVec3f
and
	getValueSFVec3f
	getValueMFRotation

etc. etc.

Of course, this becomes much more valuable if the code set methods can avoid turning typed arrays into strings before the get methods access them.

More thought required on this approach.

b. for floating point arrays, perhaps overloaded methods for double arrays when a float array is expected, avoiding the need for "f" after each value.

however this could bloat the API quite a lot, also be more confusing.

so, type conversion of individual complex-type values like that might be best accomplished in a deliberate fashion, so it might be better to concentrate such type-conversion methods in the SF/MF field object classes.

For example, MFDouble.  existing methods can be found at

	http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/jsail/fields/MFDoubleObject.html#method.summary

	void 	setValue(double newValue)
		Assign a single double as new array value.
	void 	setValue(double[] newValue)
		Assign a new double[] value to this field.

perhaps some additional set methods like

	void 	setValue(int newValue)
		Assign a single int as new array value.
	void 	setValue(int[] newValue)
		Assign a new int[] value to this field.

	void 	setValue(float newValue)
		Assign a single float as new array value.
	void 	setValue(float[] newValue)
		Assign a new float[] value to this field.

The Java compiler must worry about the general case and thus can be pretty picky about type coercion, often requiring the programmer to coerce types explicitly so that no unintended loss of numerical fidelity occurs.  In terms of X3D scene graph, however, the typed precision of each value is strictly defined in the abstract specification, so there is no ambiguity about what the end-state is.  So there might be legitimate room for additions here while avoiding the creation of trapdoors for programmers to fall into.

comments welcome.  i'll start by looking at setValue utility methods on objects like MFDoubleObject etc.


On 3/24/2017 8:25 AM, yottzumm at gmail.com wrote:
> There’s one with floating point numbers which is even bigger.  At least the previous message one is scrollable.
>
>
>
> John
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
>
> *From: *yottzumm at gmail.com <mailto:yottzumm at gmail.com>
> *Sent: *Friday, March 24, 2017 11:20 AM
> *To: *Don Brutzman <mailto:brutzman at nps.edu>
> *Cc: *X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
> *Subject: *RE: X3DJSAIL: Exceeding Java String limits on setValue? What do wedo?
>
>
>
> Attached.
>
>
>
> John
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>
>
> *From: *Don Brutzman <mailto:brutzman at nps.edu>
> *Sent: *Friday, March 24, 2017 11:17 AM
> *To: *yottzumm at gmail.com <mailto:yottzumm at gmail.com>
> *Cc: *X3D Graphics public mailing list <mailto:x3d-public at web3d.org>
> *Subject: *Re: X3DJSAIL: Exceeding Java String limits on setValue? What do wedo?
>
>
>
> On 3/24/2017 5:33 AM, yottzumm at gmail.com wrote:
>
>> There are a couple of files where setValue exceeds Java string limits.  What should we do?  Would passing an array help?
>
>
>
> - please share example
>
> - ("splitting strings" + " is easy enough" + " for passed parameters")
>
> - arrays are definitely more efficient and more compact for compilation and storage
>
> - better understanding will likely lead to even further options

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list