~hilaire-fernandes/drgeo/trunk

« back to all changes in this revision

Viewing changes to src/DrGeoII-Core/DrGPointIntersectionItem.class.st

  • Committer: Hilaire Fernandes
  • Date: 2017-11-15 13:17:03 UTC
  • Revision ID: hilaire.fernandes@gmail.com-20171115131703-pz09obavthi53ebt
DrGeo code under Tonel file format

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"
 
2
k                               - (-1) or 1 when they are 2 intersection points
 
3
"
 
4
Class {
 
5
        #name : #DrGPointIntersectionItem,
 
6
        #superclass : #DrGPointItem,
 
7
        #instVars : [
 
8
                'k'
 
9
        ],
 
10
        #category : #'DrGeoII-Core-Item'
 
11
}
 
12
 
 
13
{ #category : #'as yet unclassified' }
 
14
DrGPointIntersectionItem class >> newWith: theParents k: integer [
 
15
        "Instantiate this mathItem with these parents
 
16
        Parents contains other MathItem instance, sometime it contains other object as Point"
 
17
        ^self new 
 
18
                parents: theParents; 
 
19
                k: integer;
 
20
                update;
 
21
                rehash;
 
22
                yourself
 
23
]
 
24
 
 
25
{ #category : #comparing }
 
26
DrGPointIntersectionItem >> = aMathItem [
 
27
        ^ super = aMathItem and: [k = aMathItem k]
 
28
]
 
29
 
 
30
{ #category : #'initialize-release' }
 
31
DrGPointIntersectionItem >> initialize: theParents [
 
32
"check for the right intersection point when one parent is a circle or an arc"
 
33
|pointA pointB clicPoint|
 
34
        super initialize: theParents.
 
35
        k := 0. "0 when only one intersection"
 
36
        (theParents first isCircleItem 
 
37
                or: [theParents second isCircleItem
 
38
                        or: [theParents first isArcItem
 
39
                                or: [theParents second isArcItem]]])
 
40
                ifFalse: [^self].
 
41
        pointA := [theParents first intersectionWith: theParents second flag: -1] on: Error do: [nil].
 
42
        pointB := [theParents first intersectionWith: theParents second flag: 1] on: Error do: [nil].
 
43
        pointA ifNil: [^ self k: 1].
 
44
        pointB ifNil: [^ self k: -1].
 
45
        clicPoint := theParents third.
 
46
        (pointA squaredDistanceTo: clicPoint) < (pointB squaredDistanceTo: clicPoint)
 
47
                ifTrue: [self k: -1] 
 
48
                ifFalse: [self k: 1]
 
49
]
 
50
 
 
51
{ #category : #'*DrGeoII-Core-testing' }
 
52
DrGPointIntersectionItem >> isConstrainedPointItem [
 
53
        ^true
 
54
]
 
55
 
 
56
{ #category : #'*DrGeoII-Core-testing' }
 
57
DrGPointIntersectionItem >> isIntersectionPointItem [
 
58
        ^true
 
59
]
 
60
 
 
61
{ #category : #accessing }
 
62
DrGPointIntersectionItem >> k [
 
63
        ^k
 
64
]
 
65
 
 
66
{ #category : #accessing }
 
67
DrGPointIntersectionItem >> k: integer [ 
 
68
        k := integer.
 
69
        self update.
 
70
        self rehash
 
71
]
 
72
 
 
73
{ #category : #'xml writing' }
 
74
DrGPointIntersectionItem >> nodeType [
 
75
        ^#Intersection
 
76
]
 
77
 
 
78
{ #category : #accessing }
 
79
DrGPointIntersectionItem >> parents: aCollection [ 
 
80
        "We only need the 1st and 2nd mathItem in the collection. 
 
81
The 3rd one is a Point instance (position the user clicked) only used at initialization time"
 
82
        aCollection isEmptyOrNil ifTrue: 
 
83
                [parents := aCollection.
 
84
                ^self].
 
85
        parents := OrderedCollection new
 
86
                add: aCollection first;
 
87
                add: aCollection second;
 
88
                yourself.
 
89
 
 
90
]
 
91
 
 
92
{ #category : #comparing }
 
93
DrGPointIntersectionItem >> rehash [
 
94
        ^hash := (super rehash bitXor: k ) bitXor: point hash 
 
95
]
 
96
 
 
97
{ #category : #updating }
 
98
DrGPointIntersectionItem >> update [
 
99
        |aPoint|
 
100
        self doParentsExist ifTrue:
 
101
                [aPoint := [(parents first intersectionWith: parents second flag: k)] on: Error do: [nil].
 
102
                aPoint 
 
103
                        ifNil: [exist := false]
 
104
                        ifNotNil: 
 
105
                                [exist := true.
 
106
                                self point: aPoint]].
 
107
]
 
108
 
 
109
{ #category : #'xml writing' }
 
110
DrGPointIntersectionItem >> writeAsXmlTo: aNode [ 
 
111
        | node |
 
112
        node := super writeAsXmlTo: aNode.
 
113
        node
 
114
                attributeAt: #extra
 
115
                put: (k = 1
 
116
                                ifTrue: ['1']
 
117
                                ifFalse: ['0']).
 
118
        ^node
 
119
]