<commit_before>/**
 *
 */
package ca.eandb.jmist.framework.material;

import java.io.Serializable;

import ca.eandb.jmist.framework.Painter;
import ca.eandb.jmist.framework.ScatteredRay;
import ca.eandb.jmist.framework.ScatteredRayRecorder;
import ca.eandb.jmist.framework.SurfacePoint;
import ca.eandb.jmist.framework.color.Color;
import ca.eandb.jmist.framework.color.WavelengthPacket;
import ca.eandb.jmist.math.RandomUtil;
import ca.eandb.jmist.math.Ray3;
import ca.eandb.jmist.math.SphericalCoordinates;
import ca.eandb.jmist.math.Vector3;

/**
 * A <code>Material</code> that reflects light equally in all directions in
 * the upper hemisphere.
 * @author <NAME>
 */
public final class LambertianMaterial extends OpaqueMaterial implements
		Serializable {

	/**
	 * Creates a new <code>LambertianMaterial</code> that does not emit light.
	 * @param reflectance The reflectance <code>Painter</code>.
	 */
	public LambertianMaterial(Painter reflectance) {
		this(reflectance, null);
	}

	/**
	 * Creates a new <code>LambertianMaterial</code> that emits light.
	 * @param reflectance The reflectance <code>Painter</code>.
	 * @param emittance The emission <code>Painter</code>.
	 */
	public LambertianMaterial(Painter reflectance, Painter emittance) {
		this.reflectance = reflectance;
		this.emittance = emittance;
	}

	/* (non-Javadoc)
	 * @see ca.eandb.jmist.framework.AbstractMaterial#isEmissive()
	 */
	@Override
	public boolean isEmissive() {
		return (this.emittance != null);
	}

	/* (non-Javadoc)
	 * @see ca.eandb.jmist.framework.material.AbstractMaterial#emission(ca.eandb.jmist.framework.SurfacePoint, ca.eandb.jmist.math.Vector3, ca.eandb.jmist.framework.color.WavelengthPacket)
	 */
	@Override
	public Color emission(SurfacePoint x, Vector3 out, WavelengthPacket lambda) {

		if (this.emittance == null || x.getNormal().dot(out) < 0.0) {
			return lambda.getColorModel().getBlack(lambda);
		}

		double ndotv = x.getShadingNormal().dot(out);
		return ndotv > 0.0 ? emittance.getColor(x, lambda).times(ndotv) : lambda.getColorModel().getBlack(lambda);

	}<commit_msg>Added constructors to LambertianMaterial that take Spectrums instead of Painters.<commit_after>/**
 *
 */
package ca.eandb.jmist.framework.material;

import java.io.Serializable;

import ca.eandb.jmist.framework.Painter;
import ca.eandb.jmist.framework.ScatteredRay;
import ca.eandb.jmist.framework.ScatteredRayRecorder;
import ca.eandb.jmist.framework.SurfacePoint;
import ca.eandb.jmist.framework.color.Color;
import ca.eandb.jmist.framework.color.Spectrum;
import ca.eandb.jmist.framework.color.WavelengthPacket;
import ca.eandb.jmist.framework.painter.UniformPainter;
import ca.eandb.jmist.math.RandomUtil;
import ca.eandb.jmist.math.Ray3;
import ca.eandb.jmist.math.SphericalCoordinates;
import ca.eandb.jmist.math.Vector3;

/**
 * A <code>Material</code> that reflects light equally in all directions in
 * the upper hemisphere.
 * @author <NAME>
 */
public final class LambertianMaterial extends OpaqueMaterial implements
		Serializable {

	/**
	 * Creates a new <code>LambertianMaterial</code> that does not emit light.
	 * @param reflectance The reflectance <code>Painter</code>.
	 */
	public LambertianMaterial(Painter reflectance) {
		this(reflectance, null);
	}

	/**
	 * Creates a new <code>LambertianMaterial</code> that emits light.
	 * @param reflectance The reflectance <code>Painter</code>.
	 * @param emittance The emission <code>Painter</code>.
	 */
	public LambertianMaterial(Painter reflectance, Painter emittance) {
		this.reflectance = reflectance;
		this.emittance = emittance;
	}

	/**
	 * Creates a new <code>LambertianMaterial</code> that does not emit light.
	 * @param reflectance The reflectance <code>Spectrum</code>.
	 */
	public LambertianMaterial(Spectrum reflectance) {
		this(new UniformPainter(reflectance));
	}

	/**
	 * Creates a new <code>LambertianMaterial</code> that emits light.
	 * @param reflectance The reflectance <code>Spectrum</code>.
	 * @param emittance The emission <code>Spectrum</code>.
	 */
	public LambertianMaterial(Spectrum reflectance, Spectrum emittance) {
		this(new UniformPainter(reflectance), new UniformPainter(emittance));
	}

	/* (non-Javadoc)
	 * @see ca.eandb.jmist.framework.AbstractMaterial#isEmissive()
	 */
	@Override
	public boolean isEmissive() {
		return (this.emittance != null);
	}

	/* (non-Javadoc)
	 * @see ca.eandb.jmist.framework.material.AbstractMaterial#emission(ca.eandb.jmist.framework.SurfacePoint, ca.eandb.jmist.math.Vector3, ca.eandb.jmist.framework.color.WavelengthPacket)
	 */
	@Override
	public Color emission(SurfacePoint x, Vector3 out, WavelengthPacket lambda) {

		if (this.emittance == null || x.getNormal().dot(out) < 0.0) {
			return lambda.getColorModel().getBlack(lambda);
		}

		double ndotv = x.getShadingNormal().dot(out);
		return ndotv > 0.0 ? emittance.getColor(x, lambda).times(ndotv) : lambda.getColorModel().getBlack(lambda);

	}
{'fraction_non_alphanumeric': 0.12647178237921233, 'fraction_numerical': 0.0032480714575720666, 'mean_word_length': 4.844602609727165, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3521108', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1631, 'n_words': 324}