mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-27 03:48:21 +01:00
68 lines
1.3 KiB
Smalltalk
68 lines
1.3 KiB
Smalltalk
Class {
|
|
#name : #DiyaPolygon,
|
|
#superclass : #Diya2DPrimShape,
|
|
#instVars : [
|
|
'points'
|
|
],
|
|
#category : #'Diya-Graphics'
|
|
}
|
|
|
|
{ #category : #'as yet unclassified' }
|
|
DiyaPolygon class >> points: points [
|
|
^self new points: points; yourself
|
|
]
|
|
|
|
{ #category : #'as yet unclassified' }
|
|
DiyaPolygon class >> points: points shader:s [
|
|
^self new points: points; shader:s; yourself
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaPolygon >> calculateVertices [
|
|
^self subclassResponsibility
|
|
]
|
|
|
|
{ #category : #initialization }
|
|
DiyaPolygon >> initialize [
|
|
super initialize.
|
|
points := {}.
|
|
vbuffer := nil.
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaPolygon >> points [
|
|
^ points
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaPolygon >> points: anObject [
|
|
points := anObject.
|
|
dirty := true
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaPolygon >> recFromPoints [
|
|
|maxX maxY minX minY x y|
|
|
maxX := minX := (points at: 1) x.
|
|
maxY := minY := (points at: 1) y.
|
|
points do: [ :p|
|
|
x := p x.
|
|
y := p y.
|
|
maxX := maxX max: x.
|
|
maxY := maxY max: y.
|
|
minX := minX min: x.
|
|
minY := minY min: y.
|
|
].
|
|
^ Rectangle origin: minX@minY corner: maxX @ maxY
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
DiyaPolygon >> update [
|
|
bbox := self recFromPoints.
|
|
translation = bbox origin ifFalse:[ self position: bbox origin].
|
|
points := points collect:[:e | e - bbox origin].
|
|
bbox := self recFromPoints.
|
|
self calculateVertices.
|
|
^true
|
|
]
|