Vector2, Box, and Other Shapes

Vector2 | Box | Circle | Line | Quad | Corners

Overview

  • Plasmacore "shapes" are used for representing coordinates, drawing graphics primitives, and performing collision checks.
  • The shapes listed here are all compounds.  The actual compound defines the data while the "Manager" lists the methods that can be called on that data.  For example, if Vector2Manager lists a method magnitude(Vector2).Real64, you know you can call "v.magnitude()".
  • Vector2(x,y:Real64) is a coordinate pair that can be used for 2D position, velocity, acceleration, and size.
  • Box(top_left,size:Vector2) is an axis-aligned (orthogonal) box that can be used to represent regions of space and bounding boxes.
  • Circle(position:Vector2, radius:Real64) is typically used as a bounding shape.  Intersection tests are the fastest between two circles.
  • Line(pt1,pt2:Vector2) is used to draw lines and for collision tests.
  • Quad(top_left,top_right,bottom_right,bottom_left:Vector2) is a quadrilateral most often used to represent the corner vertices of images after they've been rotated and otherwise transformed.
  • Corners(top_left,top_right:Vector2) is an alternate form of Box that stores a top-left and bottom-right rather than a top-left and size.  It is of limited use and is primarily used to represent (u,v) texture coordinates. 

 

 

Vector2
compound
  • DESCRIPTION
    • Represents a 2D Coordinate that can be interacted with using polar or rectangular coordinates. This datatype is also useful for representing 2D vectors and includes supporting functionality such as dot and cross operations.
    • Example:
        local Vector2 v(3,4)
      
  • PROPERTIES
    • x : Real64
    • y : Real64
  • METHODS
    • init(Real64 x,Real64 y).Vector2
    • init(Vector2 Vector2).Vector2

 

Vector2Manager
singleton class : Object
  • DESCRIPTION
    • Contains methods for operating on Vector2 compounds.
  • PROPERTIES
    • zero : Vector2
    • invalid : Vector2
    • sqrt_0_5 : Real64
  • METHODS
    • create_from(Real64 _magnitude,Radians angle).Vector2
      • Creates a Vector2 compound from the given magnitude and angle in radians.
      • Example:
          local Vector2 v( 5, pi/2 )
        
    • create_from(Real64 _magnitude,Degrees angle).Vector2
      • Creates a Vector2 compound from the given _magnitude and angle in degrees.
      • Example:
          local Vector2 v( 5, Degrees(90) )
        
    • to_String(Vector2 v).String
      • Returns a string representation of 'v'.
    • area(Vector2 v).Real64
      • Returns x*y.
    • max(Vector2 v1,Vector2 v2).Vector2
      • Returns a vector containing the largest x and the largest y between the two vectors.
      • Example:
          println( max(Vector2(3,6), Vector2(4,5)) )
          # prints: (4.0,6.0)
        
    • max(Vector2 v).Real64
      • Returns the largest of the two vector components.
      • Example:
          println( Vector2(3,4).max )  # prints: 4.00
        
    • min(Vector2 v1,Vector2 v2).Vector2
      • Returns a vector containing the smallest x and the smallest y between the two vectors.
      • Example:
          println( min(Vector2(3,6), Vector2(4,5)) )
          # prints: (3.0,5.0)
        
    • min(Vector2 v).Real64
      • Returns the smallest of the two vector components.
      • Example:
          println( Vector2(3,4).min )  # prints: 3.00
        
    • bounding_box(Vector2 v).Box
      • Returns a bounding box that encloses 'v'. This will be a 1x1 Box at position 'v'.
      • Example:
          bounding_box = pt.bounding_box
        
    • bounding_circle(Vector2 v).Circle
      • Returns a bounding circle that encloses 'v'. The circle will be at position v and have radius sqrt(0.5).
      • Example:
          bounding_circle = pt.bounding_circle
        
    • abs(Vector2 v).Vector2
      • Returns the vector containing the absolute value of each component of 'v'.
      • Examples:
          println( v.abs )
          println( abs(v) )
        
    • floor(Vector2 v).Vector2
      • Returns the vector containing the floor of each component of 'v'.
      • Examples:
          println( v.floor )
          println( floor(v) )
        
    • round(Vector2 v).Vector2
      • Returns the vector containing the rounded-off values of each component of 'v'.
      • Examples:
          println( v.round )
          println( round(v) )
        
    • ceiling(Vector2 v).Vector2
      • Returns the vector containing the ceiling of each component of 'v'.
      • Examples:
          println( v.ceiling )
          println( ceiling(v) )
        
    • distance_to(Vector2 v1,Vector2 v2).Real64
      • Returns the straight-line distance between v1 and v2.
      • Example:
          println( v1.distance_to(v2) )
        
    • swapped(Vector2 v).Vector2
      • Returns a Vector2 with the components swapped; if v=Vector2(x,y) then v.swapped == Vector2(y,x).
    • transformed(Vector2 v,Transform xform).Vector2 : native
      • Applies the given transformation to the given vector.
      • Example:
          v = v.transformed( Transform().rotated(pi/2) )
        
    • rotated(Vector2 v,Radians rad).Vector2
      • Rotates 'v' around the origin by the given number of radians.
      • Example:
          v2 = v1.rotated( pi/2 )
        
    • rotated(Vector2 v,Degrees deg).Vector2
      • Rotates 'v' around the origin by the given number of degrees.
      • Example:
          v2 = v1.rotated( Degrees(90) )
        
    • normalized(Vector2 v).Vector2
      • Normalizes 'v' to have the same angle with magnitude 1.0.
      • Example:
          v = v.normalized
        
    • dot(Vector2 v1,Vector2 v2).Real64
      • Returns the dot product of 'v1' and 'v2'. Returns
          v1.x*v2.x + v1.y*v2.y
        
        

        Example:

          dot_product = v1.dot(v2)
        
    • cross(Vector2 v1,Vector2 v2).Real64
      • Returns the cross product of 'v1' and 'v2':
          v1.x*v2.y - v1.y*v2.x
        
        

        Example:

          cross_product = v1.cross(v2)
        
    • parallelum(Vector2 v,Vector2 axis).Vector2
      • Returns the component of 'v' that lies along the axis defined by the second parameter.
      • Example:
          x = v.parallelum(axis)
        
    • perpendiculum(Vector2 v,Vector2 axis).Vector2
      • Returns the component of 'v' that lies perpendicular to the axis defined by the second parameter.
      • Example:
          y = v.perpendiculum(axis)
        
    • parallelum(Vector2 v,Line line).Vector2
      • Returns the component of 'v' that lies along the axis defined by the second parameter.
      • Example:
          x = v.parallelum(axis)
        
    • perpendiculum(Vector2 v,Line line).Vector2
      • Returns the component of 'v' that lies perpendicular to the axis defined by the second parameter.
      • Example:
          y = v.perpendiculum(axis)
        
    • projection_on(Vector2 v,Line line).Vector2
      • Returns the projection of 'v' on 'line'. The return value is a point along the axis of 'line' although it may be outside the beginning or end point of the line.
      • Example:
          y = v.projection_on(axis)
        
    • clamped(Vector2 v,Box b).Vector2
      • Adjusts 'v' to be within the boundaries of the given box.
      • Example:
          cursor = cursor.clamped( display_region )
        
    • clamped(Vector2 v,Corners c).Vector2
      • Adjusts 'v' to be within the given corners.
      • Example:
          cursor = cursor.clamped( Corners(-1,-1,1,1) )
        
    • clamped(Vector2 v,Real64 x1,Real64 y1,Real64 x2,Real64 y2).Vector2
      • Adjusts 'v' to be within the given corners.
      • Example:
          cursor = cursor.clamped(-1,-1,1,1)
        
    • clamped(Vector2 v,Line line).Vector2
      • Returns the point along the given line segment that is closest to 'v'.
      • Example:
      •   closest_pt_on_line = v.clamped(line)
        
        

        Notes:

      • Points along the line are defined by:
      •   Line(t) = line.pt1 + t * (line.pt2 - line.pt1)
        
        

        where t is 0 to 1. We can define t as:

      •   A = v - line.pt1
          B = line.pt2 - line.pt1
          t = dot(A,B) / dot(B,B)
        
        

        as this is the projection of A along and proportional to B.

    • is_on_line(Vector2 v,Line line[,Real64 tolerance]).Logical
      • Returns true if 'v' is on the given line with the given tolerance.
    • normal(Vector2 v).Vector2
      • Returns the normal of the given vector.
      • Example:
          println( v.normal )
        
    • radians(Vector2 v).Radians
      • Returns the angle of the given vector in radians.
      • Example:
          println( v.radians )
        
    • degrees(Vector2 v).Degrees
      • Returns the angle of the given vector in degrees.
      • Example:
          println( v.degrees )
        
    • magnitude(Vector2 v).Real64
      • Returns the magnitude (radial length) of the given vector.
      • Example:
          println( v.magnitude )
        
    • op+(Vector2 v1,Vector2 v2).Vector2
      • Returns the vector sum v3 = v1 + v2 where
          v3.x = v1.x + v2.x
          v3.y = v1.y + v2.y
        
        

        Examples:

          v3 = v1 + v2
          v1 += v2
        
    • op-(Vector2 v1,Vector2 v2).Vector2
      • Returns the vector sum v3 = v1 - v2 where
          v3.x = v1.x - v2.x
          v3.y = v1.y - v2.y
        
        

        Examples:

          v3 = v1 - v2
          v1 -= v2
        
    • op*(Vector2 v1,Vector2 v2).Vector2
      • Returns the vector product v3 = v1 * v2 where
          v3.x = v1.x * v2.x
          v3.y = v1.y * v2.y
        
        

        Examples:

          v3 = v1 * v2
          v1 *= v2
        
    • op/(Vector2 v1,Vector2 v2).Vector2
      • Returns the vector product v3 = v1 / v2 where
          v3.x = v1.x / v2.x
          v3.y = v1.y / v2.y
        
        

        Examples:

          v3 = v1 / v2
          v1 /= v2
        
    • op%(Vector2 v1,Vector2 v2).Vector2
      • Returns the vector product v3 = v1 % v2 where
          v3.x = v1.x % v2.x
          v3.y = v1.y % v2.y
        
        

        Examples:

          v3 = v1 % v2
          v1 %= v2
        
    • op-(Vector2 v).Vector2
      • Returns the negative of this vector v2 = -v1 where
          v2.x = -v1.x
          v2.y = -v1.y
        
        

        Example:

          v1 = -v1
        
    • op+(Vector2 v1,Real64 n).Vector2
      • Adds 'n' to both components of v1. Equivalent to
          v1 + Vector2(n,n)
        
        

        Examples:

          v = v + 5
          v += 5
        
    • op-(Vector2 v1,Real64 n).Vector2
      • Subtracts 'n' from both components of v1. Equivalent to
          v1 - Vector2(n,n)
        
        

        Examples:

          v = v - 5
          v -= 5
        
    • op*(Vector2 v1,Real64 n).Vector2
      • Multiplies both components of v1 by 'n'. Equivalent to
          v1 * Vector2(n,n)
        
        

        Examples:

          v = v * 5
          v *= 5
        
    • op/(Vector2 v1,Real64 n).Vector2
      • Divides both components of v1 by 'n'. Equivalent to
          v1 / Vector2(n,n)
        
        

        Examples:

          v = v / 5
          v /= 5
        
    • op%(Vector2 v1,Real64 n).Vector2
      • Returns the Vector2 modulo of each component of 'v1' divided by 'n'. Equivalent to
          v1 % Vector2(n,n)
        
        

        Examples:

          v = v % 5
          v %= 5
        
    • op+(Real64 n,Vector2 v).Vector2
      • Equivalent to Vector2(n,n) + v
      • Example:
          v = 5 + v
        
    • op-(Real64 n,Vector2 v).Vector2
      • Equivalent to Vector2(n,n) - v
      • Example:
          v = 5 - v
        
    • op*(Real64 n,Vector2 v).Vector2
      • Equivalent to Vector2(n,n) * v
      • Example:
          v = 5 * v
        
    • op/(Real64 n,Vector2 v).Vector2
      • Equivalent to Vector2(n,n) / v
      • Example:
          v = 5 / v
        
    • op%(Real64 n,Vector2 v).Vector2
      • Equivalent to Vector2(n,n) % v
      • Example:
          v = 5 % v
        
    • draw(Vector2 v,Color color[,Render render_flags]) : native
      • Draws the specified color at the given point 'v'.
      • Example:
          v.draw( Color.red )
        
    • init_object()
    • hash_code().Int32
    • create_duplicate().Object
    • to_String().String
    • op==(Object other).Logical {multimethod}
    • op<>(Object other).Logical {multimethod}
    • type_name().String : native
    • runtime_type().RuntimeType : native
    • runtime_properties().RuntimeProperties
    • runtime_methods().RuntimeMethods

 

Box
compound
  • DESCRIPTION
    • Compound representing an abstract 2D box with a top-left 'position' and a total size. Used for sub-image specification, collision physics, and the like.
    • The coordinates and dimensions of a Box use a continuous rather than discrete interval, meaning that a box at position (0,0) and having size (5,10) will have a bottom-right coordinate of (5,10) and not (4,9).
    • Example:
        local Box recticle( view.size/2 - 10, Vector2(20,20) )
      
  • PROPERTIES
    • position : Vector2
    • size : Vector2
  • METHODS
    • init(Vector2 position,Vector2 size).Box
    • init(Box Box).Box

 

BoxManager
singleton class : Object
  • DESCRIPTION
    • Contains methods for operating on Box compounds.
  • METHODS
    • create_from(Vector2 size).Box
      • Creates a Box compound with the given size and position (0,0).
      • Example:
          local Box screen_region( view.size )
        
    • create_from(Corners c).Box
      • Creates a Box compound with the given corners.
      • Example:
          local Box recticle( Corners(view.size/2 - 10, view.size/2 + 10) )
        
    • create_from(Real64 x,Real64 y,Real64 width,Real64 height).Box
      • Creates a Box compound with the given position and size.
      • Example:
          local Box bounding_box(x,y,64,64)
        
    • to_String(Box box).String
      • Returns a string representation of 'box'.
    • transformed(Box box,Transform xform).Quad : native
      • Applies the given transformation to the given box. Note that the result is a Quad, not a Box.
      • Example:
          quad = box.transformed( Transform().rotated(pi/2) )
        
    • op+(Box box,Vector2 v).Box
      • Shifts the position of 'box' by +v.
      • Examples:
          new_pos = box + offset 
          box += offset 
        
    • op-(Box box,Vector2 v).Box
      • Shifts the position of 'box' by -v.
      • Examples:
          new_pos = box - offset 
          box -= offset 
        
    • op*(Box box,Vector2 n).Box
      • Scales the "vertices" of 'box' by 'n'.
      • Examples:
          b3 = b2 * b1 
          box *= scale
        
    • op*(Box box,Real64 n).Box
      • Scales the "vertices" of 'box' by 'n'.
      • Examples:
          b2 = b1 * factor
          box *= factor 
        
    • op/(Box box,Vector2 n).Box
      • Scales the "vertices" of 'box' by '1/n'.
      • Examples:
          b2 = b1 / scale
          box /= scale 
        
    • op/(Box box,Real64 n).Box
      • Scales the "vertices" of 'box' by '1/n'.
      • Examples:
          b1 = b1 / factor
          box /= factor 
        
    • scaled(Box box,Vector2 factor).Box
      • Scales the size of 'box' by 'factor' without affecting the position.
      • Example:
          half_height = box.scaled( Vector2(1.0,0.5) )
        
    • scaled(Box box,Real64 factor).Box
      • Scales the size of 'box' by 'factor' without affecting the position.
      • Example:
          half_size = box.scaled( 0.5 )
        
    • x1(Box box).Real64
      • Returns the leftmost x coordinate of 'box'.
      • Example:
          println( "left edge:$" (box.x1) )
        
    • y1(Box box).Real64
      • Returns the topmost y coordinate of 'box'.
      • Example:
          println( "top edge:$" (box.y1) )
        
    • x2(Box box).Real64
      • Returns the rightmost x coordinate of 'box'.
      • Example:
          println( "right edge:$" (box.x2) )
        
    • y2(Box box).Real64
      • Returns the bottommost y coordinate of 'box'.
      • Example:
          println( "bottom edge:$" (box.y2) )
        
    • top_left(Box box).Vector2
      • Returns the top-left corner of 'box'.
      • Example:
          println( box.top_left )
        
    • top_right(Box box).Vector2
      • Returns the top-right corner of 'box'.
      • Example:
          println( box.top_right )
        
    • bottom_right(Box box).Vector2
      • Returns the bottom-right corner of 'box'.
      • Example:
          println( box.bottom_right )
        
    • bottom_left(Box box).Vector2
      • Returns the bottom-left corner of 'box'.
      • Example:
          println( box.bottom_left )
        
    • width(Box box).Real64
      • Returns the width of 'box'.
      • Example:
          println( box.width )
        
    • height(Box box).Real64
      • Returns the height of 'box'.
      • Example:
          println( box.height )
        
    • center(Box box).Vector2
      • Returns the center point of 'box'.
      • Example:
          local Vector2 sprite_center = sprite.bounding_box.center
        
    • area(Box box).Real64
      • Returns the area of 'box' (width * height).
      • Example:
          println( box.area ) 
        
    • contains(Box box,Vector2 pt).Logical
      • Returns "true" if 'box' contains the given point.
      • Example:
          println( actor.bounding_box.contains(Input.mouse_position) )
        
    • contains(Box box1,Box box2).Logical
      • Returns true if 'box1' contains 'box2'. An exactly overlapping 'box2' would count as being contained within 'box1'.
    • intersects(Box box1,Box box2).Logical
      • Returns "true" if rectangles box1 and box2 intersect at all.
      • Example:
          if (actor1.bounding_box.intersects(actor2.bounding_box)) ...
        
    • intersection(Box box1,Box box2).Box
      • Returns the box defining the area that is common to both 'box1' and 'box2'. If the result's size is zero then the rectangles do not overlap.
      • Example:
          collision_region = actor1.bounding_box.intersection(actor2.bounding_box)
          if (collision_region.area?) ...
        
    • intersects(Box box,Line line).Logical
      • Returns true if 'box' and 'line' intersect.
      • Example:
          if (box.intersects(line)) ...
        
    • intersection(Box box,Line line).Line
      • See Line::intersection(Box).
    • expanded(Box box,Real64 per_side).Box
      • Returns a box that is 'per_side' units larger on every side.
      • Example:
          padded_box = box.expanded(16)
        
    • expanded(Box box,Vector2 amount).Box
      • Returns a box that is "amount.x" units larger on the left and right sides and "amount.y" units larger on the top and bottom.
      • Example:
          padded_box = box.expanded(border_size)
        
    • cropped(Box box,Real64 per_side).Box
      • Returns a box that is 'per_side' units smaller on every side.
      • Example:
          smaller_box = box.cropped(16)
        
    • cropped(Box box,Vector2 amount).Box
      • Returns a box that is smaller on the left and right sides by "amount.x" and is smaller on the top and bottom sides by "amount.y".
      • Example:
          smaller_box = box.cropped(border_size)
        
    • enclosing(Box b,Vector2 pt).Box
      • Returns a box just big enough to contain the given box and the given point.
    • enclosing(Box box1,Box box2).Box
      • Returns a box just big enough to contain both given rectangles.
    • bounding_circle(Box box).Circle
      • Creates a circle just big enough to contain the given box.
      • Example:
          hit_zone = sprite.bounding_circle
        
    • fill(Box box,Color color)
      • Draws 'box' to the screen filled with the given color.
      • Example:
          box.fill( COLOR.red )
        
    • fill(Box box,ColorGradient colors)
      • Draws 'box' to the screen as a gradient fill. The four colors are assigned clockwise starting with the top-left corner.
    • draw(Box box,Color color)
      • Draws an outline of 'box' to the screen in the given color.
      • Example:
          box.draw( COLOR.white )
        
    • init_object()
    • hash_code().Int32
    • create_duplicate().Object
    • to_String().String
    • op==(Object other).Logical {multimethod}
    • op<>(Object other).Logical {multimethod}
    • type_name().String : native
    • runtime_type().RuntimeType : native
    • runtime_properties().RuntimeProperties
    • runtime_methods().RuntimeMethods

 

Circle
compound
  • DESCRIPTION
    • Defines an abstract circle as 'position' and 'radius'. Note: Circle drawing requires many operations!
  • PROPERTIES
    • position : Vector2
    • radius : Real64
  • METHODS
    • init(Vector2 position,Real64 radius).Circle
    • init(Circle Circle).Circle

  

CircleManager
singleton class : Object
  • DESCRIPTION
    • Contains methods for operating on Circle compounds.
  • METHODS
    • enclosing(Circle circle,Vector2 v).Circle
      • Creates a circle just big enough to contain the given circle and vector.
      • Example:
          circle = circle.enclosing(pt)
        
    • enclosing(Circle c1,Circle c2).Circle
      • Creates a circle just big enough to contain both given circles.
      • Example:
          hit_zone = body.bounding_circle.enclosing(left_wing).enclosing(right_wing)
        
    • to_String(Circle circle).String
      • Returns a string representation of 'circle'.
    • point_at(Circle circle,Radians angle).Vector2
      • Returns the point along the edge of the circle at the given angle.
      • Example:
          one_oclock = circle.point_at( 2*pi/12 )
        
    • point_at(Circle circle,Degrees angle).Vector2
      • Returns the point along the edge of the circle at the given angle.
      • Example:
          one_oclock = circle.point_at( Degrees(360.0/12.0) )
        
    • transformed(Circle circle,Transform xform).Circle : native
      • Applies the given transformation to the given circle. The result will be incorrect for scaling operations that do not preserve aspect ratio (e.g. same width with half height). A future version of Plasmacore may address this.
      • Example:
          circle = circle.transformed( Transform().rotated(pi/2) )
        
    • op+(Circle circle,Vector2 v).Circle
      • Shifts the position of 'circle' by +v.
      • Examples:
          circle2 = circle1 + offset
          circle += offset
        
    • op-(Circle circle,Vector2 v).Circle
      • Shifts the position of 'circle' by -v.
      • Examples:
          circle2 = circle1 - offset
          circle -= offset
        
    • op*(Circle circle,Real64 n).Circle
      • Scales the position and size of 'circle' by 'n'.
      • Examples:
          circle2 = circle1 * k
          circle *= k
        
    • op/(Circle circle,Real64 n).Circle
      • Scales the position and size of 'circle' by '1/n'.
      • Examples:
          circle2 = circle1 / k
          circle /= k
        
    • scaled(Circle circle,Real64 factor).Circle
      • Scales the radius of 'circle' by 'factor' without affecting the position.
      • Example:
          circle = circle.scaled(2)
        
    • x1(Circle circle).Real64
      • Returns the leftmost coordinate of the given circle.
      • Example:
          println( circle.x1 )
        
    • y1(Circle circle).Real64
      • Returns the topmost coordinate of the given circle.
      • Example:
          println( circle.y1 )
        
    • x2(Circle circle).Real64
      • Returns the rightmost coordinate of the given circle.
      • Example:
          println( circle.x2 )
        
    • y2(Circle circle).Real64
      • Returns the bottommost coordinate of the given circle.
      • Example:
          println( circle.y2 )
        
    • intersects(Circle c1,Circle c2).Logical
      • Returns "true" if c1 and c2 intersect.
      • Example:
          if (circle1.intersects(circle2)) ...
        
    • intersects(Circle circle,Line line).Logical
      • Returns true if 'line' and 'circle' intersect.
      • Example:
          if (circle1.intersects(line)) ...
        
    • bounding_box(Circle circle).Box
      • Returns a box just big enough to contain the given circle.
      • Example:
          local Box bounds = circle.bounding_box
        
    • draw(Circle circle,Color color[,Real64 segments])
      • Draws the given circle to the screen in the given color.
      • Parameters:
          circle
            The circle to draw, centered at "circle.position" and with
            pixel radius "circle.radius".
        
          color
            The color to draw the circle in.
        
          segments [default: (1.0/12.0)]
            If whole - the number of segements.  
            If fractional -  the number of segements is dynamically determined 
            as this fraction of the circle's circumference.
        
        

        Example:

          Circle(view.size/2, 16).draw( Color.blue )
        
    • init_object()
    • hash_code().Int32
    • create_duplicate().Object
    • to_String().String
    • op==(Object other).Logical {multimethod}
    • op<>(Object other).Logical {multimethod}
    • type_name().String : native
    • runtime_type().RuntimeType : native
    • runtime_properties().RuntimeProperties
    • runtime_methods().RuntimeMethods

 

Line
compound
  • DESCRIPTION
    • Defines an abstract line as a 'pt1' and an 'pt2' coordinate pair.
    • Example:
        local Line line( Vector2(0,0), view.size )
      
  • PROPERTIES
    • pt1 : Vector2
    • pt2 : Vector2
  • METHODS
    • init(Vector2 pt1,Vector2 pt2).Line
    • init(Line Line).Line

  

LineManager
singleton class : Object
  • DESCRIPTION
    • Contains methods for operating on Line compounds.
  • PROPERTIES
    • invalid : Line
  • METHODS
    • create_from(Real64 x1,Real64 y1,Real64 x2,Real64 y2).Line
      • Creates a Line from (x1,y1) to (x2,y2).
      • Example:
          local Line line( x1, y2, x2, y2 )
        
    • bounding_box(Line line).Box
      • Returns a box just big enough to contain the given line.
    • bounding_circle(Line line).Circle
      • Creates a circle just big enough to contain the given line.
      • Example:
          hit_zone = line.bounding_circle
        
    • to_String(Line line).String
      • Returns a string representation of 'line'.
    • point_along(Line line,Real64 p).Vector2
      • Returns the point along the given line corresponding to fraction 'p', where 0 <= p <= 1.0.
      • Invariant:
          point_along(line,0.0) == line.pt1
          point_along(line,0.5) == line.center
          point_along(line,1.0) == line.pt2
        
        

        Example:

          three_quarters = line.point_along(0.75)
        
    • center(Line line).Vector2
      • Returns the center point of the given line.
      • Example:
          m = line.center
        
    • midpoint(Line line).Vector2
      • Returns the point in the middle of the given line. Equivalent to center().
      • Example:
          m = line.midpoint
        
    • length(Line line).Real64
      • Returns the length of the given line.
      • Example:
          println( line.length )
        
    • transformed(Line line,Transform xform).Line : native
      • Applies the given transformation to the given vector.
      • Example:
          line = line.transformed( Transform().rotated(pi/2) )
        
    • op+(Line line,Vector2 v).Line
      • Shifts the position of 'line' by +v.
      • Examples:
          line2 = line1 + Vector2(5,0)
          line += Vector2(5,0)
        
    • op-(Line line,Vector2 v).Line
      • Shifts the position of 'line' by -v.
      • Examples:
          line2 = line1 - Vector2(5,0)
          line -= Vector2(5,0)
        
    • op*(Line line,Vector2 n).Line
      • Scales the position of 'line' by n.
      • Examples:
          line2 = line1 * Vector2(1024,768)
          line *= Vector2(1024,768)
        
    • op*(Line line,Real64 n).Line
      • Scales the position of 'line' by n.
      • Examples:
          line2 = line1 * 2
          line *= 2
        
    • op/(Line line,Vector2 n).Line
      • Scales the position of 'line' by 1/n.
      • Examples:
          line2 = line1 / Vector2(1024,768)
          line /= Vector2(1024,768)
        
    • op/(Line line,Real64 n).Line
      • Scales the position of 'line' by 1/n.
      • Examples:
          line2 = line1 / 2
          line /= 2
        
    • intersection(Line line1,Line line2).Vector2
      • Returns the point of intersection between line1 and line 2 or Vector2.invalid ("Vector2(NaN,NaN)") if there is no intersection.
      • Example:
          local var intersection = line1.intersection(line2) 
          if (intersection != Vector2.invalid ) ...
        
    • intersects(Line line1,Line line2).Logical
      • Returns true if line segments 'line1' and 'line2' intersect. Use 'intersection' to determine the point of intersection.
      • Example:
          if (line1.intersects(line2)) ...
        
    • intersects(Line line,Circle circle).Logical
      • Returns true if 'line' and 'circle' intersect.
      • Example:
          if (line.intersects(circle)) ...
        
    • intersects(Line line,Box box).Logical
      • Returns true if 'line' and 'box' intersect.
      • Example:
          if (line.intersects(box)) ...
        
    • intersection(Line line,Box box).Line
      • This method clips a line to a box, returning a line segment that is enclosed by the box if such a segment exists.
      • The result will be Line.invalid if the line is completely outside the Box. If you know the line originates from outside the box, you can use this method to determine IF and where a line intersets a box at both points.
      • This is implemented using the Liang-Barsky line clipping algorithm.
    • draw(Line line,Color color[,Render render_flags]) : native
      • Draws the given line to the screen in the given color.
      • Example:
          line.draw( Color.yellow )
        
    • init_object()
    • hash_code().Int32
    • create_duplicate().Object
    • to_String().String
    • op==(Object other).Logical {multimethod}
    • op<>(Object other).Logical {multimethod}
    • type_name().String : native
    • runtime_type().RuntimeType : native
    • runtime_properties().RuntimeProperties
    • runtime_methods().RuntimeMethods

 

Quad
compound
  • DESCRIPTION
    • Defines an abstract geometric quadrangle composed of four vertices.
  • PROPERTIES
    • top_left : Vector2
    • top_right : Vector2
    • bottom_right : Vector2
    • bottom_left : Vector2
  • METHODS
    • init(Vector2 top_left,Vector2 top_right,Vector2 bottom_right,Vector2 bottom_left).Quad
    • init(Quad Quad).Quad

  

QuadManager
singleton class : Object
  • DESCRIPTION
    • Contains methods for operating on Quad compounds.
  • METHODS
    • create_from(Box box).Quad
      • Creates a Quad with the same position and size as the given box.
    • create_from(Corners corners).Quad
    • to_String(Quad q).String
      • Returns a string representation of 'q'.
    • bounding_box(Quad quad).Box
      • Returns a bounding box that encloses 'quad'.
      • Example:
          bounding_box = quad.bounding_box
        
    • bounding_circle(Quad quad).Circle
      • Returns a bounding circle that encloses 'quad'.
      • Example:
          bounding_circle = quad.bounding_circle
        
    • transformed(Quad quad,Transform xform).Quad : native
      • Applies the given transformation to the given quad.
      • Example:
          quad = quad.transformed( Transform().rotated(pi/2) )
        
    • op+(Quad quad,Vector2 n).Quad
      • Shifts the vertices of 'quad' by n.
      • Examples:
          quad2 = quad1 + n
          quad += n
        
    • op-(Quad quad,Vector2 n).Quad
      • Shifts the vertices of 'quad' by -n.
      • Examples:
          quad2 = quad1 - n
          quad -= n
        
    • op*(Quad quad,Vector2 n).Quad
      • Scales the vertices of 'quad' by n.
      • Examples:
          quad2 = quad1 * n
          quad *= n
        
    • op*(Quad quad,Real64 n).Quad
      • Scales the vertices of 'quad' by n.
      • Examples:
          quad2 = quad1 * n
          quad *= n
        
    • op/(Quad quad,Vector2 n).Quad
      • Scales the vertices of 'quad' by 1/n.
      • Examples:
          quad2 = quad1 / n
          quad /= n
        
    • op/(Quad quad,Real64 n).Quad
      • Scales the vertices of 'quad' by 1/n.
      • Examples:
          quad2 = quad1 / n
          quad /= n
        
    • fill(Quad quad,Color color)
      • Draws 'q' to the screen filled with the given color.
      • Example:
          quad.fill( Color.red )
        
    • fill(Quad quad,ColorGradient colors[,Render render_flags]) : native
      • Draws 'q' to the screen as a gradient fill. The four colors in the gradient are assigned clockwise starting with the first vertex.
    • draw(Quad q,Color color)
      • Draws an outline of 'q' to the screen in the given color.
      • Example:
          quad.draw( Color.black )
        
    • init_object()
    • hash_code().Int32
    • create_duplicate().Object
    • to_String().String
    • op==(Object other).Logical {multimethod}
    • op<>(Object other).Logical {multimethod}
    • type_name().String : native
    • runtime_type().RuntimeType : native
    • runtime_properties().RuntimeProperties
    • runtime_methods().RuntimeMethods

 

Corners
compound
  • DESCRIPTION
    • Compound consisting of two corners. Exists both as a means to create a box from two corners rather than a corner and a size and as a way to store data such as UV coordinates that are "naturally" represented as two points rather than as a point and a size.
    • Example:
        local Corners c( center-0.5, center+0.5 )
      
  • PROPERTIES
    • top_left : Vector2
    • bottom_right : Vector2
  • METHODS
    • init(Vector2 top_left,Vector2 bottom_right).Corners
    • init(Corners Corners).Corners

 

CornersManager
singleton class : Object
  • DESCRIPTION
    • Contains methods for operating on Corners compounds.
  • METHODS
    • create_from(Real64 x1,Real64 y1,Real64 x2,Real64 y2).Corners
      • Creates a Corners compound from the given top-left and bottom- right coordinates.
      • Example:
          local Corners c( x1, y1, x2, y2 )
        
    • create_from(Vector2 position).Corners
      • Creates a corners compound with 'position' as both the top-left and bottom-right coordinates.
      • Example:
          local Corners c( pt )
        
    • create_from(Box b).Corners
      • Creates a corners compound with the same dimensions as 'b'.
      • Example:
          local Corners img_corners( img.bounding_box )
        
    • to_String(Corners c).String
      • Returns a string representation of 'c'.
    • bounding_box(Corners corners).Box
      • Returns a bounding box that encloses 'corners'.
      • Example:
          bounding_box = corners.bounding_box
        
    • bounding_circle(Corners corners).Circle
      • Returns a bounding circle that encloses 'corners'.
      • Example:
          bounding_circle = corners.bounding_circle
        
    • x1(Corners c).Real64
      • Returns the leftmost x coordinate of 'c'.
      • Example:
          println( "left edge:$" (corners.x1) )
        
    • y1(Corners c).Real64
      • Returns the topmost y coordinate of 'c'.
      • Example:
          println( "top edge:$" (corners.y1) )
        
    • x2(Corners c).Real64
      • Returns the rightmost x coordinate of 'c'.
      • Example:
          println( "right edge:$" (corners.x2) )
        
    • y2(Corners c).Real64
      • Returns the bottommost y coordinate of 'c'.
      • Example:
          println( "bottom edge:$" (corners.y2) )
        
    • size(Corners c).Vector2
      • Returns the size of 'c' as a Vector2.
      • Example:
          println( "Dimensions: $" (corners.size) )
        
    • transformed(Corners corners,Transform xform).Quad : native
      • Applies the given transformation to the given corners. Note that the result is type Quad, not type Corners.
      • Example:
          quad = corners.transformed( Transform().rotated(pi/2) )
        
    • op+(Corners corners,Vector2 v).Corners
      • Shifts the position of 'corners' by +v.
      • Example:
          corners = corners + origin
        
    • op-(Corners corners,Vector2 v).Corners
      • Shifts the position of 'corners' by -v.
      • Example:
          corners = corners - origin
        
    • op*(Corners corners,Vector2 n).Corners
      • Scales the "vertices" of 'corners' by 'n'.
      • Example:
          corners = corners * scale
        
    • op*(Corners corners,Real64 n).Corners
      • Scales the "vertices" of 'corners' by 'n'.
      • Example:
          corners = corners * k
        
    • op/(Corners corners,Vector2 n).Corners
      • Scales the "vertices" of 'corners' by '1/n'.
      • Example:
          corners = corners / scale
        
    • op/(Corners corners,Real64 n).Corners
      • Scales the "vertices" of 'corners' by '1/n'.
      • Example:
          corners = corners / k
        
    • init_object()
    • hash_code().Int32
    • create_duplicate().Object
    • to_String().String
    • op==(Object other).Logical {multimethod}
    • op<>(Object other).Logical {multimethod}
    • type_name().String : native
    • runtime_type().RuntimeType : native
    • runtime_properties().RuntimeProperties
    • runtime_methods().RuntimeMethods