/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2012 Ausenco Engineering Canada Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.render;

import java.util.ArrayList;
import java.util.List;

import com.jaamsim.math.Color4d;
import com.jaamsim.math.Vec4d;

public class LineProxy implements RenderProxy {

	private List<Vec4d> _lineSegments;
	private Color4d _colour;
	private Color4d _hoverColour;
	private double _lineWidth;
	private long _pickingID;
	private DebugLine _cachedLine;
	private VisibilityInfo _visInfo;

	public LineProxy(List<Vec4d> lineSegments, Color4d colour, double lineWidth, VisibilityInfo visInfo, long pickingID) {
		_lineSegments = lineSegments;
		_colour = colour;
		_hoverColour = colour;
		_lineWidth = lineWidth;
		_pickingID = pickingID;
		_visInfo = visInfo;

		assert(lineSegments.size() >= 2);
	}

	public void setHoverColour(Color4d hoverColour) {
		_hoverColour = hoverColour;
	}

	@Override
	public void collectRenderables(Renderer r, ArrayList<Renderable> outList) {

		if (_cachedLine == null) {
			_cachedLine = new DebugLine(_lineSegments, _colour, _hoverColour, _lineWidth, _visInfo, _pickingID);
		}
		outList.add(_cachedLine);
	}
	@Override
	public void collectOverlayRenderables(Renderer r,
			ArrayList<OverlayRenderable> outList) {
		// None
	}

}

@@ -853,16 +853,22 @@
 private 
+final 
 List%3CVec
@@ -887,32 +887,38 @@
 ments;%0A%09private 
+final 
 Color4d _colour;
@@ -958,16 +958,22 @@
 private 
+final 
 double _
@@ -992,16 +992,22 @@
 private 
+final 
 long _pi
@@ -1056,16 +1056,22 @@
 private 
+final 
 Visibili
@@ -1362,45 +1362,8 @@
 nfo;
-%0A%0A%09%09assert(lineSegments.size() %3E= 2);
 %0A%09%7D%0A
@@ -1537,16 +1537,85 @@
 ist) %7B%0A%0A
+%09%09if (_lineSegments == null %7C%7C _lineSegments.size() %3C 2)%0A%09%09%09return;%0A%0A
 %09%09if (_c

Make line proxy robust against bad input