All Implemented Interfaces:
EventEmitterInterface, EventListener, IdempotentEventListener<GPointMovedEvent,Vector3>, CanCopy, DecomposeWhenDrawn<Segment>, HasParents<GTri>, SceneObject, HasProperties

GLine represents, you guessed it, a line.

A GLine's pivot is always defined as its midpoint.

A GLine is drawn by a parent GTri but otherwise is stored alongside other GObjects within a Thing. And a GLine also draws it's relevant GPoints

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • pointA

      protected GPoint pointA
      The startpoint of this line
    • pointB

      protected GPoint pointB
      The endPoint of this line.
    • deletedState

      protected boolean deletedState
    • parents

      private HashSet<GTri> parents
    • renderState

      private RenderState<Segment,GObject> renderState
  • Constructor Details

    • GLine

      public GLine(GPoint A, GPoint B)
      Default Constructor
      Parameters:
      A - The start point
      B - THe end point
  • Method Details

    • fromRaw

      public static GLine fromRaw(String id, GPoint A, GPoint B)
      Constructs a GLine.
      Parameters:
      id - The id of the line defined by the file
      A - The first constructed GPoint reference.
      B - The second constructed GPoint reference.
      Returns:
      A GLine
    • isDeletedState

      public boolean isDeletedState()
      Overrides:
      isDeletedState in class GObject
    • addProps

      private void addProps()
    • deleteSelf

      public boolean deleteSelf()
      Description copied from class: GObject
      Deletes itself
      Overrides:
      deleteSelf in class GObject
      Returns:
      true if the line was deleted
    • getB

      public GPoint getB()
      Returns the end GPoint
      Returns:
      GPoint
    • getA

      public GPoint getA()
      Returns the start GPoint
      Returns:
      start
    • length

      public double length()
      Calculates and returns the length of this line.
      Returns:
      a double representing the length of the line.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPointStream

      public Stream<GPoint> getPointStream()
      Creates a stream of this line's points.
      Returns:
      A stream of GPoints
    • getParents

      public HashSet<GTri> getParents()
      Description copied from interface: HasParents
      Retrieves the set of all parent objects that this object belongs to.
      Specified by:
      getParents in interface HasParents<GTri>
      Returns:
      A HashSet containing all parent objects. Using a Set ensures that a parent can only be added once.
    • addParent

      public void addParent(GTri parent)
      Description copied from interface: HasParents
      Adds a parent to this object's set of parents.
      Specified by:
      addParent in interface HasParents<GTri>
      Parameters:
      parent - The parent object to add.
    • removeParent

      public void removeParent(GTri parent)
      Description copied from interface: HasParents
      Removes a parent from this object's set of parents.
      Specified by:
      removeParent in interface HasParents<GTri>
      Parameters:
      parent - The parent object to remove.
    • onEvent

      public void onEvent(EventType event, EventPayload properties)
      Description copied from interface: EventListener
      onEvent is called by EventEmitter via EventEmitter.broadcast(EventType, EventPayload). Allowing the emitter to call any other object that implements this.
      Specified by:
      onEvent in interface EventListener
      Overrides:
      onEvent in class GObject
      Parameters:
      event - The type of event
      properties - The given event payload
    • getDupeObjectToCheck

      public Vector3 getDupeObjectToCheck()
      Description copied from interface: IdempotentEventListener
      Returns the duplicate object that events of type T will calculate/generate.
      Specified by:
      getDupeObjectToCheck in interface IdempotentEventListener<GPointMovedEvent,Vector3>
      Returns:
      The duplicate object to check against.
    • handlePossibleDuplicates

      public void handlePossibleDuplicates(EventType type, GPointMovedEvent payload)
      Description copied from interface: IdempotentEventListener
      The handler to pass through for this specific type.
      Specified by:
      handlePossibleDuplicates in interface IdempotentEventListener<GPointMovedEvent,Vector3>
      Parameters:
      type - The type of event.
      payload - The payload given.
    • copy

      public void copy(CopyProperties props) throws InvalidCopyException
      Description copied from interface: CanCopy
      Copies the properties of this object based on the provided CopyProperties. The implementation should handle how the copying is performed, potentially creating a new instance or modifying an existing one.
      Specified by:
      copy in interface CanCopy
      Overrides:
      copy in class GObject
      Parameters:
      props - The properties defining how the copy operation should be performed.
      Throws:
      InvalidCopyException - If the copy operation cannot be completed due to invalid properties or state.
    • copy

      protected GLine copy(GPoint copyA, GPoint copyB)
    • getOrCreateCopy

      public static GLine getOrCreateCopy(CopyProperties copyProperties, GLine original) throws InvalidCopyException
      Throws:
      InvalidCopyException
    • explode

      public ArrayList<GPoint> explode(GTri tri)
    • identicalPoints

      public boolean identicalPoints(GPoint A, GPoint B)
      Checks if this GLine's points are identical to the given points, regardless of order.
      Parameters:
      A - The first GPoint to compare.
      B - The second GPoint to compare.
      Returns:
      true if the points match, false otherwise.
    • getInstance

      public static GLine getInstance(HashSet<GLine> lines, GPoint A, GPoint B)
      Retrieves an existing GLine from a list if its points match the given points, or creates a new GLine if no match is found.
      Parameters:
      lines - The list of existing GLines to search through.
      A - The first GPoint for comparison or new GLine creation.
      B - The second GPoint for comparison or new GLine creation.
      Returns:
      An existing GLine with matching points, or a new GLine if none exists.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class GObject
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GObject
    • toSegment

      public Segment toSegment()
    • decompose

      public void decompose()
      Specified by:
      decompose in interface DecomposeWhenDrawn<Segment>
    • genericRenderStateList

      public ArrayList genericRenderStateList()
      Overrides:
      genericRenderStateList in class GObject
    • getDecomposeList

      public ArrayList<RenderState<Segment,GObject>> getDecomposeList()
      Specified by:
      getDecomposeList in interface DecomposeWhenDrawn<Segment>
    • getEngineObjectType

      public EngineObject.Type getEngineObjectType()
      Specified by:
      getEngineObjectType in class GObject
    • toObject

      public EngineObject toObject()
      Overrides:
      toObject in class GObject