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.31 date: 2023/08/10 13:11:36
user: alkurz
file: LineSegment.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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 #=).

copyright

COPYRIGHT (c) 1996 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

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  endPoint: 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) **

o  startPoint: aPoint
set the startPoint

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

Usage example(s):

     |v|

     v := View new openAndWaitUntilVisible.

     (LineSegment from:10@10 to:50@50) displayStrokedOn:v

printing
o  printOn: aStream
(comment from inherited method)
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

The default here is to output the receiver's class name.
BUT: this method is heavily redefined for objects which
can print prettier.

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.
That is the length of a line perpendicular to the line segment,
which hits aPoint.

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      
     (LineSegment from:(0@0) to:(10@0)) dist:5@0      

     (LineSegment from:(0@0) to:(10@0)) dist:5@1      
     (LineSegment from:(0@0) to:(10@0)) dist:5@3      
     (LineSegment from:(0@0) to:(10@0)) dist:5@-3      
     (LineSegment from:(0@0) to:(0@10)) dist:5@5      
     (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  roundedToNearestIntegerPoint
return a copy of the receiver, where all points are rounded to ly on the nearest integer coordinate

o  scaledBy: amount
(comment from inherited method)
return a copy of the receiver, which is scaled by the argument, a point or number

o  transformedBy: transformation
return a copy of the receiver, which is transformed using aMatrix

o  translatedBy: amount
return a copy of the receiver which is translated (i.e. moved)
by amount, aPoint or Number


Examples:


low leel use:
  |v l|

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

  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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:17:27 GMT