eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'LineSegment':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: LineSegment


Inheritance:

   Object
   |
   +--Geometric
      |
      +--LineSegment
         |
         +--Arrow
         |
         +--Bezier2Segment

Package:
stx:libbasic2
Category:
Graphics-Geometry-Objects
Version:
rev: 1.21 date: 2009/06/06 10:07:44
user: cg
file: LineSegment.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


LineSegments represent a line consisting of start and endPoint
(actually, its a vector, since the direction makes a difference when
 instances are compared using #=).


Related information:

    Rectangle
    Polygon
    EllipticalArc
    Circle
    Spline
    Curve
    Point
    Arrow
    ArrowedSpline
    GraphicsContext
    StrokingWrapper

Class protocol:

instance creation
o  from: start to: end
return a new lineSegment.

o  with: p1 with: p2
return a new lineSegment; the smaller point is taken as startPoint.


Instance protocol:

accessing
o  end
return the endPoint

o  end: aPoint
set the endPoint

o  setStart: p1 end: p2
set both the startPoint and the endPoint

o  start
return the startPoint

o  start: aPoint
set the startPoint

o  start: p1 end: p2
set both the startPoint and the endPoint.
Obsolete - use setStart:end: for VW compatibility.

** This is an obsolete interface - do not use it (it may vanish in future versions) **

comparing
o  = aLineSegment
return true, if the receiver represents the same lineSegment
as the argument, aLineSegment

o  hash
return a number useul for hashing.
Redefined, since #= is redefined.

converting
o  asPointArray
return an array containing my points.

displaying
o  displayFilledOn: aGC
raise an error - a lineSegment cannot be drawn filled

o  displayStrokedOn: aGC
display the receiver in the graphicsContext, aGC

printing
o  printOn: aStream

queries
o  angle
return the receiver's angle (in degrees) in a polar coordinate system.
The angle is counted counter-clock-wise, starting with 0 for a horizontal
line (i.e. 0@0 -> 100@0 has an angle of 0 and 0@0 -> 0@100 has an angle of 90)

usage example(s):

     (LineSegment from:0@0 to:100@0) angle
     (LineSegment from:0@0 to:100@100) angle   
     (LineSegment from:0@0 to:0@100) angle      
     (LineSegment from:0@0 to:-100@100) angle
     (LineSegment from:0@0 to:-100@0) angle
     (LineSegment from:0@0 to:-100@-100) angle
     (LineSegment from:0@0 to:0@-100) angle

o  center
(LineSegment from:(10@10) to:(20@10)) center
(LineSegment from:(10@10) to:(20@20)) center

o  computeBounds
return the smallest enclosing rectangle

o  dist: aPoint
the distance of aPoint to this segment

usage example(s):

(startPoint dist:aPoint)

usage example(s):

(endPoint dist:aPoint)

usage example(s):

     (LineSegment from:(0@0) to:(10@10)) dist:0@0      
     (LineSegment from:(0@0) to:(10@10)) dist:10@10    
     (LineSegment from:(0@0) to:(10@10)) dist:11@10    
     (LineSegment from:(0@0) to:(10@10)) dist:-1@-1    
     (LineSegment from:(0@0) to:(10@10)) dist:5@5      
     (LineSegment from:(0@0) to:(10@10)) dist:6@4      
     (LineSegment from:(0@0) to:(10@10)) dist:5@0      

o  isHorizontal
return true, if I am a horizontal line

o  isVertical
return true, if I am a vertical line

o  length
return the length of the vector

testing
o  isLineSegment
return true, if the receiver is a line segment

transforming
o  scaledBy: amount

o  translatedBy: amount


Examples:


low leel use:
  |v l|

  v := (View extent:100@100) openAndWait.

  l := LineSegment from:10@10 to:90@90. 

  v paint:Color red.
  l displayStrokedOn:v.

  l setStart:90@10 end:10@90.
  v paint:Color blue.
  l displayStrokedOn:v.
as component (automatic redraw):
  |v l|

  v := View extent:100@100.

  l := LineSegment from:10@10 to:90@90. 
  v addComponent:(StrokingWrapper on:l).

  l := LineSegment from:90@10 to:10@90. 
  v addComponent:((StrokingWrapper on:l) foregroundColor:(Color red)).

  v open.


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Tue, 19 Mar 2024 05:14:26 GMT