001/*
002 * Renderer 4. The MIT License.
003 * Copyright (c) 2022 rlkraft@pnw.edu
004 * See LICENSE for details.
005*/
006
007package renderer.scene.primitives;
008
009import java.util.List;
010
011/**
012   A {@code LineSegment} object has four integers that
013   represent the endpoints of the line segment and the
014   color at each endpoint. Two of the integers are indices
015   into the {@link renderer.scene.Vertex} list of a
016   {@link renderer.scene.Model} object and the other two
017   integers are indices into the {@link java.awt.Color}
018   list of that {@link renderer.scene.Model} object.
019*/
020public class LineSegment extends Primitive
021{
022   /**
023      Construct a {@code LineSegment} object using two integer indices.
024      Use the given indices for both the vertex and the color lists.
025
026      @param i0  index of 1st endpoint {@link renderer.scene.Vertex} and color of the new {@code LineSegment}
027      @param i1  index of 2nd endpoint {@link renderer.scene.Vertex} and color of the new {@code LineSegment}
028   */
029   public LineSegment(final int i0, final int i1)
030   {
031      this(i0, i1, i0, i1);
032   }
033
034
035   /**
036      Construct a {@code LineSegment} object using two integer indices
037      for the vertices and one integer index for the colors.
038
039      @param i0  index of 1st endpoint {@link renderer.scene.Vertex} of the new {@code LineSegment}
040      @param i1  index of 2nd endpoint {@link renderer.scene.Vertex} of the new {@code LineSegment}
041      @param c   index of the color of the new {@code LineSegment}
042   */
043   public LineSegment(final int i0, final int i1,
044                      final int c)
045   {
046      this(i0, i1, c, c);
047   }
048
049
050   /**
051      Construct a {@code LineSegment} object using two integer indices
052      for the vertices and two integer indices for the colors.
053      <p>
054      NOTE: This constructor does not put any {@link renderer.scene.Vertex}
055      or {@link java.awt.Color} objects into this {@link Primitive}'s
056      {@link renderer.scene.Model} object. This constructor assumes that
057      the given indices are valid (or will be valid by the time this
058      {@link Primitive} gets rendered).
059
060      @param i0  index of 1st endpoint {@link renderer.scene.Vertex} of the new {@code LineSegment}
061      @param i1  index of 2nd endpoint {@link renderer.scene.Vertex} of the new {@code LineSegment}
062      @param c0  index of 1st endpoint {@link java.awt.Color} of the new {@code LineSegment}
063      @param c1  index of 2nd endpoint {@link java.awt.Color} of the new {@code LineSegment}
064   */
065   public LineSegment(final int i0, final int i1,
066                      final int c0, final int c1)
067   {
068      super();
069
070      vIndexList.add(i0);
071      vIndexList.add(i1);
072      cIndexList.add(c0);
073      cIndexList.add(c1);
074   }
075
076
077   /**
078      Construct a {@code LineSegment} object using the two given
079      {@link List}s of integer indices.
080      <p>
081      NOTE: This constructor does not put any {@link renderer.scene.Vertex}
082      or {@link java.awt.Color} objects into this {@link Primitive}'s
083      {@link renderer.scene.Model} object. This constructor assumes that
084      the given indices are valid (or will be valid by the time this
085      {@link Primitive} gets rendered).
086
087      @param vIndexList  {@link List} of integer indices into a {@link renderer.scene.Vertex} list
088      @param cIndexList  {@link List} of integer indices into a {@link java.awt.Color} list
089      @throws NullPointerException if {@code vIndexList} is {@code null}
090      @throws NullPointerException if {@code cIndexList} is {@code null}
091      @throws IllegalArgumentException if the size of {@code vIndexList} or {@code cIndexList} is not 2
092   */
093   public LineSegment(final List<Integer> vIndexList,
094                      final List<Integer> cIndexList)
095   {
096      super(vIndexList, cIndexList);
097
098      if ( 2 != vIndexList.size() )
099         throw new IllegalArgumentException("the vertex index list must have length 2");
100      if ( 2 != cIndexList.size() )
101         throw new IllegalArgumentException("the color index list must have length 2");
102   }
103
104
105   /**
106      For debugging.
107
108      @return {@link String} representation of this {@code LineSegment} object
109   */
110   @Override
111   public String toString()
112   {
113      return "LineSegment: ([" + vIndexList.get(0) + ", " + vIndexList.get(1) + "], "
114                         + "[" + cIndexList.get(0) + ", " + cIndexList.get(1) + "])";
115   }
116}